#!/bin/sh
# Runs in the startup image when a snapshot is started from the boot menu, on the snapshot's fstab in the writable
# memory layer: the boot partition read-only (the normal system's kernels live there), and no line for / (the
# snapshot is already mounted; remounting it with the normal system's options would fail).
fstab="$1"
[ -f "$fstab" ] || exit 0
awk '
    /^[[:space:]]*#/ || NF < 4 { print; next }
    $2 == "/" { print "# " $0; next }
    $2 == "/boot" || $2 == "/efi" { $4 = $4 ",ro" }
    { print }
' "$fstab" > "$fstab.starchaser" && mv "$fstab.starchaser" "$fstab"
