#!/usr/bin/env bash
# Re-apply every mount recorded in mounts.list.  Run this after a reboot,
# once the container (with its rslave bind) is back up.
set -euo pipefail

here="$(cd "$(dirname "$(realpath "$0")")" && pwd)"
root="$(dirname "$here")"
staging="$root/workspace"
record="$root/mounts.list"
mountctl="$here/mountctl"

mkdir -p "$staging"
[ -f "$record" ] || exit 0
while IFS=$'\t' read -r src name; do
  [ -z "${name:-}" ] && continue
  mkdir -p "$staging/$name"
  "$mountctl" mount "$src" "$name"
done < "$record"
