Jan Kundrát | 567058d | 2018-11-08 19:15:56 +0100 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | echo "Preparing /etc overlay" |
| 4 | /bin/mount -t tmpfs tmpfs /.ov -o mode=0700 |
| 5 | /bin/mkdir /.ov/etc-u |
| 6 | /bin/mkdir /.ov/etc-w |
| 7 | /bin/mount overlay -t overlay /etc -olowerdir=/etc,upperdir=/.ov/etc-u,workdir=/.ov/etc-w |
| 8 | |
| 9 | /bin/mount -t proc proc /proc -o rw,nosuid,nodev,noexec,relatime |
| 10 | if grep -q rauc.slot=A /proc/cmdline; then |
| 11 | RAUC_SLOT_NO=0 |
| 12 | RAUC_SLOT_NAME=A |
| 13 | elif grep -q rauc.slot=B /proc/cmdline; then |
| 14 | RAUC_SLOT_NO=1 |
| 15 | RAUC_SLOT_NAME=B |
| 16 | else |
| 17 | echo "Cannot determine active RAUC rootfs slot" |
| 18 | #exit 1 |
| 19 | fi |
| 20 | /bin/umount /proc |
| 21 | echo "RAUC: active slot ${RAUC_SLOT_NAME}" |
| 22 | |
| 23 | # sed magic: |
| 24 | # 1) use `sed -n` so that we only print what's explicitly printed |
| 25 | # 2) anchor the search between the "[slot.cfg.$RAUC_SLOT_NO]" and any other section |
| 26 | # 3) look for a line beginning with "device=" |
| 27 | # 4) take stuff which is behind the "=" |
| 28 | # 5) print it |
| 29 | DEVICE=$(sed -n "/\[slot\.cfg\.${RAUC_SLOT_NO}\]/,/\[.*\]/{/^device=/s/\(.*\)=\(.*\)/\\2/p}" /etc/rauc/system.conf) |
| 30 | |
| 31 | if [ x$DEVICE = x ]; then |
| 32 | echo "Cannot determine device for /cfg from RAUC" |
| 33 | #exit 1 |
| 34 | fi |
| 35 | |
| 36 | if [ ! -b $DEVICE ]; then |
| 37 | echo "Device ${DEVICE} is not a block device" |
| 38 | #exit 1 |
| 39 | fi |
| 40 | |
| 41 | echo "Mounting /cfg" |
| 42 | /bin/mount ${DEVICE} /cfg -t auto -o relatime,nosuid,nodev |
| 43 | |
| 44 | if [ -d /cfg/etc ]; then |
| 45 | echo "Restoring /etc from /cfg" |
| 46 | /bin/cp -a /cfg/etc/* /etc/ |
| 47 | fi |
| 48 | |
| 49 | exec /sbin/init |