Last active
October 17, 2019 07:36
-
-
Save ikskuh/e94575792627c133b3df01a2c39d805c to your computer and use it in GitHub Desktop.
Zig updater script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# allows installing and/or updating your local | |
# zig installation. | |
# | |
# adjust INSTALLDIR, ZIG_OS, ZIG_TARGET to | |
# configure your installation. | |
# | |
# prerequisites: | |
# - jq (https://stedolan.github.io/jq/) | |
# - curl (https://curl.haxx.se/) | |
INSTALLDIR=/home/felix/zig | |
ZIG_OS=linux | |
ZIG_TARGET=x86_64-${ZIG_OS} | |
JSON_SOURCE=https://ziglang.org/download/index.json | |
ZIG_VERSION=master | |
TEMPFILE=/tmp/zig-versions.json | |
VERSFILE=${INSTALLDIR}.version | |
function die() | |
{ | |
echo "$@" >&2 | |
exit 1 | |
} | |
if test ! -d ${INSTALLDIR}; then | |
echo "Installdir does not exist or is not a directory!" | |
exit 1 | |
fi | |
echo "Fetching metadata…" | |
curl -s "${JSON_SOURCE}" | jq ".\"${ZIG_VERSION}\".\"${ZIG_TARGET}\"" > ${TEMPFILE} || die "Failed to fetch metadata!" | |
TARBALL_SOURCE=$(jq --raw-output .tarball ${TEMPFILE}) | |
TARBALL_SHASUM=$(jq --raw-output .shasum ${TEMPFILE}) | |
if test -f "${VERSFILE}"; then | |
if [ "${TARBALL_SHASUM}" == "$(cat ${VERSFILE})" ]; then | |
echo "Everything up to date. Stopping." | |
exit 0 | |
fi | |
fi | |
cd ${INSTALLDIR} | |
rm -rf ${INSTALLDIR}/* | |
echo "Downloading current version" | |
curl ${TARBALL_SOURCE} | unxz | tar -x || die "Failed to unpack tar archive!" | |
mv ${INSTALLDIR}/*/* ${INSTALLDIR}/ || die "Failed to move data to real folder." | |
rm -r ${INSTALLDIR}/zig-${ZIG_OS}-* || die "Failed to remove tar archive content." | |
echo ${TARBALL_SHASUM} > ${VERSFILE} | |
echo "Successfully installed zig $(./zig version)" | |
rm ${TEMPFILE} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment