blob: 32e83e680283a68f3a95cc30f038c88995811ecc [file] [log] [blame]
Milton D. Miller II0e775142016-01-20 14:57:54 -06001#!/bin/sh
2
3echo update: "$@"
4
5export PS1=update-sh#\
6# exec /bin/sh
7
8cd /
9if ! test -r /proc/mounts || ! test -f /proc/mounts
10then
11 mkdir -p /proc
12 mount -t proc proc proc
13fi
14if ! test -d /sys/class
15then
16 mkdir -p /sys
17 mount -t sysfs sys sys
18fi
19if ! test -c /dev/null
20then
21 mkdir -p /dev
22 mount -t devtmpfs dev dev
23fi
24while grep mtd /proc/mounts
25do
26 echo 1>&2 "Error: A mtd device is mounted."
27 sulogin
28 # exec /bin/sh
29done
30
31findmtd() {
32 m=$(grep -xl "$1" /sys/class/mtd/*/name)
33 m=${m%/name}
34 m=${m##*/}
35 echo $m
36}
37
Milton D. Miller II0e775142016-01-20 14:57:54 -060038rwfs=$(findmtd rwfs)
39
Milton Millerba65b7b2016-02-05 12:07:53 -060040rwdev=/dev/mtdblock${rwfs#mtd}
Milton D. Miller II0e775142016-01-20 14:57:54 -060041rwfst=ext4
Milton Millerba65b7b2016-02-05 12:07:53 -060042rwopts=rw
43rorwopts=ro${rwopts#rw}
44
45rwdir=rw
46upper=$rwdir/cow
47save=save/${upper##*/}
Milton D. Miller II0e775142016-01-20 14:57:54 -060048
49if test -n "$rwfs" && test -s whitelist
50then
51
Milton Millerba65b7b2016-02-05 12:07:53 -060052 mkdir -p $rwdir
53 mount $rwdev $rwdir -t $rwfst -o $rorwopts
Milton D. Miller II0e775142016-01-20 14:57:54 -060054
55 while read f
56 do
Milton Millerba65b7b2016-02-05 12:07:53 -060057 if ! test -e $upper/$f
Milton D. Miller II0e775142016-01-20 14:57:54 -060058 then
59 continue
60 fi
Milton Millerba65b7b2016-02-05 12:07:53 -060061 d="$save/$f"
Milton D. Miller II0e775142016-01-20 14:57:54 -060062 mkdir -p "${d%/*}"
Milton Millerba65b7b2016-02-05 12:07:53 -060063 cp -rp $upper/$f "${d%/*}/"
Milton D. Miller II0e775142016-01-20 14:57:54 -060064 done < whitelist
65
Milton Millerba65b7b2016-02-05 12:07:53 -060066 umount $rwdir
Milton D. Miller II0e775142016-01-20 14:57:54 -060067fi
68
Milton Miller36d336c2016-02-05 11:19:58 -060069image=/run/initramfs/image-
70for f in $image*
Milton D. Miller II0e775142016-01-20 14:57:54 -060071do
Milton Miller36d336c2016-02-05 11:19:58 -060072 m=$(findmtd ${f#$image})
Milton D. Miller II0e775142016-01-20 14:57:54 -060073 if test -z "$m"
74 then
Milton Millerba65b7b2016-02-05 12:07:53 -060075 echo 1>&2 "Unable to find mtd partiton for ${f##*/}."
Milton D. Miller II0e775142016-01-20 14:57:54 -060076 exec /bin/sh
77 fi
78done
79
Milton Miller36d336c2016-02-05 11:19:58 -060080for f in $image*
Milton D. Miller II0e775142016-01-20 14:57:54 -060081do
Milton Miller36d336c2016-02-05 11:19:58 -060082 m=$(findmtd ${f#$image})
83 echo "Updating ${f#$image}..."
Milton D. Miller II0e775142016-01-20 14:57:54 -060084 # flasheraseall /dev/$m && dd if=$f of=/dev/$m
85 flashcp -v $f /dev/$m
86done
87
Milton Millerba65b7b2016-02-05 12:07:53 -060088if test -d $save
Milton D. Miller II0e775142016-01-20 14:57:54 -060089then
Milton Millerba65b7b2016-02-05 12:07:53 -060090 mount $rwdev $rwdir -t $rwfst -o $rwopts
91 cp -rp $save/. $upper/
92 umount $rwdir
Milton D. Miller II0e775142016-01-20 14:57:54 -060093fi
94
95# Execute the command systemd told us to ...
96if test -d /oldroot && test -x "/sbin/$1" && test -f "/sbin/$1"
97then
98 if test "$1" == kexec
99 then
100 /sbin/$1 -f -e
101 else
102 /sbin/$1 -f
103 fi
104fi
105
106
107echo "Execute ${1-reboot} -f if all is ok"
108
109export PS1=update-sh#\
110exec /bin/sh