|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +set -x |
| 4 | +set -e |
| 5 | + |
| 6 | +echo "Running mountbootpartition-generator.sh" > /dev/kmsg |
| 7 | + |
| 8 | +# type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh |
| 9 | + |
| 10 | +function updateVeritySetupUnit () { |
| 11 | + systemdDropInDir=/etc/systemd/system |
| 12 | + verityDropInDir=$systemdDropInDir/systemd-veritysetup@root.service.d |
| 13 | + |
| 14 | + mkdir -p $verityDropInDir |
| 15 | + verityConfiguration=$verityDropInDir/verity-azl-extension.conf |
| 16 | + |
| 17 | + cat <<EOF > $verityConfiguration |
| 18 | +[Unit] |
| 19 | +After=bootmountmonitor.service |
| 20 | +Requires=bootmountmonitor.service |
| 21 | +EOF |
| 22 | + |
| 23 | + chmod 644 $verityConfiguration |
| 24 | + chown root:root $verityConfiguration |
| 25 | +} |
| 26 | + |
| 27 | +# ----------------------------------------------------------------------------- |
| 28 | +function createBootPartitionMonitorScript () { |
| 29 | + local bootPartitionMonitorCmd=$1 |
| 30 | + local semaphorefile=$2 |
| 31 | + |
| 32 | + cat <<EOF > $bootPartitionMonitorCmd |
| 33 | +#!/bin/sh |
| 34 | +while [ ! -e "$semaphorefile" ]; do |
| 35 | + echo "Waiting for $semaphorefile to exist..." |
| 36 | + sleep 1 |
| 37 | +done |
| 38 | +EOF |
| 39 | + chmod +x $bootPartitionMonitorCmd |
| 40 | +} |
| 41 | + |
| 42 | +# ----------------------------------------------------------------------------- |
| 43 | +function createBootPartitionMonitorUnit() { |
| 44 | + local bootPartitionMonitorCmd=$1 |
| 45 | + |
| 46 | + bootMountMonitorName="bootmountmonitor.service" |
| 47 | + systemdDropInDir=/etc/systemd/system |
| 48 | + bootMountMonitorDir=$systemdDropInDir |
| 49 | + bootMountMonitorUnitFile=$bootMountMonitorDir/$bootMountMonitorName |
| 50 | + |
| 51 | + cat <<EOF > $bootMountMonitorUnitFile |
| 52 | +[Unit] |
| 53 | +Description=bootpartitionmounter |
| 54 | +DefaultDependencies=no |
| 55 | +
|
| 56 | +[Service] |
| 57 | +Type=oneshot |
| 58 | +ExecStart=$bootPartitionMonitorCmd |
| 59 | +RemainAfterExit=yes |
| 60 | +
|
| 61 | +[Install] |
| 62 | +WantedBy=multi-user.target |
| 63 | +EOF |
| 64 | +} |
| 65 | + |
| 66 | +# ----------------------------------------------------------------------------- |
| 67 | + |
| 68 | +updateVeritySetupUnit |
| 69 | + |
| 70 | +systemdScriptsDir=/usr/local/bin |
| 71 | +bootPartitionMonitorCmd=$systemdScriptsDir/boot-partition-monitor.sh |
| 72 | +semaphorefile=/run/boot-parition-mount-complete.sem |
| 73 | + |
| 74 | +mkdir -p $systemdScriptsDir |
| 75 | + |
| 76 | +createBootPartitionMonitorScript $bootPartitionMonitorCmd $semaphorefile |
| 77 | +createBootPartitionMonitorUnit $bootPartitionMonitorCmd |
| 78 | + |
| 79 | +echo "mountbootpartition-generator.sh completed successfully." > /dev/kmsg |
0 commit comments