Milton D. Miller II | 0e77514 | 2016-01-20 14:57:54 -0600 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | echo update: "$@" |
| 4 | |
| 5 | export PS1=update-sh#\ |
| 6 | # exec /bin/sh |
| 7 | |
| 8 | cd / |
| 9 | if ! test -r /proc/mounts || ! test -f /proc/mounts |
| 10 | then |
| 11 | mkdir -p /proc |
| 12 | mount -t proc proc proc |
| 13 | fi |
| 14 | if ! test -d /sys/class |
| 15 | then |
| 16 | mkdir -p /sys |
| 17 | mount -t sysfs sys sys |
| 18 | fi |
| 19 | if ! test -c /dev/null |
| 20 | then |
| 21 | mkdir -p /dev |
| 22 | mount -t devtmpfs dev dev |
| 23 | fi |
| 24 | while grep mtd /proc/mounts |
| 25 | do |
| 26 | echo 1>&2 "Error: A mtd device is mounted." |
| 27 | sulogin |
| 28 | # exec /bin/sh |
| 29 | done |
| 30 | |
| 31 | findmtd() { |
| 32 | m=$(grep -xl "$1" /sys/class/mtd/*/name) |
| 33 | m=${m%/name} |
| 34 | m=${m##*/} |
| 35 | echo $m |
| 36 | } |
| 37 | |
| 38 | rofs=$(findmtd rofs) |
| 39 | rwfs=$(findmtd rwfs) |
| 40 | |
| 41 | rofst=squahsfs |
| 42 | rwfst=ext4 |
| 43 | |
| 44 | if test -n "$rwfs" && test -s whitelist |
| 45 | then |
| 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 |
| 62 | fi |
| 63 | |
| 64 | |
| 65 | for f in image-* |
| 66 | do |
| 67 | m=$(findmtd ${f#image-}) |
| 68 | if test -z "$m" |
| 69 | then |
| 70 | echo 1>&2 "Unable to find mtd partiton for $f" |
| 71 | exec /bin/sh |
| 72 | fi |
| 73 | done |
| 74 | |
| 75 | for f in image-* |
| 76 | do |
| 77 | m=$(findmtd ${f#image-}) |
| 78 | echo "Updating ${f#image-}" |
| 79 | # flasheraseall /dev/$m && dd if=$f of=/dev/$m |
| 80 | flashcp -v $f /dev/$m |
| 81 | done |
| 82 | |
| 83 | |
| 84 | if test -d save/cow |
| 85 | then |
| 86 | mount /dev/mtdblock${rwfs#mtd} rw -o rw -t $rwfst |
| 87 | cp -rp save/cow/. rw/cow/ |
| 88 | umount rw |
| 89 | fi |
| 90 | |
| 91 | # Execute the command systemd told us to ... |
| 92 | if test -d /oldroot && test -x "/sbin/$1" && test -f "/sbin/$1" |
| 93 | then |
| 94 | if test "$1" == kexec |
| 95 | then |
| 96 | /sbin/$1 -f -e |
| 97 | else |
| 98 | /sbin/$1 -f |
| 99 | fi |
| 100 | fi |
| 101 | |
| 102 | |
| 103 | echo "Execute ${1-reboot} -f if all is ok" |
| 104 | |
| 105 | export PS1=update-sh#\ |
| 106 | exec /bin/sh |