Skip to content
Snippets Groups Projects
Unverified Commit 45f87aa9 authored by Jan Alexander Steffens (heftig)'s avatar Jan Alexander Steffens (heftig)
Browse files

lib/archroot.sh: Simplify check_root

Move the function and save the orig_argv right along it.
parent 66553e7e
No related branches found
No related tags found
No related merge requests found
...@@ -25,8 +25,6 @@ usage() { ...@@ -25,8 +25,6 @@ usage() {
exit 1 exit 1
} }
orig_argv=("$@")
while getopts 'hC:M:c:' arg; do while getopts 'hC:M:c:' arg; do
case "$arg" in case "$arg" in
C) pac_conf="$OPTARG" ;; C) pac_conf="$OPTARG" ;;
...@@ -39,7 +37,7 @@ done ...@@ -39,7 +37,7 @@ done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
(( $# < 1 )) && die 'You must specify a directory.' (( $# < 1 )) && die 'You must specify a directory.'
check_root "$0" "${orig_argv[@]}" check_root
working_dir=$(readlink -f "$1") working_dir=$(readlink -f "$1")
shift 1 shift 1
......
#!/bin/bash #!/bin/bash
m4_include(lib/common.sh) m4_include(lib/common.sh)
m4_include(lib/archroot.sh)
base_packages=(base-devel) base_packages=(base-devel)
makechrootpkg_args=(-c -n) makechrootpkg_args=(-c -n)
...@@ -29,8 +30,6 @@ usage() { ...@@ -29,8 +30,6 @@ usage() {
exit 1 exit 1
} }
orig_argv=("$@")
while getopts 'hcr:' arg; do while getopts 'hcr:' arg; do
case "${arg}" in case "${arg}" in
c) clean_first=true ;; c) clean_first=true ;;
...@@ -39,7 +38,7 @@ while getopts 'hcr:' arg; do ...@@ -39,7 +38,7 @@ while getopts 'hcr:' arg; do
esac esac
done done
check_root "$0" "${orig_argv[@]}" check_root
# Pass all arguments after -- right to makepkg # Pass all arguments after -- right to makepkg
makechrootpkg_args+=("${@:$OPTIND}") makechrootpkg_args+=("${@:$OPTIND}")
......
CHROOT_VERSION='v4' CHROOT_VERSION='v4'
##
# usage : check_root
##
orig_argv=("$0" "$@")
check_root() {
(( EUID == 0 )) && return
if type -P sudo >/dev/null; then
exec sudo -- "${orig_argv[@]}"
else
exec su root -c "$(printf ' %q' "${orig_argv[@]}")"
fi
}
...@@ -227,15 +227,3 @@ find_cached_package() { ...@@ -227,15 +227,3 @@ find_cached_package() {
return 1 return 1
esac esac
} }
##
# usage : check_root ("$0" "$@")
##
check_root() {
(( EUID == 0 )) && return
if type -P sudo >/dev/null; then
exec sudo -- "$@"
else
exec su root -c "$(printf ' %q' "$@")"
fi
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
# GNU General Public License for more details. # GNU General Public License for more details.
m4_include(lib/common.sh) m4_include(lib/common.sh)
m4_include(lib/archroot.sh)
shopt -s nullglob shopt -s nullglob
...@@ -258,8 +259,6 @@ move_products() { ...@@ -258,8 +259,6 @@ move_products() {
} }
# }}} # }}}
orig_argv=("$@")
while getopts 'hcur:I:l:nTD:d:U:' arg; do while getopts 'hcur:I:l:nTD:d:U:' arg; do
case "$arg" in case "$arg" in
c) clean_first=true ;; c) clean_first=true ;;
...@@ -279,7 +278,7 @@ done ...@@ -279,7 +278,7 @@ done
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' [[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.'
[[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.' [[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.'
check_root "$0" "${orig_argv[@]}" check_root
# Canonicalize chrootdir, getting rid of trailing / # Canonicalize chrootdir, getting rid of trailing /
chrootdir=$(readlink -e "$passeddir") chrootdir=$(readlink -e "$passeddir")
......
...@@ -23,8 +23,6 @@ usage() { ...@@ -23,8 +23,6 @@ usage() {
exit 1 exit 1
} }
orig_argv=("$@")
while getopts 'hC:M:c:' arg; do while getopts 'hC:M:c:' arg; do
case "$arg" in case "$arg" in
C) pac_conf="$OPTARG" ;; C) pac_conf="$OPTARG" ;;
...@@ -38,7 +36,7 @@ shift $(($OPTIND - 1)) ...@@ -38,7 +36,7 @@ shift $(($OPTIND - 1))
(( $# < 2 )) && die 'You must specify a directory and one or more packages.' (( $# < 2 )) && die 'You must specify a directory and one or more packages.'
check_root "$0" "${orig_argv[@]}" check_root
working_dir="$(readlink -f $1)" working_dir="$(readlink -f $1)"
shift 1 shift 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment