From 6689047a779b248e3444821344a71a7498f405a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 1 May 2019 13:24:07 +0200 Subject: uchroot: fix for qemu hosted systems It seems that because in case of qemu run ash it does not detect that it should a loggin shell. This changes uchroot so it forces ash to be always logging shell. This also makes user argument optional --- scripts/uchroot | 33 +++++++++++++++------------------ 1 file 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 -- cgit v1.2.3