From 3618382d07d166be2c1b7c7d4047cd985c97c6ce Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Mon, 8 Jul 2024 13:27:47 -0300 Subject: [PATCH] Handle BSD checksum and file utilities (#14690) * Handle BSD checksum utilities The BSDs have different checksum utilities than GNU systems do. If we don't see the GNU checksum utilities installed, use the BSD ones, as their output is compatible enough. Addresses part of GH-14688. * Prefer GNU touch BSD touch at least in macOS does not handle local timezone in the timestamp (like 2024-06-27T10:26:23-03:00). As such, try GNU touch (as ports systems almost always prefix with g if coreutils is installed) and prefer that if available. It's not the end of the world though if GNU touch isn't available, as BSD touch on some systems may support it, and if it doesn't, then it's just timestamps, nothing too serious. --- scripts/dev/gen_verify_stub | 6 +++++- scripts/dev/makedist | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/scripts/dev/gen_verify_stub b/scripts/dev/gen_verify_stub index f326230e5d4c1..f9d9cc67ee3ea 100755 --- a/scripts/dev/gen_verify_stub +++ b/scripts/dev/gen_verify_stub @@ -1,5 +1,9 @@ #!/bin/bash +# Handle GNU vs. BSD checksum utilities +sha256sum="$(which sha256sum)" +sha256sum="${sha256sum:-$(which shasum) -a 256}" + if [ "x$1" == "x" ] then echo "Usage: $0 [email]" @@ -41,7 +45,7 @@ done for TARBALL in "$PHPROOT/php-$RELEASE_VER.tar.bz2" "$PHPROOT/php-$RELEASE_VER.tar.gz" "$PHPROOT/php-$RELEASE_VER.tar.xz" do basename $TARBALL - echo "SHA256 hash: `sha256sum $TARBALL | cut -d' ' -f1`"; + echo "SHA256 hash: `$sha256sum $TARBALL | cut -d' ' -f1`"; echo PGP signature: cat $TARBALL.asc echo -e "\n" diff --git a/scripts/dev/makedist b/scripts/dev/makedist index ffdf536907651..48e54cffaaf79 100755 --- a/scripts/dev/makedist +++ b/scripts/dev/makedist @@ -9,6 +9,14 @@ tar="$(which gtar)" tar="${tar:-$(which tar)}" +# Handle GNU vs. BSD checksum utilities +md5sum="$(which md5sum)" +md5sum="${md5sum:-$(which md5)}" + +# GNU touch is preferred since it handles local TZ in timestamps +touch="$(which gtouch)" +touch="${touch:-$(which touch)}" + if [[ $($tar --version) == *"bsdtar"* ]]; then echo "Found bsdtar at $tar, but this script needs GNU tar." exit 1 @@ -169,8 +177,8 @@ fi # Reset the modification and access times of all files to be packaged. commitDate="$(git log -1 --format=%cI $treeish)" echo "makedist: Resetting the modification and access times of package files to $commitDate" -touch -c -d"$commitDate" NEWS -find . -exec touch -r NEWS -c {} \; +"$touch" -c -d"$commitDate" NEWS +find . -exec "$touch" -r NEWS -c {} \; cd .. @@ -181,7 +189,7 @@ rm -rf "$prefix" "$prefix".tar.* echo "makedist: Creating $prefix.tar.gz archive." gzip -9 -k "$prefix".tar || exit 6 -md5sum "$prefix".tar.gz +"$md5sum" "$prefix".tar.gz gzip -t "$prefix".tar.gz sync @@ -189,7 +197,7 @@ sleep 2 echo "makedist: Creating $prefix.tar.bz2 archive." bzip2 -9 -k $prefix.tar || exit 7 -md5sum $prefix.tar.bz2 +"$md5sum" $prefix.tar.bz2 bzip2 -t $prefix.tar.bz2 sync @@ -197,7 +205,7 @@ sleep 2 echo "makedist: Creating $prefix.tar.xz archive." xz -9 -k "$prefix".tar || exit 9 -md5sum "$prefix".tar.xz +"$md5sum" "$prefix".tar.xz xz -t "$prefix".tar.xz echo ""