#!/bin/bash
# macOS Bash 3.2 and Linux. Downloaded engine and bundle are hash-verified.
set -euo pipefail
umask 077
command -v python3 >/dev/null 2>&1 || { echo 'Install Python 3 first: https://voltvaultapp.com/upgrade.html#requirements' >&2; exit 1; }
scratch=$(mktemp -d "${TMPDIR:-/tmp}/voltvault-upgrade.XXXXXX")
trap 'rm -rf -- "$scratch"' EXIT
trap 'exit 130' INT TERM
curl --fail --show-error --location --proto '=https' --tlsv1.2 --connect-timeout 20 --max-time 120 'https://voltvaultapp.com/downloads/upgrade-2.0.7.py' -o "$scratch/upgrade.py"
python3 -c 'import hashlib,sys; sys.exit(0 if hashlib.sha256(open(sys.argv[1],"rb").read()).hexdigest()==sys.argv[2] else "Updater verification failed; nothing changed.")' "$scratch/upgrade.py" 'a761f54affe22e64dd5dd406a66a37e402fc4a2d5f7faae9f565973042410686'
python3 "$scratch/upgrade.py" "$@"
