summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2020-08-19 13:26:50 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2022-08-30 20:40:24 -0400
commitde5205f21a660ebe0e338ec87905c420afdbe353 (patch)
treee9ba903534e708b8b44b824a9c10be4c8dbfdeff
parentdb736c6104d6497d735c4c987768fd136d297661 (diff)
verify mksource() source-balls, and handle them gracefully
-rw-r--r--makechrootpkg.in94
1 files changed, 93 insertions, 1 deletions
diff --git a/makechrootpkg.in b/makechrootpkg.in
index c099a71..492991e 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -29,10 +29,22 @@ usage() {
echo 'command:'
echo ' mkarchroot <chrootdir>/root base-devel'
echo ''
+ echo 'Note that this script is not normally initiated by the user,'
+ echo 'but is used internally by `libremakepkg`. `libremakepkg` is the'
+ echo 'preferred tool for building "release-ready" Parabola packages.'
+ echo 'When using `libremakepkg`, create the chroot with `librechroot`.'
+ echo ''
echo 'This script reads {SRC,SRCPKG,PKG,LOG}DEST, MAKEFLAGS and PACKAGER'
echo 'from makepkg.conf(5), if those variables are not part of the'
echo 'environment.'
echo ''
+ echo 'Note that, when run on a PKGBUILD which includes a mksource() function,'
+ echo 'and if a new libre source-ball was created as a result,'
+ echo 'or if the libre sources do not match the checksums in the PKGBUILD,'
+ echo 'this script will inject the correct checksums into the PKGBUILD,'
+ echo 'fork a new instance of the calling process to handle it'
+ echo '(usually libremakepkg), and exit immediately'
+ echo ''
echo "Default makepkg args: ${default_makepkg_args[*]}"
echo ''
echo 'Flags:'
@@ -256,6 +268,41 @@ _chrootnamcap() {
done
}
+
+# Usage: VerifyLibreSources
+# Description: verify the number of libre source-balls which should be,
+# and were downloaded/created via the mksource() mechanism
+# Globals:
+# - SRCDEST
+# Output:
+# - "N N" (n_srcs_required n_srcs_exist)
+VerifyLibreSources()
+(
+ local src_n src_file_url src_file repo
+ local is_libre_src src_exists is_sig
+ local n_srcs_required=0
+ local n_srcs_exist=0
+
+ load_conf librefetch.conf MIRRORS || exit
+ source PKGBUILD ; cd ${SRCDEST} ;
+
+ for (( src_n=0 ; src_n < ${#source[@]} ; ++src_n ))
+ do src_file_url=${source[src_n]}
+ src_file=${src_file_url##*/}
+
+ for repo in "${MIRRORS[@]}"
+ do is_libre_src=$( [[ "$src_file_url" == "$repo"* ]] && echo 1 || echo 0 )
+ src_exists=$( [[ -f "${src_file}" ]] && echo 1 || echo 0 )
+ is_sig=$( [[ "${src_file/*.}" =~ (asc|sig) ]] && echo 1 || echo 0 )
+ (( is_libre_src )) && n_srcs_required=$(( ++n_srcs_required )) &&
+ (( src_exists || is_sig )) && n_srcs_exist=$(( ++n_srcs_exist ))
+ done
+ done
+
+ echo "${n_srcs_required} ${n_srcs_exist}"
+)
+
+
# Usage: download_sources $copydir $makepkg_user
# Globals:
# - SRCDEST
@@ -264,6 +311,10 @@ _chrootnamcap() {
download_sources() {
local copydir=$1
local makepkg_user=$2
+ local n_libre_sources_in=$(VerifyLibreSources)
+ local n_libre_sources_out n_libre_sources_required n_libre_sources_exist
+ local sums_msg done_msg restart_msg rerun_msg fail_msg die_msg
+ local this_cmd=() h_rule
local builddir
builddir="$(mktemp -d)"
@@ -273,10 +324,51 @@ download_sources() {
sudo -u "$makepkg_user" --preserve-env=GNUPGHOME \
env SRCDEST="$SRCDEST" SRCPKGDEST="$SRCPKGDEST" PKGDEST="$PKGDEST" BUILDDIR="$builddir" \
makepkg --config="$copydir/etc/makepkg.conf" --allsource ||
- die "Could not download sources."
+ : # die "Could not download sources."
+ if (( $? ))
+ then # Ensure that all libre sources have been downloaded,
+ # or created via the mksource() mechanism.
+ # There are multiple reasons for why the preceding `makepkg` invokation may have failed
+ # (invalid checksums/sigs, download failure, borked PKGBUILD, etc);
+ # so we must deduce the cause of failure here.
+ # The expected failure here, is invalid checksum(s) for the newly created libre sources.
+ # In that case, we inject the new checksum(s) into the PKGBUILD,
+ # then fork a new instance of libremakepkg, and exit this process.
+ n_libre_sources_out=$(VerifyLibreSources)
+ n_libre_sources_required=${n_libre_sources_out% *}
+ n_libre_sources_exist=${n_libre_sources_out#* }
+ sums_msg="Running \`updpkgsums\` to account for the newly created libre source-ball(s)"
+ done_msg="MkSource completed successfully"
+ restart_msg="Restarting libremakepkg to complete the build"
+ rerun_msg="Run libremakepkg again to complete the build"
+ fail_msg="Could not download upstream sources"
+ this_cmd=( $(ps --pid=$$ --format=args --no-headers) )
+ h_rule="--$(dd if=/dev/zero bs=${#restart_msg} count=1 2> /dev/null | tr '\0' '-')--"
+
+ if [[ "$n_libre_sources_out" != "$n_libre_sources_in" ]] &&
+ (( n_libre_sources_exist + n_libre_sources_required )) &&
+ (( n_libre_sources_exist == n_libre_sources_required ))
+ then echo "${sums_msg}"
+ sudo -u "$makepkg_user" updpkgsums
+ echo "${done_msg}"
+
+ if [[ "${this_cmd[@]}" =~ ([^\ ]*libremakepkg)(\ .*)? ]]
+ then this_cmd=(${BASH_REMATCH[@]:1})
+
+ echo -e "\n${h_rule}\n| ${restart_msg} |\n${h_rule}\n"
+ sleep 5 && ${this_cmd[@]} &
+
+ die_msg='<EMPTY>'
+ else die_msg="${rerun_msg}"
+ fi
+ else die_msg="${fail_msg}"
+ fi
+ fi
# Clean up garbage from verifysource
rm -rf "$builddir"
+
+ [[ -z "${die_msg}" ]] || die "${die_msg/<EMPTY>/}"
}
# Usage: move_products $copydir $owner