chiark / gitweb /
add chroot-setup, chroot-teardown, and chroot-enter suite of tools
[bin.git] / chroot-teardown
diff --git a/chroot-teardown b/chroot-teardown
new file mode 100755 (executable)
index 0000000..f7ceed9
--- /dev/null
@@ -0,0 +1,29 @@
+#! /bin/sh
+set +e # intentional
+
+ROOT="${1:-/chroot/sid}"
+
+is_mountpoint () {
+       grep -q "^[^ ]* $1 " /proc/mounts
+}
+
+maybe_umount () {
+       if is_mountpoint "$ROOT/${1#/}"; then
+               sudo umount "$ROOT/${1#/}"
+       fi
+}
+
+maybe_umount /home/cjwatson/src
+maybe_umount /home/cjwatson/.keychain
+if [ "$GPG_AGENT_INFO" ]; then
+       maybe_umount "$(dirname "$GPG_AGENT_INFO")"
+fi
+if [ "$SSH_AUTH_SOCK" ]; then
+       maybe_umount "$(dirname "$SSH_AUTH_SOCK")"
+fi
+maybe_umount /tmp/.ICE-unix
+maybe_umount /tmp/.X11-unix
+maybe_umount /dev/pts
+maybe_umount /dev
+maybe_umount /sys
+maybe_umount /proc