#!/bin/sh set -eu REPO="bakare-dev/gotunnel-io" say() { printf '%s\n' "$*" } fail() { printf 'gotunnel install: %s\n' "$*" >&2 exit 1 } download() { if command -v curl >/dev/null 2>&1; then curl -fsSL --proto '=https' --tlsv1.2 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q --https-only -O "$2" "$1" else fail "curl or wget is required" fi } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d ' ' -f 1 else fail "sha256sum or shasum is required to verify the download" fi } main() { case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "unsupported OS $(uname -s). On Windows, run this in PowerShell: irm https://gotunnel.site/install.ps1 | iex" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "unsupported CPU $(uname -m)" ;; esac if [ "$os" = darwin ] && [ "$arch" = amd64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then arch=arm64 fi version="${GOTUNNEL_VERSION:-latest}" case "$version" in *[!A-Za-z0-9._-]*) fail "invalid GOTUNNEL_VERSION: $version" ;; esac if [ "$version" = latest ]; then base="https://github.com/$REPO/releases/latest/download" else base="https://github.com/$REPO/releases/download/$version" fi asset="gotunnel-$os-$arch" dir="${GOTUNNEL_INSTALL_DIR:-/usr/local/bin}" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT trap 'exit 130' INT TERM say "Downloading $asset ($version)..." download "$base/$asset" "$tmp/gotunnel" || fail "could not download $asset ($version)" download "$base/checksums.txt" "$tmp/checksums.txt" || fail "could not download checksums.txt, so the download can't be verified" want="$(awk -v f="$asset" '$2 == f { print $1 }' "$tmp/checksums.txt")" [ -n "$want" ] || fail "checksums.txt has no entry for $asset" [ "$want" = "$(sha256 "$tmp/gotunnel")" ] || fail "checksum mismatch for $asset; nothing was installed" chmod 755 "$tmp/gotunnel" sudo="" if [ -d "$dir" ] && [ -w "$dir" ]; then : elif [ ! -e "$dir" ] && mkdir -p "$dir" 2>/dev/null; then : else if [ "$(id -u)" -ne 0 ]; then command -v sudo >/dev/null 2>&1 || fail "can't write to $dir. Re-run as root, or set GOTUNNEL_INSTALL_DIR to a folder you own" say "Installing to $dir needs administrator rights, so sudo may ask for your password." sudo="sudo" fi $sudo mkdir -p "$dir" fi $sudo mv -f "$tmp/gotunnel" "$dir/gotunnel" if [ -n "$sudo" ]; then $sudo chown 0:0 "$dir/gotunnel" fi say "Installed $("$dir/gotunnel" version) to $dir/gotunnel" case ":$PATH:" in *":$dir:"*) found="$(command -v gotunnel || true)" if [ -n "$found" ] && [ "$found" != "$dir/gotunnel" ]; then say "Note: another gotunnel at $found comes first on your PATH." fi ;; *) say "Note: $dir is not on your PATH. Add it with: export PATH=\"$dir:\$PATH\"" ;; esac say "" say "Get started: gotunnel http 3000" } main "$@"