#!/bin/sh # FadeHost Bridge installer for Linux and macOS. # # Downloads the bridge program for this machine from the FadeHost release # feed, checks it against the sha256 the feed publishes and installs it for # the current user (no root needed, and the program can then keep itself # up to date). # # curl -fsSL https://fadehost.com/bridge/install.sh | sh # # BRIDGE_INSTALL_DIR chooses another directory than ~/.local/bin. set -eu API="${BRIDGE_API:-https://services.fadehost.com}" DIR="${BRIDGE_INSTALL_DIR:-$HOME/.local/bin}" fail() { echo "bridge: $1" >&2 exit 1 } os=$(uname -s | tr '[:upper:]' '[:lower:]') case "$os" in linux | darwin) ;; *) fail "this installer covers Linux and macOS. On Windows, download bridge.exe from https://fadehost.com/bridge/" ;; esac arch=$(uname -m) case "$arch" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "there is no build for $arch yet" ;; esac name="bridge-$os-$arch" fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" elif command -v wget >/dev/null 2>&1; then wget -qO- "$1" else fail "curl or wget is needed" fi } latest=$(fetch "$API/api/bridge/agent/latest") || fail "could not reach the release feed" version=$(printf '%s' "$latest" | sed -n 's/.*"version":"\([0-9.]*\)".*/\1/p') sha=$(printf '%s' "$latest" | tr '{' '\n' | grep "\"name\":\"$name\"" | sed -n 's/.*"sha256":"\([a-f0-9]*\)".*/\1/p') [ -n "$version" ] || fail "could not read the version from the release feed" [ -n "$sha" ] || fail "version $version has no build for $os/$arch" tmp=$(mktemp) trap 'rm -f "$tmp"' EXIT echo "Downloading bridge $version for $os/$arch..." fetch "$API/api/bridge/agent/download/$name?version=$version" >"$tmp" || fail "the download failed" if command -v sha256sum >/dev/null 2>&1; then got=$(sha256sum "$tmp" | cut -d' ' -f1) else got=$(shasum -a 256 "$tmp" | cut -d' ' -f1) fi [ "$got" = "$sha" ] || fail "the download does not match its sha256, nothing was installed" mkdir -p "$DIR" chmod 755 "$tmp" mv "$tmp" "$DIR/bridge" trap - EXIT echo "bridge $version is installed at $DIR/bridge" case ":$PATH:" in *":$DIR:"*) echo "Start it with: bridge" ;; *) echo "Start it with: $DIR/bridge" echo "To call it as bridge, add this line to your shell profile:" echo " export PATH=\"$DIR:\$PATH\"" ;; esac