blob: f83b1ad4fbc2b4e34cd8bcd6b7d1b15c8b6a7493 [file] [log] [blame]
Milton D. Miller IId89d5e02016-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
38rofs=$(findmtd rofs)
39rwfs=$(findmtd rwfs)
40
41rofst=squahsfs
42rwfst=ext4
43
44if test -n "$rwfs" && test -s whitelist
45then
46
47 mkdir -p rw
48 mount /dev/mtdblock${rwfs#mtd} rw -oro -t $rwfst
49
50 while read f
51 do
52 if ! test -e rw/cow/$f
53 then
54 continue
55 fi
56 d="save/cow/$f"
57 mkdir -p "${d%/*}"
58 cp -rp rw/cow/$f "${d%/*}/"
59 done < whitelist
60
61 umount rw
62fi
63
Milton Millerd93b48e2016-02-05 11:19:58 -060064image=/run/initramfs/image-
65for f in $image*
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060066do
Milton Millerd93b48e2016-02-05 11:19:58 -060067 m=$(findmtd ${f#$image})
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060068 if test -z "$m"
69 then
70 echo 1>&2 "Unable to find mtd partiton for $f"
71 exec /bin/sh
72 fi
73done
74
Milton Millerd93b48e2016-02-05 11:19:58 -060075for f in $image*
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060076do
Milton Millerd93b48e2016-02-05 11:19:58 -060077 m=$(findmtd ${f#$image})
78 echo "Updating ${f#$image}..."
Milton D. Miller IId89d5e02016-01-20 14:57:54 -060079 # flasheraseall /dev/$m && dd if=$f of=/dev/$m
80 flashcp -v $f /dev/$m
81done
82
83
84if test -d save/cow
85then
86 mount /dev/mtdblock${rwfs#mtd} rw -o rw -t $rwfst
87 cp -rp save/cow/. rw/cow/
88 umount rw
89fi
90
91# Execute the command systemd told us to ...
92if test -d /oldroot && test -x "/sbin/$1" && test -f "/sbin/$1"
93then
94 if test "$1" == kexec
95 then
96 /sbin/$1 -f -e
97 else
98 /sbin/$1 -f
99 fi
100fi
101
102
103echo "Execute ${1-reboot} -f if all is ok"
104
105export PS1=update-sh#\
106exec /bin/sh