Skip to content
Snippets Groups Projects
Unverified Commit 49088b08 authored by Luke Shumaker's avatar Luke Shumaker Committed by Jan Alexander Steffens (heftig)
Browse files

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.
parent a1f8ac9c
No related branches found
No related tags found
No related merge requests found
...@@ -15,26 +15,28 @@ m4_include(lib/archroot.sh) ...@@ -15,26 +15,28 @@ m4_include(lib/archroot.sh)
shopt -s nullglob shopt -s nullglob
default_makepkg_args=(-s --noconfirm -L --holdver) init_variables() {
makepkg_args=("${default_makepkg_args[@]}") default_makepkg_args=(-s --noconfirm -L --holdver)
repack=false makepkg_args=("${default_makepkg_args[@]}")
update_first=false repack=false
clean_first=false update_first=false
run_namcap=false clean_first=false
temp_chroot=false run_namcap=false
chrootdir= temp_chroot=false
passeddir= chrootdir=
makepkg_user= passeddir=
declare -a install_pkgs makepkg_user=
declare -i ret=0 declare -ga install_pkgs
declare -gi ret=0
bindmounts_ro=()
bindmounts_rw=() bindmounts_ro=()
bindmounts_rw=()
copy=$USER
[[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER copy=$USER
[[ -z "$copy" || $copy = root ]] && copy=copy [[ -n ${SUDO_USER:-} ]] && copy=$SUDO_USER
src_owner=${SUDO_USER:-$USER} [[ -z "$copy" || $copy = root ]] && copy=copy
src_owner=${SUDO_USER:-$USER}
}
usage() { usage() {
echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]" echo "Usage: ${0##*/} [options] -r <chrootdir> [--] [makepkg args]"
...@@ -308,109 +310,115 @@ move_products() { ...@@ -308,109 +310,115 @@ move_products() {
} }
# }}} # }}}
while getopts 'hcur:I:l:nTD:d:U:' arg; do main() {
case "$arg" in init_variables
c) clean_first=true ;;
D) bindmounts_ro+=(--bind-ro="$OPTARG") ;; while getopts 'hcur:I:l:nTD:d:U:' arg; do
d) bindmounts_rw+=(--bind="$OPTARG") ;; case "$arg" in
u) update_first=true ;; c) clean_first=true ;;
r) passeddir="$OPTARG" ;; D) bindmounts_ro+=(--bind-ro="$OPTARG") ;;
I) install_pkgs+=("$OPTARG") ;; d) bindmounts_rw+=(--bind="$OPTARG") ;;
l) copy="$OPTARG" ;; u) update_first=true ;;
n) run_namcap=true; makepkg_args+=(-i) ;; r) passeddir="$OPTARG" ;;
T) temp_chroot=true; copy+="-$$" ;; I) install_pkgs+=("$OPTARG") ;;
U) makepkg_user="$OPTARG" ;; l) copy="$OPTARG" ;;
h|*) usage ;; n) run_namcap=true; makepkg_args+=(-i) ;;
esac T) temp_chroot=true; copy+="-$$" ;;
done U) makepkg_user="$OPTARG" ;;
h|*) usage ;;
[[ ! -f PKGBUILD && -z "${install_pkgs[*]}" ]] && die 'This must be run in a directory containing a PKGBUILD.' esac
[[ -n $makepkg_user && -z $(id -u "$makepkg_user") ]] && die 'Invalid makepkg user.' done
check_root [[ ! -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.'
# Canonicalize chrootdir, getting rid of trailing /
chrootdir=$(readlink -e "$passeddir") check_root
[[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
[[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir" # Canonicalize chrootdir, getting rid of trailing /
chrootdir=$(readlink -e "$passeddir")
if [[ ${copy:0:1} = / ]]; then [[ ! -d $chrootdir ]] && die "No chroot dir defined, or invalid path '%s'" "$passeddir"
copydir=$copy [[ ! -d $chrootdir/root ]] && die "Missing chroot dir root directory. Try using: mkarchroot %s/root base-devel" "$chrootdir"
else
copydir="$chrootdir/$copy" if [[ ${copy:0:1} = / ]]; then
fi copydir=$copy
else
# Pass all arguments after -- right to makepkg copydir="$chrootdir/$copy"
makepkg_args+=("${@:$OPTIND}") fi
# See if -R was passed to makepkg # Pass all arguments after -- right to makepkg
for arg in "${@:OPTIND}"; do makepkg_args+=("${@:$OPTIND}")
case ${arg%%=*} in
-*R*|--repackage) # See if -R was passed to makepkg
repack=true for arg in "${@:OPTIND}"; do
break 2 case ${arg%%=*} in
;; -*R*|--repackage)
esac repack=true
done break 2
;;
if [[ -n $SUDO_USER ]]; then esac
eval "USER_HOME=~$SUDO_USER" done
else
USER_HOME=$HOME if [[ -n $SUDO_USER ]]; then
fi eval "USER_HOME=~$SUDO_USER"
else
umask 0022 USER_HOME=$HOME
fi
load_vars "${XDG_CONFIG_HOME:-$USER_HOME/.config}/pacman/makepkg.conf" || load_vars "$USER_HOME/.makepkg.conf"
load_vars /etc/makepkg.conf umask 0022
# Use PKGBUILD directory if these don't exist load_vars "${XDG_CONFIG_HOME:-$USER_HOME/.config}/pacman/makepkg.conf" || load_vars "$USER_HOME/.makepkg.conf"
[[ -d $PKGDEST ]] || PKGDEST=$PWD load_vars /etc/makepkg.conf
[[ -d $SRCDEST ]] || SRCDEST=$PWD
[[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD # Use PKGBUILD directory if these don't exist
[[ -d $LOGDEST ]] || LOGDEST=$PWD [[ -d $PKGDEST ]] || PKGDEST=$PWD
[[ -d $SRCDEST ]] || SRCDEST=$PWD
# Lock the chroot we want to use. We'll keep this lock until we exit. [[ -d $SRCPKGDEST ]] || SRCPKGDEST=$PWD
lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy" [[ -d $LOGDEST ]] || LOGDEST=$PWD
if [[ ! -d $copydir ]] || $clean_first; then # Lock the chroot we want to use. We'll keep this lock until we exit.
sync_chroot "$chrootdir" "$copy" lock 9 "$copydir.lock" "Locking chroot copy [%s]" "$copy"
fi
if [[ ! -d $copydir ]] || $clean_first; then
$update_first && arch-nspawn "$copydir" \ sync_chroot "$chrootdir" "$copy"
fi
$update_first && arch-nspawn "$copydir" \
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
pacman -Syu --noconfirm
if [[ -n ${install_pkgs[*]:-} ]]; then
install_packages "$copydir" "${install_pkgs[@]}"
ret=$?
# If there is no PKGBUILD we have done
[[ -f PKGBUILD ]] || return $ret
fi
download_sources "$copydir" "$src_owner"
prepare_chroot "$copydir" "$USER_HOME" "$repack"
if arch-nspawn "$copydir" \
--bind="$PWD:/startdir" \
--bind="$SRCDEST:/srcdest" \
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \ "${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
pacman -Syu --noconfirm /chrootbuild "${makepkg_args[@]}"
then
move_products "$copydir" "$src_owner"
else
(( ret += 1 ))
fi
if [[ -n ${install_pkgs[*]:-} ]]; then $temp_chroot && delete_chroot "$copydir" "$copy"
install_packages "$copydir" "${install_pkgs[@]}"
ret=$? if (( ret != 0 )); then
# If there is no PKGBUILD we have done if $temp_chroot; then
[[ -f PKGBUILD ]] || return $ret die "Build failed"
fi else
die "Build failed, check %s/build" "$copydir"
download_sources "$copydir" "$src_owner" fi
prepare_chroot "$copydir" "$USER_HOME" "$repack"
if arch-nspawn "$copydir" \
--bind="$PWD:/startdir" \
--bind="$SRCDEST:/srcdest" \
"${bindmounts_ro[@]}" "${bindmounts_rw[@]}" \
/chrootbuild "${makepkg_args[@]}"
then
move_products "$copydir" "$src_owner"
else
(( ret += 1 ))
fi
$temp_chroot && delete_chroot "$copydir" "$copy"
if (( ret != 0 )); then
if $temp_chroot; then
die "Build failed"
else else
die "Build failed, check %s/build" "$copydir" true
fi fi
else }
true
fi main "$@"
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