#!/usr/bin/env bash set -euo pipefail fail() { printf 'Error: %s\n' "$*" >&2; exit 1; } install_dir="${HOME:?HOME must be set}/.local/bin" setup=true while [[ $# -gt 0 ]]; do case "$1" in --no-setup) setup=false; shift ;; --bin-dir) [[ $# -ge 2 ]] || fail '--bin-dir needs a path.'; install_dir=$2; shift 2 ;; *) fail "Unknown argument: $1" ;; esac done if "$setup" && ! ( : < /dev/tty ) 2>/dev/null; then fail 'Open a terminal to run guided setup, or use bash -s -- --no-setup to install only.' fi [[ $(uname -s) == Linux ]] || fail 'This installer currently supports Linux. macOS packaging is still being tested.' [[ $(uname -m) == x86_64 ]] || fail 'Prebuilt downloads currently support Linux x86_64 only.' for tool in curl tar sha256sum mktemp chmod mv mkdir; do command -v "$tool" >/dev/null 2>&1 || fail "Required command not found: $tool" done [[ $install_dir == /* ]] || fail '--bin-dir must be an absolute path.' mkdir -p "$install_dir" [[ ! -d "$install_dir/volume" ]] || fail "$install_dir/volume is a directory." temporary=$(mktemp -d "$install_dir/.volume-install.XXXXXXXX") trap 'rm -rf -- "$temporary"' EXIT digest='5a5c455ffd591e5474e22b11ff9c4121c4449721a9b8744977b1cdc93b5bfbe1' printf 'Downloading Portable Volume for Linux x86_64…\n' curl --fail --silent --show-error --location --proto '=https' --proto-redir '=https' \ "https://volumes-dev.twin.so/releases/$digest/volume-linux-x86_64.tar.gz" \ --output "$temporary/volume.tar.gz" printf '%s %s\n' "$digest" "$temporary/volume.tar.gz" | sha256sum --check --status \ || fail 'Download checksum did not match. Existing installation was not changed.' tar -xOzf "$temporary/volume.tar.gz" volume > "$temporary/volume" [[ -s "$temporary/volume" ]] || fail 'Downloaded binary is empty.' chmod 755 "$temporary/volume" mv -fT -- "$temporary/volume" "$install_dir/volume" printf '\nInstalled %s/volume\n' "$install_dir" case ":$PATH:" in *":$install_dir:"*) ;; *) printf 'Add this directory to your shell PATH: %s\n' "$install_dir" ;; esac if ! command -v fusermount3 >/dev/null 2>&1; then printf 'Mounting requires FUSE 3 (fusermount3). Install it using your distribution package manager.\n' fi if [[ ! -c /dev/fuse ]]; then printf 'Mounting also requires access to /dev/fuse; restricted containers may not provide it.\n' fi if "$setup"; then printf '\nStarting guided setup…\n' "$install_dir/volume" --endpoint https://volumes-dev.twin.so setup < /dev/tty else printf '\nRun guided setup:\n %q --endpoint https://volumes-dev.twin.so setup\n' "$install_dir/volume" fi