summaryrefslogtreecommitdiffstats
path: root/meta-phosphor/common/recipes-phosphor/obmc-phosphor-initfs/files/obmc-shutdown.sh
blob: cc076fdc08a940d293a29986dc9df7b34e6cff57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

echo shutdown: "$@"

export PS1=shutdown-sh#\ 
# exec bin/sh

if [ ! -e /proc/mounts ]
then
	mkdir -p /proc
	mount  proc proc -tproc
	umount_proc=1
else
	umount_proc=
fi

# remove an empty oldroot, that means we are not invoked from systemd-shutdown
rmdir /oldroot 2>/dev/null

set -x
for f in $( awk '/oldroot/ { print $2 }' < /proc/mounts | sort -r )
do
	umount $f
done
set +x

if test -s /run/fw_env -a -c /run/mtd:u-boot-env -a ! -e /image-u-boot-env &&
	! cmp /run/mtd:u-boot-env /run/fw_env
then
	ln -s /run/fw_env /image-u-boot-env
fi

if test -x /update && ls image-* > /dev/null 2>&1
then
	exec /update ${1+"$@"}
fi

echo Remaining mounts:
cat /proc/mounts

test "umount_proc" && umount /proc && rmdir /proc



# Execute the command systemd told us to ...
if test -d /oldroot  && test "$1"
then
	if test "$1" == kexec
	then
		$1 -f -e
	else
		$1 -f
	fi
fi


echo "Execute ${1-reboot} -f if all unounted ok, or exec /init"

export PS1=shutdown-sh#\ 
exec /bin/sh
OpenPOWER on IntegriCloud