[arch-projects] [DEVTOOLS][PATCH] check_root must be run before args parsing

Sébastien Luttringer seblu at seblu.net
Sat May 17 04:37:33 EDT 2014


check_root function reexecute the running script with sudo (or su) and needs all
arguments to be untouched. So we have to run it before args parsing,
which may call shift.

Thanks to Jan Steffens for reporting it.
---
 arch-nspawn.in   | 3 ++-
 archbuild.in     | 4 ++--
 makechrootpkg.in | 4 ++--
 mkarchroot.in    | 4 ++--
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch-nspawn.in b/arch-nspawn.in
index 4436a0e..f0517de 100644
--- a/arch-nspawn.in
+++ b/arch-nspawn.in
@@ -10,6 +10,8 @@
 
 m4_include(lib/common.sh)
 
+check_root "$0" "$@"
+
 CHROOT_VERSION='v3'
 
 working_dir=''
@@ -38,7 +40,6 @@ done
 shift $(($OPTIND - 1))
 
 (( $# < 1 )) && die 'You must specify a directory.'
-check_root "$0" "$@"
 
 working_dir=$(readlink -f "$1")
 shift 1
diff --git a/archbuild.in b/archbuild.in
index ae2f511..e0e03ee 100644
--- a/archbuild.in
+++ b/archbuild.in
@@ -2,6 +2,8 @@
 
 m4_include(lib/common.sh)
 
+check_root "$0" "$@"
+
 base_packages=(base-devel)
 makechrootpkg_args=(-c -n)
 
@@ -40,8 +42,6 @@ done
 # Pass all arguments after -- right to makepkg
 makechrootpkg_args+=("${@:$OPTIND}")
 
-check_root "$0" "$@"
-
 if ${clean_first} || [[ ! -d "${chroots}/${repo}-${arch}" ]]; then
 	msg "Creating chroot for [${repo}] (${arch})..."
 
diff --git a/makechrootpkg.in b/makechrootpkg.in
index 97c7780..dbfe946 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -10,6 +10,8 @@
 
 m4_include(lib/common.sh)
 
+check_root "$0" "$@"
+
 shopt -s nullglob
 
 makepkg_args='-s --noconfirm -L --holdver'
@@ -81,8 +83,6 @@ while getopts 'hcur:I:l:nTD:d:' arg; do
 	esac
 done
 
-check_root "$0" "$@"
-
 [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
 
 # Canonicalize chrootdir, getting rid of trailing /
diff --git a/mkarchroot.in b/mkarchroot.in
index fb472bc..e0fbeef 100644
--- a/mkarchroot.in
+++ b/mkarchroot.in
@@ -10,6 +10,8 @@
 
 m4_include(lib/common.sh)
 
+check_root "$0" "$@"
+
 CHROOT_VERSION='v3'
 
 working_dir=''
@@ -37,8 +39,6 @@ shift $(($OPTIND - 1))
 
 (( $# < 2 )) && die 'You must specify a directory and one or more packages.'
 
-check_root "$0" "$@"
-
 working_dir="$(readlink -f $1)"
 shift 1
 
-- 
Sébastien "Seblu" Luttringer



More information about the arch-projects mailing list