Added mount-chroot-fs

Pascal J. Bourguignon [2018-04-21 11:59]
Added mount-chroot-fs
Filename
mount-chroot-fs
diff --git a/mount-chroot-fs b/mount-chroot-fs
new file mode 100755
index 0000000..e585114
--- /dev/null
+++ b/mount-chroot-fs
@@ -0,0 +1,66 @@
+#!/bin/bash
+
+_SYSEXITS_H=1
+EX_OK=0
+EX__BASE=64
+EX_USAGE=64
+EX_DATAERR=65
+EX_NOINPUT=66
+EX_NOUSER=67
+EX_NOHOST=68
+EX_UNAVAILABLE=69
+EX_SOFTWARE=70
+EX_OSERR=71
+EX_OSFILE=72
+EX_CANTCREAT=73
+EX_IOERR=74
+EX_TEMPFAIL=75
+EX_PROTOCOL=76
+EX_NOPERM=77
+EX_CONFIG=78
+EX__MAX=78
+
+pname="$(basename "$0")"
+root=none
+
+function parse_arguments(){
+    for arg ; do
+        case "$arg" in
+        -h|--help)
+            usage
+            exit 0
+            ;;
+        -*)
+            printf "%s error: unknown option: %s\n" "$pname" "$arg" 1>&2
+            usage
+            exit $EX_USAGE
+            ;;
+        *)
+            if [ "$root" = none ] ; then
+                root="$arg"
+            else
+                printf "%s error:  option: %s\n" "$pname" "$arg" 1>&2
+                usage
+                exit $EX_USAGE
+            fi
+            ;;
+        esac
+    done
+}
+
+function mount_them(){
+    cd "$root"
+    mount -t proc proc     proc
+    mount -t sysfs sys     sys
+    mount -o bind /dev     dev
+    mount -o bind /dev/pts dev/pts
+}
+
+function main(){
+    parse_arguments
+    mount_them
+}
+
+main
+exit $EX_OK
+
ViewGit