makechrootpkg: Avoid having code floating around outside of a function.

This means wrapping variable initialization in init_variables(), and the
main program routine in main().

I did NOT put `shopt -s nullglob` in to a function.

It make make sense to move init_variables() down into the main()
function, instead of having it as a separate function up top (if this
done, then the `-g` flag passed to `declare` in init_variables() can
be dropped).  However, in interest of keeping the `diff -w` small, and
merges/rebases simpler, this isn't done here.
This commit is contained in:
Luke Shumaker 2017-04-05 19:06:10 -04:00 committed by Jan Alexander Steffens (heftig)
parent a1f8ac9c70
commit 49088b0860
No known key found for this signature in database
GPG Key ID: A5E9288C4FA415FA
1 changed files with 125 additions and 117 deletions

View File

@ -15,6 +15,7 @@ m4_include(lib/archroot.sh)
shopt -s nullglob
init_variables() {
default_makepkg_args=(-s --noconfirm -L --holdver)
makepkg_args=("${default_makepkg_args[@]}")
repack=false
@ -25,8 +26,8 @@ temp_chroot=false
chrootdir=
passeddir=
makepkg_user=
declare -a install_pkgs
declare -i ret=0
declare -ga install_pkgs
declare -gi ret=0
bindmounts_ro=()
bindmounts_rw=()
@ -35,6 +36,7 @@ copy=$USER
[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER
[[ -z "$copy" || $copy = root ]] && copy=copy
src_owner=${SUDO_USER:-$USER}
}
usage() {
echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]"
@ -308,6 +310,9 @@ move_products() {
}
# }}}
main() {
init_variables
while getopts 'hcur:I:l:nTD:d:U:' arg; do
case "$arg" in
c) clean_first=true ;;
@ -414,3 +419,6 @@ if (( ret != 0 )); then
else
true
fi
}
main "$@"