lib/archroot.sh: Simplify check_root
Move the function and save the orig_argv right along it.
This commit is contained in:
parent
66553e7e07
commit
45f87aa9d5
|
@ -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
|
||||||
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
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/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() {
|
||||||
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
|
||||||
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}")
|
||||||
|
|
|
@ -1 +1,14 @@
|
||||||
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() {
|
||||||
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 @@
|
||||||
# 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() {
|
||||||
}
|
}
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
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
|
||||||
[[ ! -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() {
|
||||||
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))
|
||||||
|
|
||||||
(( $# < 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
|
||||||
|
|
Loading…
Reference in New Issue