add script for bind mounting into overlay
authorRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 2 Dec 2022 08:11:55 +0000 (19:11 +1100)
committerRalph Ronnquist <ralph.ronnquist@gmail.com>
Fri, 2 Dec 2022 08:11:55 +0000 (19:11 +1100)
overlay-share [new file with mode: 0755]

diff --git a/overlay-share b/overlay-share
new file mode 100755 (executable)
index 0000000..1ed74fc
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+#
+# Share a directory tree with an overlay-boot subhost
+#
+# $1 = directory $2 = subhost
+
+set -e
+
+. $(dirname $(realpath $0))/functions
+
+if [ ! -d "$1" ] ; then
+   echo "** Not a directory: $1" >&2
+   exit 1
+fi
+
+SHARE="$1"
+NAME="$2"
+
+[ -z "$NAME" ] && echo "Select subhost: $(list_running)" && exit 0
+
+read USPID RSPID <<EOF
+$(is_live $NAME)
+EOF
+[ -z "$USPID" ] && echo "$NAME is not running" >&2 && exit 1
+if [ -z "$RSPID" ] ; then
+    cat <<EOF >&2
+***  $NAME is started (pid $USPID) but doesn't seem to be running
+*** /.reaper and might need manual fixing.
+EOF
+    exit 1
+fi
+
+sudo nsenter -t "$RSPID" -n -m -p /bin/bash <<EOF
+set -e
+LIVE=\$(awk '\$1=="$NAME" && \$3=="overlay" {print \$2;}' < /proc/mounts)
+[ -d "\$LIVE" ] && mount --bind $SHARE "\$LIVE$SHARE"
+EOF
+echo "Sharing $SHARE with subhost $NAME"
+exit 0