diff options
author | bill-auger <mr.j.spam.me@gmail.com> | 2021-01-14 05:27:49 -0500 |
---|---|---|
committer | bill-auger <mr.j.spam.me@gmail.com> | 2021-01-23 00:54:46 -0500 |
commit | 110ddb6e047099fb3c40acceccefa9351ee82012 (patch) | |
tree | 99db1d5e8035ad0473b5e202a3f17c5e3300f32d | |
parent | f826ac534156270dd126285ae68d571fd877e259 (diff) |
makepkg: update mksource checksums
-rw-r--r-- | scripts/makepkg.sh.in | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index c9e381d5..478d0d76 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1011,6 +1011,44 @@ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } +# update mksource checksums, if $BUILDFILE is a temporary mksource() PKGBUILD +# Gobals: +# - $BUILDFILE +update_mksums() { + declare -r PKGBUILD="$(dirname $BUILDFILE)"/PKGBUILD + local padding + local mksums + local mksums_ind + + if [[ -f "$BUILDFILE" && -w "$BUILDFILE" ]] && # temporary mksource PKGBUILD + [[ -f "$PKGBUILD" && -w "$PKGBUILD" ]]; then # the real PKGBUILD + updpkgsums "$BUILDFILE" + source_safe "$BUILDFILE" + + for algo in ${known_hash_algos[*]}; do + for array in mk${algo}sums{,_armv7h,_i686,_x86_64}; do + if grep "^[[:blank:]]*$array=(" "$PKGBUILD" > /dev/null; then + padding=$(printf "%${#array}s ") + mksums_ind="${array}[@]" + mksums="'$(sed "s| |'\n$padding'|g" <<<${!mksums_ind})'" + + awk -v array=$array \ + -v array_rx="^[ ]*${array}=" \ + -v mksums="$mksums" \ + '$0 ~ array_rx , /^[^#]*\)/ { m=NR } \ + NR == m + 1 && !!m { print array"=("mksums")" } \ + NR != m { print } ' \ + "$PKGBUILD" > "$PKGBUILD".tmp + cat -- "$PKGBUILD".tmp > "$PKGBUILD" ; rm "$PKGBUILD".tmp ; + fi + done + done + else + error "$(gettext "%s is not writeable -- checksums will not be updated")" "$BUILDFILE" + exit $E_PKGBUILD_ERROR + fi +} + # PROGRAM START # ensure we have a sane umask set @@ -1223,6 +1261,11 @@ pkgbase=${pkgbase:-${pkgname[0]}} # check the PKGBUILD for some basic requirements lint_pkgbuild || exit $E_PKGBUILD_ERROR +# detect temporary mksource PKGBUILD +declare -r MKSOURCE_RX='librefetch\.[^\ ]{11}\.PKGBUILD\.to\.SRCBUILD$' +declare -r IS_MKSOURCE=$( [[ "$BUILDFILE" =~ $MKSOURCE_RX ]] && echo 1 || echo 0 ) + + if (( !SOURCEONLY && !PRINTSRCINFO )); then merge_arch_attrs fi @@ -1246,7 +1289,13 @@ if (( GENINTEG )); then chmod a-s "$srcdir" cd_safe "$srcdir" download_sources novcs allarch >&2 - generate_checksums + + # trick `updpkgsums` into updating mk*sums(), if this is temporary mksource() PKGBUILD + if (( IS_MKSOURCE )); then + generate_checksums | sed 's|^\(.*\)=(|mk\1=(|g' + else # standard behavior + generate_checksums + fi exit $E_OK fi @@ -1409,7 +1458,22 @@ if (( !REPKG )); then warning "$(gettext "Using existing %s tree")" "\$srcdir/" else download_sources - check_source_integrity + if ! ( check_source_integrity ); then + # offer to update mksource checksums, if $BUILDFILE is a temporary mksource() PKGBUILD + if (( IS_MKSOURCE )); then + warning "$(gettext "The PKGBUILD checksums do not match the upstream mksource().")" + echo -en "\n$(gettext "Run \`updpkgsums\` to account for the mksource() checksums mismatch?")" + read -p " [y/N] " -n 1 -r ; echo ; + if [[ $REPLY =~ ^[yY]$ ]]; then + update_mksums + else + exit $E_PKGBUILD_ERROR + fi + else # standard behavior + exit $E_PKGBUILD_ERROR + fi + fi + (( VERIFYSOURCE )) && exit $E_OK if (( CLEANBUILD )); then |