From e753a4d1af740a3cfeb4a4c994395f3a0a5a3c73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 2 Sep 2018 22:55:51 +0200 Subject: alpine-amd64: try to change how we do chroot --- scripts/uchroot | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'scripts/uchroot') 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" -- cgit v1.2.3