Revert "makechrootpkg: Have functions be more function-y."

This reverts (the bulk of) commit 2fd5931a8c.

Reducing globals makes little sense in in a oneshot bash script, but
reduces code clarity and in fact resulted in bugs because even the
commit author couldn't keep track of the script state.

An exit was changed to a return, even though that made no sense outside
of a function, and has been duly returned to being an exit. This was
never tested and later papered over by wrapping the entire script in a
main() function and then calling the function for hysterical raisins.

The functiony nature of sync_chroot/delete_chroot is preserved, as those
functions demonstrate meaningfully standalone functionality -- who
knows? we may want to reuse this. Everything else is tightly bound to
the internal logic of makechrootpkg.

Completely separate functionality that was silently implemented in the
original commit is also preserved:
- declare a couple of variables as locals
- move the abort-on-no-PKGBUILD outside the install_packages function

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Levente Polyak <anthraxx@archlinux.org>
This commit is contained in:
Eli Schwartz 2019-02-13 02:23:51 -05:00 committed by Levente Polyak
parent df0d6b867b
commit 46d614d91a
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
1 changed files with 6 additions and 33 deletions

View File

@ -151,11 +151,7 @@ delete_chroot() {
stat_done
}
# Usage: install_packages $copydir $pkgs...
install_packages() {
local copydir=$1
local install_pkgs=("${@:2}")
local -a pkgnames
local ret
@ -170,16 +166,7 @@ install_packages() {
return $ret
}
# Usage: prepare_chroot $copydir $HOME $keepbuilddir $run_namcap
# Globals:
# - MAKEFLAGS
# - PACKAGER
prepare_chroot() {
local copydir=$1
local USER_HOME=$2
local keepbuilddir=$3
local run_namcap=$4
[[ $keepbuilddir = true ]] || rm -rf "$copydir/build"
local builduser_uid builduser_gid
@ -258,13 +245,7 @@ _chrootnamcap() {
done
}
# Usage: download_sources $copydir $makepkg_user
# Globals:
# - SRCDEST
download_sources() {
local copydir=$1
local makepkg_user=$2
setup_workdir
chown "$makepkg_user:" "$WORKDIR"
@ -275,15 +256,7 @@ download_sources() {
die "Could not download sources."
}
# Usage: move_products $copydir $owner
# Globals:
# - PKGDEST
# - LOGDEST
# - SRCPKGDEST
move_products() {
local copydir=$1
local src_owner=$2
local pkgfile
for pkgfile in "$copydir"/pkgdest/*; do
chown "$src_owner" "$pkgfile"
@ -389,10 +362,10 @@ $update_first && arch-nspawn "$copydir" \
pacman -Syu --noconfirm
if [[ -n ${install_pkgs[*]:-} ]]; then
install_packages "$copydir" "${install_pkgs[@]}"
install_packages
ret=$?
# If there is no PKGBUILD we have done
[[ -f PKGBUILD ]] || return $ret
# If there is no PKGBUILD we are done
[[ -f PKGBUILD ]] || exit $ret
fi
if [[ "$(id -u "$makepkg_user")" == 0 ]]; then
@ -400,9 +373,9 @@ if [[ "$(id -u "$makepkg_user")" == 0 ]]; then
exit 1
fi
download_sources "$copydir" "$makepkg_user"
download_sources
prepare_chroot "$copydir" "$USER_HOME" "$keepbuilddir" "$run_namcap"
prepare_chroot
if arch-nspawn "$copydir" \
--bind="$PWD:/startdir" \
@ -410,7 +383,7 @@ if arch-nspawn "$copydir" \
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
/chrootbuild "${makepkg_args[@]}"
then
move_products "$copydir" "$src_owner"
move_products
else
(( ret += 1 ))
fi