diff --git a/run.sh b/run.sh index 0b04297..ae72481 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,11 @@ #!/usr/bin/env bash help () { - echo 'dchr-run [command]' + echo 'dchr-run [options] [command]' + echo '-- options:' + echo ' -u uid[:gid] invoke command in chroot as a different user' + # TODO: + #echo ' -x11 apply options for correctly starting GUI apps' echo 'https://dchr.dc09.ru' } @@ -28,22 +32,43 @@ setup () { runcmd () { echo -e '-- \e[1;32mOK\e[0m -- running chroot' - chrdir="$1" - shift + userspec="--userspec=$1" + chrdir="$2" + shift 2 chrcmd=("$@") - chroot "$chrdir" "${chrcmd[@]}" + chroot "$userspec" "$chrdir" "${chrcmd[@]}" } main () { [[ "$1" == "--help" || "$1" == "" ]] && help && exit 0 + userspec="$(id -u):$(id -g)" + + while [[ "$1" == -* ]] + do + case "$1" in + -u) + userspec="$2" + shift 2 + ;; + #-x11);; TODO + *) + echo -ne '-- \e[1mInvalid option:\e[0m ' + echo "$1" + echo '-- Use ./ or full path if your chroot-dir starts with dash (-)' + help + exit 2 + ;; + esac + done + chrdir=$(readlink -f "$1") shift trap "clean \"$chrdir\"" EXIT setup "$chrdir" - runcmd "$chrdir" "$@" + runcmd "$userspec" "$chrdir" "$@" exit $? }