summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-10-14 17:31:02 +0200
committerKarel Kočí <cynerd@email.cz>2018-10-14 20:59:19 +0200
commitd562390407eec6ecc83a9f19635258fbe83b6695 (patch)
tree922364534f2a031f8b76cc67229c287016ed5c1a /scripts
parent4ddbc0c658e65fb14f4c22b63fff2e56032ccf7f (diff)
downloadlaminar-cnf-d562390407eec6ecc83a9f19635258fbe83b6695.tar.gz
laminar-cnf-d562390407eec6ecc83a9f19635258fbe83b6695.tar.bz2
laminar-cnf-d562390407eec6ecc83a9f19635258fbe83b6695.zip
alpine: move it to templates and try to add qemu support
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/uchroot35
1 files changed, 29 insertions, 6 deletions
diff --git a/scripts/uchroot b/scripts/uchroot
index b11981a..b94e14f 100755
--- a/scripts/uchroot
+++ b/scripts/uchroot
@@ -1,7 +1,11 @@
#!/bin/sh
set -e
[ $# -ge 1 ] || {
- echo "Usage: uchroot ROOT [USER] [CMD]" >&2
+ echo "Usage: uchroot USER [CMD] [ARG].." >&2
+ echo "Configuration has to be passed trough envrionment."
+ echo " ROOT: path to directory to chroot in"
+ echo " ARCH: optional target architecture (if qemu should be used)"
+ echo " MOUNT: pairs of two paths separated by colon (LOCAL:INROOT)"
exit 1
}
@@ -10,10 +14,17 @@ if [ "$(id -u)" != "0" ]; then
fi
###############################################################
-ROOT="$1"
-USR="${2:-root}"
-shift 2
-[ $# -lt 1 ] && CMD="" || CMD="-c '$@'"
+[ -n "$ROOT" ] || {
+ echo "Variable ROOT has to be defined in environment."
+ exit 1
+}
+
+USR="${1:-root}"
+shift
+[ $# -lt 1 ] && CMD="" || {
+ CMD="-c \"$1\""
+ shift
+}
[ -d "$ROOT" ] || {
echo "There is no such directory: $ROOT" >&2
@@ -24,11 +35,23 @@ shift 2
exit 1
}
+EXECUTOR=
+
mount --rbind "$ROOT" "$ROOT"
mount -t proc none "$ROOT/proc"
mount --rbind /dev "$ROOT/dev"
mount --rbind /sys "$ROOT/sys"
+while IFS=: read src target; do
+ [ -n "$src" -a -n "$target" ] || continue
+ mount --rbind "$src" "$ROOT/$target"
+done <<<"$MOUNT"
+
cp -f /etc/resolv.conf "$ROOT/etc/resolv.conf"
cp -f /etc/hosts "$ROOT/etc/hosts"
+if [ -n "$ARCH" -a "$ARCH" != "$(arch)" ]; then
+ cp -f "$(which "qemu-$ARCH")" "$ROOT/qemu"
+ EXECUTOR=/qemu
+fi
-exec chroot "$ROOT" /bin/sh -c ". /etc/profile && exec su $CMD -l $USR" "$0"
+exec chroot "$ROOT" $EXECUTOR /bin/sh -c \
+ ". /etc/profile && exec su -l $USR $CMD \"\$@\"" -- "$@"