blob: 3197722d9b7ea510495e96eb2a308a62683e5cf4 [file] [log] [blame]
#!/bin/sh
set -e
if grep -q rauc.slot=A /proc/cmdline; then
RAUC_SLOT_NO=0
RAUC_SLOT_NAME=A
elif grep -q rauc.slot=B /proc/cmdline; then
RAUC_SLOT_NO=1
RAUC_SLOT_NAME=B
else
echo "Cannot determine active RAUC rootfs slot"
exit 1
fi
# sed magic:
# 1) use `sed -n` so that we only print what's explicitly printed
# 2) anchor the search between the "[slot.cfg.$RAUC_SLOT_NO]" and any other section
# 3) look for a line beginning with "device="
# 4) take stuff which is behind the "="
# 5) print it
DEVICE=$(sed -n "/\[slot\.cfg\.${RAUC_SLOT_NO}\]/,/\[.*\]/{/^device=/s/\(.*\)=\(.*\)/\\2/p}" /etc/rauc/system.conf)
if [ x$DEVICE -eq x ]; then
echo "Cannot determine device for /cfg from RAUC"
exit 1
fi
if [ ! -b $DEVICE ]; then
echo "Device ${DEVICE} is not a block device"
exit 1
fi
cat > $1/cfg.mount <<EOF
[Unit]
Description=Persistent config (slot ${RAUC_SLOT_NAME})
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
After=swap.target
[Mount]
What=${DEVICE}
Where=/cfg
Type=auto
Options=relatime,nosuid,nodev
EOF