Hugo Package Install on MacOS
Beginning with version v0.153.0, the Hugo developers starting shipping the MacOS release of Hugo as a Mac-native pkg file rather than in the traditional compressed tar format.
Since I use Hugo to build this site, I had long maintained a shell script that automated the installation of the old tar.gz distribution files, so I needed to rework my script to deal with the pkg file. The reworked version is below.
The only note I’ll make is that the script uses wget rather than curl to fetch the pkg file from GitHub. wget is more graceful at following the sort of redirects github.com puts in place for downloads.
#!/bin/bash
#
# fetch and install hugo package. this script requires wget, which
# isn't part of a standard MacOS installation.
#
# ====================================================================
ME="$(basename $0)"
VERS="$1"
SAMPLEVERS="0.153.2"
if test -z "$VERS"; then
echo "usage: $ME <hugo-version>"
echo " ex: $ME $SAMPLEVERS"
exit 1
fi
# location for package download
STGDIR="${HOME}/Downloads/hugo"
# remote file information
HUGOPKG="hugo_${VERS}_darwin-universal.pkg"
HUGOSITE="https://github.com/gohugoio/hugo/releases/download/v${VERS}/${HUGOPKG}"
# create staging directory if it doesn't exist; neither
# this directory nor its contents will be deleted when
# this script finishes -- but any content there now will
# soon get zapped.
if test ! -d "$STGDIR"; then mkdir -v "$STGDIR"; fi
# enter staging directory
pushd "$STGDIR"
# said zapping
/bin/rm -fv *
# use wget to fetch package because it follows redirects without asking
wget "$HUGOSITE"
# if redirect is not followed correctly, the download is not
# a pkg file, so this op will fail.
/usr/sbin/installer -pkginfo -pkg $HUGOPKG
if test $? -ne 0; then
echo "FATAL: Package download failed. Exiting now."
exit 1
fi
# do the installation
sudo /usr/sbin/installer -pkg $HUGOPKG -target /
# exit staging directory
popd
# prove we've got what we need
hugo version
# fin