diff options
-rwxr-xr-x | scripts/uchroot | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/scripts/uchroot b/scripts/uchroot index ad6b9c3..5a876c2 100755 --- a/scripts/uchroot +++ b/scripts/uchroot @@ -1,14 +1,10 @@ #!/bin/sh +# Usage: uchroot [USER [SCRIPT [ARG]..]] +# Configuration has to be passed trough envrionment. +# ROOT: path to directory to chroot in +# ARCH: optional target architecture (if qemu should be used) +# MOUNT: pairs of two paths separated by colon (LOCAL:INROOT) set -e -[ $# -ge 1 ] || { - 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 -} - if [ "$(id -u)" != "0" ]; then exec uroot --binfmt "$0" "$@" fi @@ -19,13 +15,6 @@ fi exit 1 } -USR="${1:-root}" -shift -[ $# -lt 1 ] && CMD="" || { - CMD="-c \"$1\"" - shift -} - [ -d "$ROOT" ] || { echo "There is no such directory: $ROOT" >&2 exit 1 @@ -52,5 +41,13 @@ if [ "$ARCH" != "$(arch)" ]; then cp -f "$qemu_exec" "$ROOT$qemu_exec" fi -exec chroot "$ROOT" /bin/sh -c \ - ". /etc/profile && exec su -l $USR $CMD \"\$@\"" -- "$@" +USR="${1:-root}" +shift 2>/dev/null || true + +if [ $# -gt 0 ]; then + SCRIPT="$1" + shift + exec chroot "$ROOT" /bin/su -l "$USR" -- -l -c "$SCRIPT" -- "$@" +else + exec chroot "$ROOT" /bin/su -l "$USR" -- -l +fi |