summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/uchroot15
1 files changed, 7 insertions, 8 deletions
diff --git a/scripts/uchroot b/scripts/uchroot
index 6aa76b2..b11981a 100755
--- a/scripts/uchroot
+++ b/scripts/uchroot
@@ -1,7 +1,7 @@
#!/bin/sh
set -e
-[ $# -ge 2 ] || {
- echo "Usage: uchroot ROOT USER[:GROUP] [CMD] [ARG].." >&2
+[ $# -ge 1 ] || {
+ echo "Usage: uchroot ROOT [USER] [CMD]" >&2
exit 1
}
@@ -11,8 +11,10 @@ fi
###############################################################
ROOT="$1"
-USERSPEC="$2"
+USR="${2:-root}"
shift 2
+[ $# -lt 1 ] && CMD="" || CMD="-c '$@'"
+
[ -d "$ROOT" ] || {
echo "There is no such directory: $ROOT" >&2
exit 1
@@ -22,14 +24,11 @@ shift 2
exit 1
}
-
+mount --rbind "$ROOT" "$ROOT"
mount -t proc none "$ROOT/proc"
mount --rbind /dev "$ROOT/dev"
mount --rbind /sys "$ROOT/sys"
cp -f /etc/resolv.conf "$ROOT/etc/resolv.conf"
cp -f /etc/hosts "$ROOT/etc/hosts"
-if [ $# -lt 1 ]; then
- set "/bin/sh"
-fi
-exec chroot --userspec="$USERSPEC" "$ROOT" "$@"
+exec chroot "$ROOT" /bin/sh -c ". /etc/profile && exec su $CMD -l $USR" "$0"