From 41d4624879d01b1269d6af9c1440592a15ad7784 Mon Sep 17 00:00:00 2001 From: Levente Polyak Date: Sat, 20 May 2023 00:20:41 +0200 Subject: fix(archroot): pass along the real command and argv by the caller Before modularizing the repo layout, we used m4_include to assemble together sources into a single file. Now, we properly use a library layout without assembling multiple files, which means we cannot anymore rely on BASH_SOURCE inside the library file. Hence, pass along the actual command and argv from the check_root caller. Fixes: src: modularize repo layout into a library Signed-off-by: Morten Linderud Signed-off-by: Levente Polyak --- src/lib/archroot.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/lib/archroot.sh') diff --git a/src/lib/archroot.sh b/src/lib/archroot.sh index d7917da..3f48dc1 100644 --- a/src/lib/archroot.sh +++ b/src/lib/archroot.sh @@ -9,13 +9,14 @@ CHROOT_VERSION='v4' ## # usage : check_root $keepenv ## -orig_argv=("${BASH_SOURCE[0]}" "$@") check_root() { local keepenv=$1 + shift + local orig_argv=("$@") (( EUID == 0 )) && return if type -P sudo >/dev/null; then - exec sudo --preserve-env=$keepenv -- "${orig_argv[@]}" + exec sudo --preserve-env="${keepenv}" -- "${orig_argv[@]}" else exec su root -c "$(printf ' %q' "${orig_argv[@]}")" fi -- cgit v1.2.3-54-g00ecf