#!/bin/sh # toa installer for Linux. # # curl -fsSL https://toa-switch.pages.dev/install.sh | sh # # Downloads toa for this CPU, verifies it against the published SHA-256 # checksums and runs 'toa install'. Nothing is installed if the check fails. set -eu base='https://toa-switch.pages.dev' case "$(uname -s)" in Linux) os=linux ;; *) echo "toa supports Windows and Linux only." >&2; exit 1 ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; aarch64 | arm64) arch=arm64 ;; *) echo "Unsupported CPU: $(uname -m)" >&2; exit 1 ;; esac file="$os-$arch/toa" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" else wget -qO "$2" "$1" fi } echo "Downloading toa ($file)..." fetch "$base/download/$file" "$tmp/toa" fetch "$base/download/SHA256SUMS.txt" "$tmp/SHA256SUMS.txt" expected=$(awk -v f="$file" '{ sub(/\r$/, "") } $2 == f { print $1 }' "$tmp/SHA256SUMS.txt") if [ -z "$expected" ]; then echo "No checksum is published for $file." >&2 exit 1 fi if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/toa" | cut -d ' ' -f 1) else actual=$(shasum -a 256 "$tmp/toa" | cut -d ' ' -f 1) fi if [ "$actual" != "$expected" ]; then echo "Checksum mismatch for $file. The download was not installed." >&2 exit 1 fi echo "Checksum verified." chmod +x "$tmp/toa" # When piped into sh, stdin is this script; read answers from the terminal # instead. /dev/tty can exist yet fail to open without a controlling terminal # (CI, cron), so try opening it rather than testing that it exists. if (: /dev/null; then "$tmp/toa" install