blob: 3197722d9b7ea510495e96eb2a308a62683e5cf4 [file] [log] [blame]
Jan Kundrát0331eac2017-10-25 13:53:34 +02001#!/bin/sh
2
3set -e
4
5if grep -q rauc.slot=A /proc/cmdline; then
6 RAUC_SLOT_NO=0
7 RAUC_SLOT_NAME=A
8elif grep -q rauc.slot=B /proc/cmdline; then
9 RAUC_SLOT_NO=1
10 RAUC_SLOT_NAME=B
11else
12 echo "Cannot determine active RAUC rootfs slot"
13 exit 1
14fi
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
22DEVICE=$(sed -n "/\[slot\.cfg\.${RAUC_SLOT_NO}\]/,/\[.*\]/{/^device=/s/\(.*\)=\(.*\)/\\2/p}" /etc/rauc/system.conf)
23
24if [ x$DEVICE -eq x ]; then
25 echo "Cannot determine device for /cfg from RAUC"
26 exit 1
27fi
28
29if [ ! -b $DEVICE ]; then
30 echo "Device ${DEVICE} is not a block device"
31 exit 1
32fi
33
34cat > $1/cfg.mount <<EOF
35[Unit]
36Description=Persistent config (slot ${RAUC_SLOT_NAME})
37DefaultDependencies=no
38Conflicts=umount.target
39Before=local-fs.target umount.target
40After=swap.target
41
42[Mount]
43What=${DEVICE}
44Where=/cfg
45Type=auto
46Options=relatime,nosuid,nodev
47EOF