#!/bin/sh # install.sh -- download simu86 from the releases of github.com/C2k-studio/simu86, check its SHA-256 and put it in a folder. # curl -fsSL https://raw.githubusercontent.com/C2k-studio/simu86/main/install.sh | sh # Options (after `sh -s --`): --dir FOLDER (default: $PREFIX/bin on Termux and exshell, else ~/.local/bin), --version X.Y.Z (default: the latest) # SIMU86_BASE=URL downloads from another place (a mirror, or file:///folder). set -eu REPO="C2k-studio/simu86" DIR="" VERSION="" while [ $# -gt 0 ]; do case "$1" in --dir) [ $# -ge 2 ] || { echo "install: --dir needs a folder"; exit 1; }; DIR="$2"; shift 2 ;; --version) [ $# -ge 2 ] || { echo "install: --version needs a number"; exit 1; }; VERSION="$2"; shift 2 ;; -h|--help) sed -n '2,5p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "install: unknown option '$1' (try --help)"; exit 1 ;; esac done case "$(uname -m)" in aarch64|arm64) ;; *) echo "install: simu86 is built for Linux ARM64 (this machine is $(uname -m)); build it from the source"; exit 1 ;; esac fetch() { # fetch URL FILE case "$1" in file://*) cp "${1#file://}" "$2"; return ;; esac if command -v curl >/dev/null 2>&1; then curl -fsSL -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" elif command -v jurl >/dev/null 2>&1; then jurl -fsSL -o "$2" "$1" else echo "install: curl, wget or jurl is needed"; exit 1; fi } if [ -n "${SIMU86_BASE:-}" ]; then BASE="$SIMU86_BASE" elif [ -n "$VERSION" ]; then BASE="https://github.com/$REPO/releases/download/v$VERSION" else BASE="https://github.com/$REPO/releases/latest/download"; fi if [ -z "$DIR" ]; then if [ -n "${PREFIX:-}" ]; then DIR="$PREFIX/bin"; else DIR="$HOME/.local/bin"; fi; fi TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT echo "downloading from $BASE ..." fetch "$BASE/SHA256SUMS" "$TMP/SHA256SUMS" fetch "$BASE/simu86" "$TMP/simu86" WANT="$(grep ' simu86$' "$TMP/SHA256SUMS" | cut -d' ' -f1)" HAVE="$(sha256sum "$TMP/simu86" | cut -d' ' -f1)" [ -n "$WANT" ] && [ "$WANT" = "$HAVE" ] || { echo "install: the checksum of simu86 does not match, nothing installed"; exit 1; } mkdir -p "$DIR" cp "$TMP/simu86" "$DIR/.simu86.new" chmod +x "$DIR/.simu86.new" mv -f "$DIR/.simu86.new" "$DIR/simu86" echo "installed: $DIR/simu86 ($("$DIR/simu86" version))" case ":$PATH:" in *":$DIR:"*) ;; *) echo "add the folder to your PATH: export PATH=\"$DIR:\$PATH\"" ;; esac