#!/bin/sh # Installs the Flythrough gateway for this user and starts it as a service # (systemd on Linux, launchd on macOS). Nothing is done as root. Read it # before you run it. Windows has install.ps1. set -eu BASE="${FLYTHROUGH_BASE:-https://flythrough.work/gateway/0.0.0.0}" BIN_DIR="${HOME}/.local/bin" APP_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/flythrough-gateway" UNIT_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user" LABEL="work.flythrough.gateway" PLIST_DIR="${HOME}/Library/LaunchAgents" say() { printf '%s\n' "$*"; } die() { printf 'install: %s\n' "$*" >&2; exit 1; } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$@"; else shasum -a 256 "$@"; fi; } case "$(uname -s)" in Linux) os=linux ;; Darwin) os=macos ;; *) die "this installer is for Linux and macOS; Windows has install.ps1" ;; esac case "$(uname -m)" in aarch64|arm64) arch=aarch64 ;; x86_64|amd64) arch=x86_64 ;; *) die "there is no build for $(uname -m)" ;; esac ARCHIVE="flythrough-gateway-$arch-$os.tar.xz" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT curl -fsSL "$BASE/SHA256SUMS" -o "$tmp/SHA256SUMS" grep " $ARCHIVE\$" "$tmp/SHA256SUMS" >/dev/null || die "there is no build for $arch on $os yet" say "Downloading $ARCHIVE" curl -fsSL "$BASE/$ARCHIVE" -o "$tmp/$ARCHIVE" ( cd "$tmp" && grep " $ARCHIVE\$" SHA256SUMS | sha256 -c - >/dev/null ) \ || die "checksum mismatch for $ARCHIVE" tar -xJf "$tmp/$ARCHIVE" -C "$tmp" rm -rf "$APP_DIR" mkdir -p "$(dirname "$APP_DIR")" "$BIN_DIR" mv "$tmp/flythrough-gateway" "$APP_DIR" ln -sf "$APP_DIR/flythrough-gateway" "$BIN_DIR/flythrough-gateway" say "Installed $APP_DIR, linked $BIN_DIR/flythrough-gateway" if [ "$os" = macos ]; then mkdir -p "$PLIST_DIR" cat > "$PLIST_DIR/$LABEL.plist" < EnvironmentVariables PATH $BIN_DIR:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin KeepAlive SuccessfulExit Label work.flythrough.gateway ProgramArguments $BIN_DIR/flythrough-gateway serve RunAtLoad PLIST domain="gui/$(id -u)" launchctl bootout "$domain/$LABEL" >/dev/null 2>&1 || true launchctl bootstrap "$domain" "$PLIST_DIR/$LABEL.plist" launchctl kickstart -k "$domain/$LABEL" say "Gateway running. Check it with: $BIN_DIR/flythrough-gateway status" exit 0 fi if ! command -v systemctl >/dev/null 2>&1 || ! systemctl --user show-environment >/dev/null 2>&1; then say "No systemd user session here. Start the gateway with:" say " $BIN_DIR/flythrough-gateway serve" exit 0 fi mkdir -p "$UNIT_DIR" cat > "$UNIT_DIR/flythrough-gateway.service" <