#!/usr/bin/env bash # Installs or updates every SWAT+ tool on https://install.swat.tamu.edu: # SWAT+ Editor, SWAT+ Toolbox, QSWATPlus. # All or nothing: every installer is downloaded and the requirements are checked # before anything is installed, and the first installer that fails stops the rest. TMP="$(mktemp -d "${TMPDIR:-/tmp}/swatplus-all.XXXXXX")" || exit 1 trap 'rm -rf "$TMP"' EXIT DONE="" say() { printf '\n\033[1;35m### %s\033[0m\n' "$*"; } stop() { printf '\n\033[1;31mxx \033[0m %s\n' "$*" >&2 if [ -n "$DONE" ]; then printf 'Installed or updated before it stopped:\n%s' "$DONE" >&2 else printf 'Nothing was installed.\n' >&2; fi exit 1 } get() { # curl -fsSL --proto '=https' --tlsv1.2 --retry 3 --retry-delay 2 "$1" -o "$TMP/$2" \ || stop "Could not download $1" } # The installers are written for `curl ... | bash`, so stdin is not a terminal there either. run() { # [arguments] local name="$1" f="$2" rc shift 2 say "$name" bash "$TMP/$f" "$@" < /dev/null rc=$? [ "$rc" -eq 0 ] || stop "$name: the installer stopped with status $rc (see its messages above)." DONE="$DONE $name"$'\n' } main() { get 'https://install.swat.tamu.edu/spe.sh' editor.sh get 'https://install.swat.tamu.edu/spt.sh' toolbox.sh get 'https://install.swat.tamu.edu/qsp.sh' qswatplus.sh say 'Checking the QSWATPlus requirements' bash "$TMP/qswatplus.sh" --check < /dev/null || stop 'QSWATPlus cannot be installed here (see above).' run 'SWAT+ Editor' editor.sh run 'SWAT+ Toolbox' toolbox.sh run 'QSWATPlus' qswatplus.sh --all say "Summary" printf 'Installed or up to date:\n%s' "$DONE" } # The whole file is read before anything runs, so a cut-off download does nothing. main