#!/bin/sh # Installs the opentunnel CLI. # # curl -fsSL https://opentunnel.xyz/install | sh # # OPENTUNNEL_VERSION version to install (default: latest) # OPENTUNNEL_INSTALL install directory (default: ~/.local/bin) set -eu repo="anomalyco/opentunnel" case "$(uname -s)" in Linux) os="linux" ;; Darwin) os="darwin" ;; *) echo "opentunnel: unsupported operating system $(uname -s)" >&2; exit 1 ;; esac case "$(uname -m)" in x86_64 | amd64) arch="x64" ;; arm64 | aarch64) arch="arm64" ;; *) echo "opentunnel: unsupported architecture $(uname -m)" >&2; exit 1 ;; esac if [ -n "${OPENTUNNEL_VERSION:-}" ]; then base="https://github.com/$repo/releases/download/v${OPENTUNNEL_VERSION#v}" else base="https://github.com/$repo/releases/latest/download" fi file="opentunnel-$os-$arch.tar.gz" if command -v sha256sum >/dev/null 2>&1; then sha256() { sha256sum "$1" | cut -d ' ' -f 1; } elif command -v shasum >/dev/null 2>&1; then sha256() { shasum -a 256 "$1" | cut -d ' ' -f 1; } else echo "opentunnel: sha256sum or shasum is required to verify the download" >&2 exit 1 fi dir="${OPENTUNNEL_INSTALL:-$HOME/.local/bin}" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT echo "Downloading opentunnel for $os-$arch..." curl -fsSL -o "$tmp/$file" "$base/$file" curl -fsSL -o "$tmp/SHA256SUMS" "$base/SHA256SUMS" expected="$(awk -v file="$file" '$2 == file { print $1 }' "$tmp/SHA256SUMS")" actual="$(sha256 "$tmp/$file")" if [ -z "$expected" ] || [ "$expected" != "$actual" ]; then echo "opentunnel: checksum verification failed for $file" >&2 exit 1 fi tar -xzf "$tmp/$file" -C "$tmp" opentunnel mkdir -p "$dir" mv "$tmp/opentunnel" "$dir/opentunnel" chmod 755 "$dir/opentunnel" echo "Installed $("$dir/opentunnel" --version) to $dir/opentunnel" case ":$PATH:" in *":$dir:"*) ;; *) echo "Add $dir to your PATH to run opentunnel, for example:" echo " export PATH=\"$dir:\$PATH\"" ;; esac echo "Get started: opentunnel route add "