#!/bin/sh # Installs scene-finder: downloads the binary for this machine from the latest # GitHub release into ~/.local/bin. # # curl -fsSL https://raw.githubusercontent.com/robinroy03/scene-finder/main/install.sh | sh # # Settings (environment variables): # SCENE_FINDER_VERSION release to install, e.g. v0.1.0 (default: latest) # SCENE_FINDER_INSTALL_DIR where to put the binary (default: ~/.local/bin) set -eu REPO="robinroy03/scene-finder" fail() { echo "scene-finder install: $*" >&2 exit 1 } # Everything runs from main, called on the last line, so a download that is # cut off half way cannot run half a script. main() { command -v curl >/dev/null 2>&1 || fail "curl is needed" case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "this script supports macOS and Linux; for Windows download the .exe from https://github.com/$REPO/releases" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "unsupported processor: $(uname -m)" ;; esac version="${SCENE_FINDER_VERSION:-latest}" if [ "$version" = latest ]; then base="https://github.com/$REPO/releases/latest/download" else base="https://github.com/$REPO/releases/download/$version" fi base="${SCENE_FINDER_BASE_URL:-$base}" # for testing against a local folder dir="${SCENE_FINDER_INSTALL_DIR:-$HOME/.local/bin}" asset="scene-finder-$os-$arch" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT echo "Downloading $asset ($version)..." curl -fsSL "$base/$asset" -o "$tmp/$asset" || fail "could not download $base/$asset" # Check the download against the release's checksum list. if curl -fsSL "$base/checksums.txt" -o "$tmp/checksums.txt"; then want="$(awk -v f="$asset" '$2 == f { print $1 }' "$tmp/checksums.txt")" if command -v sha256sum >/dev/null 2>&1; then got="$(sha256sum "$tmp/$asset" | awk '{ print $1 }')" elif command -v shasum >/dev/null 2>&1; then got="$(shasum -a 256 "$tmp/$asset" | awk '{ print $1 }')" else got="" fi if [ -n "$want" ] && [ -n "$got" ] && [ "$want" != "$got" ]; then fail "checksum mismatch for $asset, not installing" fi fi mkdir -p "$dir" chmod +x "$tmp/$asset" mv "$tmp/$asset" "$dir/scene-finder" echo "Installed $dir/scene-finder" # The man page is a nice-to-have: skip it quietly if it cannot be fetched. mandir="${XDG_DATA_HOME:-$HOME/.local/share}/man/man1" if curl -fsSL "$base/scene-finder.1" -o "$tmp/scene-finder.1" 2>/dev/null; then mkdir -p "$mandir" && mv "$tmp/scene-finder.1" "$mandir/scene-finder.1" fi case ":$PATH:" in *":$dir:"*) echo "Run: scene-finder help" ;; *) echo "$dir is not on your PATH. Add this line to your shell profile, then open a new terminal:" echo " export PATH=\"$dir:\$PATH\"" ;; esac } main "$@"