Jan Kundrát | 0331eac | 2017-10-25 13:53:34 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | if grep -q rauc.slot=A /proc/cmdline; then |
| 6 | RAUC_SLOT_NO=0 |
| 7 | RAUC_SLOT_NAME=A |
| 8 | elif grep -q rauc.slot=B /proc/cmdline; then |
| 9 | RAUC_SLOT_NO=1 |
| 10 | RAUC_SLOT_NAME=B |
| 11 | else |
| 12 | echo "Cannot determine active RAUC rootfs slot" |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | # sed magic: |
| 17 | # 1) use `sed -n` so that we only print what's explicitly printed |
| 18 | # 2) anchor the search between the "[slot.cfg.$RAUC_SLOT_NO]" and any other section |
| 19 | # 3) look for a line beginning with "device=" |
| 20 | # 4) take stuff which is behind the "=" |
| 21 | # 5) print it |
| 22 | DEVICE=$(sed -n "/\[slot\.cfg\.${RAUC_SLOT_NO}\]/,/\[.*\]/{/^device=/s/\(.*\)=\(.*\)/\\2/p}" /etc/rauc/system.conf) |
| 23 | |
| 24 | if [ x$DEVICE -eq x ]; then |
| 25 | echo "Cannot determine device for /cfg from RAUC" |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
| 29 | if [ ! -b $DEVICE ]; then |
| 30 | echo "Device ${DEVICE} is not a block device" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | cat > $1/cfg.mount <<EOF |
| 35 | [Unit] |
| 36 | Description=Persistent config (slot ${RAUC_SLOT_NAME}) |
| 37 | DefaultDependencies=no |
| 38 | Conflicts=umount.target |
| 39 | Before=local-fs.target umount.target |
| 40 | After=swap.target |
| 41 | |
| 42 | [Mount] |
| 43 | What=${DEVICE} |
| 44 | Where=/cfg |
| 45 | Type=auto |
| 46 | Options=relatime,nosuid,nodev |
| 47 | EOF |