#!/usr/bin/env bash # ╔══════════════════════════════════════════════════════════════════╗ # ║ Gateway — One-Shot Bootstrap ║ # ║ ║ # ║ curl -fsSL https://thegateway.pro/install.sh | bash ║ # ║ ║ # ║ Detects arch, fetches the binary + the full installer, then ║ # ║ hands off. Defaults to the `vps` profile because that's what ║ # ║ curl-pipe-bash is overwhelmingly used for (a fresh Linux VPS ║ # ║ with no peripherals). RPi operators should run the full ║ # ║ installer directly so they can pick the rpi profile. ║ # ╚══════════════════════════════════════════════════════════════════╝ # # What this script does: # 1. sudo-elevates if not root # 2. Picks the right arch (amd64 / arm64) # 3. Downloads the release's SHA256SUMS # 4. Downloads the full installer (install-gateway.sh) into /tmp and # checks it when the release lists it # 5. Downloads the gatewayd binary (.gz when the release has it) and # checks it — a mismatch stops here, before anything runs # 6. Runs install-gateway.sh --profile vps --binary /tmp/gatewayd ... # # Flags (passed through pipe by setting env vars before piping, or as # args when run directly): # GATEWAY_PROFILE=vps|rpi|node|full|custom default: vps # GATEWAY_VERSION=latest|vX.Y.Z default: latest # GATEWAY_BASE_URL=https://thegateway.pro where install-gateway.sh + binary live # GATEWAY_FROM_SOURCE=1 clone repo and `go build` instead of binary download # GATEWAY_NONINTERACTIVE=1 skip every prompt # GATEWAY_UPDATE=1 update mode: replace the gatewayd binary # ONLY, keep config / db / certs / systemd unit # in place. Faster than re-running the full # installer and safe to re-run anytime. # GATEWAY_REFRESH=1 refresh mode: rewrite the gatewayd unit and # its helper scripts from the release's # installer; no apt, no config, no restart # GATEWAY_ALLOW_UNSIGNED=1 take a release whose SHA256SUMS no release # key signed (older releases), with a warning # GATEWAY_ALLOW_DOWNGRADE=1 update mode: install a version older than # the one running # Passed on to install-gateway.sh (its --help says more): # GATEWAY_AUTH=on|off sign-in required, default on # GATEWAY_ADMIN_PASSWORD_FILE= the admin's password, read from a file # GATEWAY_SERVER_MGMT=on|off manage servers from this gateway # GATEWAY_UPDATE_POLICY=notify|manual|auto updates of gatewayd, default notify # GATEWAY_UPDATE_WINDOW=HH:MM the window auto installs in # GATEWAY_HEADSCALE=on|off the mesh's control plane on this node, default off # GATEWAY_RELAY_MODE=none|tls|public its relays, default none # GATEWAY_TLS_SANS=,… more names for the server certificate # (the public IPv4 is in it anyway) # # Example (build from source on a VPS): # curl -fsSL https://thegateway.pro/install.sh | \ # GATEWAY_FROM_SOURCE=1 GATEWAY_PROFILE=vps GATEWAY_NONINTERACTIVE=1 bash # # Example (update an existing install to the latest binary): # curl -fsSL https://thegateway.pro/install.sh | GATEWAY_UPDATE=1 bash # # Example (update + pin to a specific release): # curl -fsSL https://thegateway.pro/install.sh | \ # GATEWAY_UPDATE=1 GATEWAY_VERSION=v2.6.0-419-gcb09c73 bash set -euo pipefail # ── Colours so curl-pipe-bash shows progress visibly ── GREEN='\033[0;32m'; YELLOW='\033[0;33m'; RED='\033[0;31m'; CYAN='\033[0;36m'; BOLD='\033[1m'; NC='\033[0m' log() { echo -e "${GREEN}[+]${NC} $*"; } warn() { echo -e "${YELLOW}[!]${NC} $*"; } err() { echo -e "${RED}[✗]${NC} $*" >&2; exit 1; } info() { echo -e "${CYAN}[i]${NC} $*"; } # ── Sudo escalation when needed ── # Curl-pipe-bash invocations run as the operator's user; the deeper # installer needs root for apt, systemd, /etc edits. Re-exec under # sudo so the operator doesn't have to remember `sudo` in the curl # line. if [ "$(id -u)" -ne 0 ]; then # `curl … | bash` has no script FILE: $0 is "bash", so `sudo … bash "$0"` # would become `sudo … bash bash` and fail with `bash: No such file` # (GR-024). We can't re-exec a consumed stdin pipe, so give a clear # instruction instead of the cryptic failure. The file case (./install.sh) # still auto-re-execs under sudo below. if [ ! -f "$0" ]; then err "This installer needs root. Re-run with sudo, e.g.: curl -fsSL | sudo bash" exit 1 fi if command -v sudo >/dev/null 2>&1; then warn "Re-running under sudo..." # `bash -c` keeps env vars (GATEWAY_*) propagated; -E on sudo # preserves them through the privilege escalation. exec sudo -E env "BASH_ENV=${BASH_ENV:-}" \ GATEWAY_PROFILE="${GATEWAY_PROFILE:-}" \ GATEWAY_VERSION="${GATEWAY_VERSION:-}" \ GATEWAY_BASE_URL="${GATEWAY_BASE_URL:-}" \ GATEWAY_FROM_SOURCE="${GATEWAY_FROM_SOURCE:-}" \ GATEWAY_NONINTERACTIVE="${GATEWAY_NONINTERACTIVE:-}" \ GATEWAY_UPDATE="${GATEWAY_UPDATE:-}" \ GATEWAY_REFRESH="${GATEWAY_REFRESH:-}" \ GATEWAY_ALLOW_UNSIGNED="${GATEWAY_ALLOW_UNSIGNED:-}" \ GATEWAY_ALLOW_DOWNGRADE="${GATEWAY_ALLOW_DOWNGRADE:-}" \ GATEWAY_REPO_URL="${GATEWAY_REPO_URL:-}" \ GATEWAY_AUTH="${GATEWAY_AUTH:-}" \ GATEWAY_ADMIN_PASSWORD_FILE="${GATEWAY_ADMIN_PASSWORD_FILE:-}" \ GATEWAY_SERVER_MGMT="${GATEWAY_SERVER_MGMT:-}" \ GATEWAY_UPDATE_POLICY="${GATEWAY_UPDATE_POLICY:-}" \ GATEWAY_UPDATE_WINDOW="${GATEWAY_UPDATE_WINDOW:-}" \ GATEWAY_HEADSCALE="${GATEWAY_HEADSCALE:-}" \ GATEWAY_RELAY_MODE="${GATEWAY_RELAY_MODE:-}" \ GATEWAY_TLS_SANS="${GATEWAY_TLS_SANS:-}" \ bash "$0" "$@" else err "sudo not available and not running as root" fi fi # ── Defaults ── PROFILE="${GATEWAY_PROFILE:-vps}" VERSION="${GATEWAY_VERSION:-latest}" BASE_URL="${GATEWAY_BASE_URL:-https://thegateway.pro}" FROM_SOURCE="${GATEWAY_FROM_SOURCE:-0}" NONINTERACTIVE="${GATEWAY_NONINTERACTIVE:-0}" UPDATE_MODE="${GATEWAY_UPDATE:-0}" REFRESH_MODE="${GATEWAY_REFRESH:-0}" if [ "$REFRESH_MODE" = "1" ] && [ "$FROM_SOURCE" = "1" ]; then err "GATEWAY_REFRESH=1 takes the units and scripts of a release, not of a source build" fi # The release agent's keys (docs/plans/server-management.md 7.4), one per # line: " " — the primary, then the # reserve (it signs only while a lost or leaked primary is replaced). Built # in since v2.18.1, as in internal/releases/embedded.go and README.md. A # release whose SHA256SUMS no key here signed is refused unless # GATEWAY_ALLOW_UNSIGNED=1 (the releases before the keys). RELEASE_KEYS=( # release keys: begin "03ea7f6bcef4ab19 /2vPiKRblHb7DU5RieDfNjlZsqf/LN+JYqC/ilccSZA=" "e740c848903fec85 gqUmZrBRpALaJOEXfUq3YTQ2KJ9j9IB01SbsKjtMySs=" # release keys: end ) # Whitelist of supported profiles so a typo doesn't silently fall back # to "vps" and surprise the operator. Empty profile means interactive; # we map that to vps for non-interactive mode below. case "$PROFILE" in ""|vps|rpi|node|full|custom) ;; *) err "GATEWAY_PROFILE must be one of: vps rpi node full custom (got: $PROFILE)" ;; esac # ── Architecture detection ── HOST_ARCH=$(uname -m) case "$HOST_ARCH" in x86_64|amd64) ARCH=amd64 ;; aarch64|arm64) ARCH=arm64 ;; *) err "Unsupported architecture: $HOST_ARCH (supported: x86_64, aarch64)" ;; esac # ── Sanity: we're on a Linux that the installer supports ── # Source os-release inside a subshell so its VERSION= # export doesn't stomp on OUR VERSION (the gateway release ref). The # subshell prints back only the fields we care about for the warning # heuristic. Without the subshell, the parent VERSION ended up as # "24.04.3 LTS (Noble Numbat)" and the binary fetch URL became a # malformed-input curl rejection. if [ ! -f /etc/os-release ]; then err "Unsupported OS — /etc/os-release missing. The installer targets Debian / Ubuntu." fi read OS_ID OS_ID_LIKE OS_PRETTY < <(. /etc/os-release; printf '%s %s %q\n' "${ID:-}" "${ID_LIKE:-}" "${PRETTY_NAME:-unknown}") case "${OS_ID}${OS_ID_LIKE}" in *debian*|*ubuntu*) ;; *) warn "Detected OS: ${OS_PRETTY}. Installer is tested on Debian 12+ / Ubuntu 22.04+; YMMV." ;; esac log "Gateway bootstrap" info " profile: $PROFILE" info " arch: $ARCH" info " from_source: $([ "$FROM_SOURCE" = "1" ] && echo "yes — will clone repo + go build" || echo "no — download prebuilt binary")" info " version: $VERSION" info " base_url: $BASE_URL" # ── Workspace ── WORK=$(mktemp -d -t gateway-bootstrap.XXXXXX) trap 'rm -rf "$WORK"' EXIT cd "$WORK" # ── Required local tooling for the bootstrap itself ── need_pkg="" command -v curl >/dev/null 2>&1 || need_pkg="$need_pkg curl" command -v tar >/dev/null 2>&1 || need_pkg="$need_pkg tar" command -v gzip >/dev/null 2>&1 || need_pkg="$need_pkg gzip" if ! command -v sha256sum >/dev/null 2>&1 && ! command -v shasum >/dev/null 2>&1; then need_pkg="$need_pkg coreutils" fi if [ "${#RELEASE_KEYS[@]}" -gt 0 ] && ! command -v openssl >/dev/null 2>&1; then need_pkg="$need_pkg openssl" fi if [ -n "$need_pkg" ]; then log "Installing bootstrap tools:$need_pkg" apt-get update -qq apt-get install -y -qq $need_pkg fi # ── Release checksums ── # The binary and the installer are checked against the release's SHA256SUMS # before anything runs. Only the copy of this script on the site did that; # a truncated or swapped download was run as root. (Signatures: plan 7.4.) RELEASE_BASE="$BASE_URL/releases/$VERSION" # listed_in_manifest NAME: SHA256SUMS has a line for NAME ("*NAME" = binary mode) listed_in_manifest() { awk -v file="$1" '{ n = $2; sub(/^\*/, "", n) } n == file { found = 1 } END { exit !found }' "$WORK/SHA256SUMS" } # verify_release_file PATH NAME MANIFEST: refuses unless MANIFEST has exactly # one well-formed checksum for NAME and PATH matches it verify_release_file() { local path="$1" name="$2" manifest="$3" count expected actual count=$(awk -v file="$name" '{ n = $2; sub(/^\*/, "", n) } n == file { c++ } END { print c + 0 }' "$manifest") [ "$count" = 1 ] || err "$(basename "$manifest") must list exactly one checksum for $name (found $count)" expected=$(awk -v file="$name" '{ n = $2; sub(/^\*/, "", n) } n == file { print tolower($1) }' "$manifest") [[ "$expected" =~ ^[0-9a-f]{64}$ ]] || err "Invalid SHA256 for $name in $(basename "$manifest")" if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$path" | awk '{print $1}') else actual=$(shasum -a 256 "$path" | awk '{print $1}') fi [ "$actual" = "$expected" ] || err "Checksum mismatch for $name — refusing to run it (expected $expected, got $actual)" info " $name sha256 OK: $actual" } # fetch_release_file NAME OUT: download a release file and check it fetch_release_file() { curl -fSL "$RELEASE_BASE/$1" -o "$2" \ || err "Failed to download $RELEASE_BASE/$1 — set GATEWAY_FROM_SOURCE=1 to build from source instead" verify_release_file "$2" "$1" "$WORK/SHA256SUMS" } # verify_signature FILE SIG: at least one line of SIG ("ed25519 # ") by a key above must hold over the exact bytes of FILE; a line by # one of them that does not hold refuses everything. Lines by other keys are # passed over: both keys sign while one is replaced. verify_signature() { local file="$1" sigfile="$2" ok=0 alg kid b64 raw k while read -r alg kid b64; do [ -n "${alg:-}" ] || continue [ "$alg" = ed25519 ] && [[ "$kid" =~ ^[0-9a-f]{16}$ ]] || err "$(basename "$sigfile") holds a line that is not a signature" raw="" for k in "${RELEASE_KEYS[@]}"; do [ "${k%% *}" = "$kid" ] && raw="${k#* }" done [ -n "$raw" ] || continue # the raw key as SubjectPublicKeyInfo: the Ed25519 prefix, then 32 bytes { echo "-----BEGIN PUBLIC KEY-----" { printf '\x30\x2a\x30\x05\x06\x03\x2b\x65\x70\x03\x21\x00'; printf '%s' "$raw" | openssl base64 -d -A; } | openssl base64 -A echo; echo "-----END PUBLIC KEY-----"; } > "$WORK/key-$kid.pem" printf '%s' "$b64" | openssl base64 -d -A > "$WORK/sig-$kid.bin" if openssl pkeyutl -verify -pubin -inkey "$WORK/key-$kid.pem" -rawin -in "$file" -sigfile "$WORK/sig-$kid.bin" >/dev/null 2>&1; then ok=1 else err "The signature of $(basename "$file") by key $kid does not hold — refusing: the file was changed" fi done < "$sigfile" [ "$ok" = 1 ] } if [ "$FROM_SOURCE" != "1" ]; then log "Fetching release checksums from $RELEASE_BASE/SHA256SUMS" curl -fsSL "$RELEASE_BASE/SHA256SUMS" -o "$WORK/SHA256SUMS" \ || err "Failed to download $RELEASE_BASE/SHA256SUMS — refusing to run unverified files" if [ "${#RELEASE_KEYS[@]}" -gt 0 ]; then if curl -fsSL "$RELEASE_BASE/SHA256SUMS.sig" -o "$WORK/SHA256SUMS.sig" 2>/dev/null \ && verify_signature "$WORK/SHA256SUMS" "$WORK/SHA256SUMS.sig"; then log "SHA256SUMS signed by a release key: OK" elif [ "${GATEWAY_ALLOW_UNSIGNED:-0}" = "1" ]; then warn "SHA256SUMS is not signed by a release key this script knows — continuing because GATEWAY_ALLOW_UNSIGNED=1" else err "SHA256SUMS is not signed by a release key this script knows — refusing (an older, unsigned release: GATEWAY_ALLOW_UNSIGNED=1)" fi else warn "This install.sh carries no release keys yet: SHA256SUMS is checked, its signature is not" fi # latest is resolved once and printed: the files that follow come from # that version even if latest moves meanwhile if [ "$VERSION" = "latest" ] && listed_in_manifest BUILDINFO; then fetch_release_file BUILDINFO "$WORK/BUILDINFO" resolved=$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\(v[0-9][0-9.]*[-0-9a-z]*\)".*/\1/p' "$WORK/BUILDINFO" | head -1) if [ -n "$resolved" ]; then VERSION="$resolved" info " latest is: $VERSION" fi fi fi # ── Fetch the deeper installer ── INSTALLER="$WORK/install-gateway.sh" if [ "$REFRESH_MODE" = "1" ] && ! listed_in_manifest install-gateway.sh; then err "GATEWAY_REFRESH=1 needs a release that lists install-gateway.sh in SHA256SUMS" fi if [ "$FROM_SOURCE" != "1" ] && listed_in_manifest install-gateway.sh; then log "Fetching installer from $RELEASE_BASE/install-gateway.sh" fetch_release_file install-gateway.sh "$INSTALLER" else if [ "$FROM_SOURCE" != "1" ]; then warn "This release does not list install-gateway.sh in SHA256SUMS: the installer from $BASE_URL is not verified" fi log "Fetching installer from $BASE_URL/install-gateway.sh" if ! curl -fsSL "$BASE_URL/install-gateway.sh" -o "$INSTALLER"; then err "Failed to download install-gateway.sh from $BASE_URL/install-gateway.sh — check connectivity and GATEWAY_BASE_URL" fi fi chmod +x "$INSTALLER" # ── Refresh mode: the unit and its helper scripts only (7.5) ── if [ "$REFRESH_MODE" = "1" ]; then log "Refresh mode: rewriting the gatewayd unit and its helper scripts" exec bash "$INSTALLER" --refresh fi # ── Acquire the gatewayd binary ── BINARY_PATH="" if [ "$FROM_SOURCE" = "1" ]; then # Source-build path. Go is installed by install-gateway.sh's # install_go() — we just shell that out here directly so the # operator's first feedback isn't "what is Go and why am I # waiting 6 minutes for it to install". log "Source-build mode: installing Go + cloning repo" if ! command -v go >/dev/null 2>&1; then GO_VER=1.24.2 curl -fsSL "https://go.dev/dl/go${GO_VER}.linux-${ARCH}.tar.gz" -o /tmp/go.tgz rm -rf /usr/local/go tar -C /usr/local -xzf /tmp/go.tgz rm /tmp/go.tgz export PATH=$PATH:/usr/local/go/bin fi if ! command -v git >/dev/null 2>&1; then apt-get install -y -qq git fi log "Cloning gateway source" git clone --depth 1 "${GATEWAY_REPO_URL:-https://github.com/thegateway-pro/gateway.git}" "$WORK/src" \ || err "git clone failed — set GATEWAY_REPO_URL to a reachable clone URL if the default is wrong" cd "$WORK/src" log "Building gatewayd (this takes ~2 min on a modest VPS)" GIT_COMMIT=$(git rev-parse --short HEAD) GIT_VERSION=$(git describe --tags --always 2>/dev/null || echo dev) BUILD_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ) LDFLAGS="-X main.version=$GIT_VERSION -X main.commit=$GIT_COMMIT -X main.buildDate=$BUILD_DATE" GOOS=linux GOARCH="$ARCH" CGO_ENABLED=0 \ go build -ldflags "$LDFLAGS" -o "$WORK/gatewayd" ./cmd/gatewayd BINARY_PATH="$WORK/gatewayd" cd "$WORK" else # Prebuilt-binary path. The release lives at $BASE_URL/releases/$VERSION/ # so the operator can self-host releases by mirroring that one URL # pattern. The compressed artefact is the one the release was built as; # the uncompressed copy is for releases that only have that. ARTIFACT="gatewayd-linux-$ARCH" if listed_in_manifest "$ARTIFACT.gz"; then log "Downloading $RELEASE_BASE/$ARTIFACT.gz" fetch_release_file "$ARTIFACT.gz" "$WORK/gatewayd.gz" gzip -dc "$WORK/gatewayd.gz" > "$WORK/gatewayd" || err "Release archive could not be decompressed" curl -fsSL "$RELEASE_BASE/UPSTREAM_SHA256SUMS" -o "$WORK/UPSTREAM_SHA256SUMS" \ || err "Failed to download $RELEASE_BASE/UPSTREAM_SHA256SUMS" if listed_in_manifest UPSTREAM_SHA256SUMS; then verify_release_file "$WORK/UPSTREAM_SHA256SUMS" UPSTREAM_SHA256SUMS "$WORK/SHA256SUMS" fi verify_release_file "$WORK/gatewayd" "$ARTIFACT" "$WORK/UPSTREAM_SHA256SUMS" else log "Downloading $RELEASE_BASE/$ARTIFACT" fetch_release_file "$ARTIFACT" "$WORK/gatewayd" fi chmod +x "$WORK/gatewayd" BINARY_PATH="$WORK/gatewayd" fi # ── Update mode: swap the binary, leave everything else alone ── # # The full installer is overkill (and slightly risky — apt updates, # systemd-unit regeneration, TLS-cert paths) for a routine binary # bump. Update mode skips all of that and just stops the daemon, # replaces /usr/local/bin/gatewayd, and starts it again. Bails # early if there's nothing to update. if [ "$UPDATE_MODE" = "1" ]; then if [ ! -x /usr/local/bin/gatewayd ]; then err "GATEWAY_UPDATE=1 set, but /usr/local/bin/gatewayd doesn't exist — run a fresh install first" fi log "Update mode: swapping gatewayd binary in place" old_ver=$(/usr/local/bin/gatewayd --version 2>&1 | head -1 || echo "unknown") new_ver=$("$BINARY_PATH" --version 2>&1 | head -1 || echo "unknown") # the rollback threshold (7.3): vX.Y.Z-N is newer than vX.Y.Z and older # than the next patch; an older version only on request version_key() { [[ "$1" =~ v([0-9]+)\.([0-9]+)\.([0-9]+)(-([0-9]+))? ]] || return 1 printf '%05d%05d%07d%08d' "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}" "${BASH_REMATCH[5]:-0}" } if old_key=$(version_key "$old_ver") && new_key=$(version_key "$new_ver") && [[ "$new_key" < "$old_key" ]]; then [ "${GATEWAY_ALLOW_DOWNGRADE:-0}" = "1" ] \ || err "The release is older than the gatewayd running here — refusing (GATEWAY_ALLOW_DOWNGRADE=1 installs it anyway)" warn "Installing an older version because GATEWAY_ALLOW_DOWNGRADE=1" fi # Runtime packages a newer gatewayd may exec that an older install never # got (openvpn was missing from every install before 2026-10-07). Only # ABSENT packages are installed, and only when that upgrades nothing # already on the box: --no-upgrade covers the named packages but not # their versioned dependencies (libssl3, libpcap…), so the install is # simulated first and skipped with a warning if it would move any of # them on a live node. Runs before the version check so re-running an update repairs # the dependencies even when the binary is current. Keep in sync with # install_base_packages in install-gateway.sh. missing="" for p in nftables iptables iproute2 conntrack wireguard-tools openvpn curl wget jq \ ca-certificates openssl openssh-client sqlite3 tcpdump ethtool cryptsetup \ procps iputils-ping kmod dbus python3 python3-yaml; do dpkg-query -W -f='${Status}' "$p" 2>/dev/null | grep -q "ok installed" || missing="$missing $p" done if ! command -v dhcpcd >/dev/null 2>&1; then for p in dhcpcd-base dhcpcd5 dhcpcd; do apt-cache show "$p" >/dev/null 2>&1 && { missing="$missing $p"; break; } done fi if [ -n "$missing" ]; then log "Installing missing runtime packages:$missing" apt-get update -qq || warn "apt-get update failed — using the package lists already on the node" upgrades=$(apt-get -s install -y --no-upgrade $missing 2>/dev/null | awk '/^Inst / && $3 ~ /^\[/ {printf "%s ", $2}' || true) if [ -n "$upgrades" ]; then warn "installing$missing would also upgrade packages already on this node: $upgrades— skipped; run 'apt-get install$missing' in a maintenance window" elif apt-get install -y -qq --no-upgrade $missing; then case " $missing " in *" openvpn "*) systemctl disable --now openvpn 2>/dev/null || true ;; esac else warn "could not install:$missing — continuing with the binary update; features needing them stay off" fi fi info " current: $old_ver" info " new: $new_ver" if [ "$old_ver" = "$new_ver" ] && [ "$old_ver" != "unknown" ]; then info "Versions match — nothing to do (re-run with GATEWAY_VERSION= to force)" exit 0 fi # Snapshot the running binary in case the new one wedges and # the operator needs to roll back fast. Same shape as the # deploy-pi.sh / deploy-vps.sh inline backup that we've been # using by hand all day. backup="/usr/local/bin/gatewayd.bak.$(date -u +%Y%m%dT%H%M%SZ)" cp /usr/local/bin/gatewayd "$backup" info " backup: $backup" # NEVER SIGKILL — corrupts the SQLite WAL on a write-in-progress # and we've burned an hour of recovery time on that before # (per project memory feedback_deploy_no_sigkill.md). Graceful # stop only. systemctl stop gatewayd cp "$BINARY_PATH" /usr/local/bin/gatewayd chmod +x /usr/local/bin/gatewayd systemctl start gatewayd sleep 4 if systemctl is-active gatewayd >/dev/null 2>&1; then log "gatewayd updated: $(/usr/local/bin/gatewayd --version 2>&1 | head -1)" info "Rollback: sudo systemctl stop gatewayd && sudo cp $backup /usr/local/bin/gatewayd && sudo systemctl start gatewayd" else warn "gatewayd failed to start with new binary — rolling back to $backup" systemctl stop gatewayd cp "$backup" /usr/local/bin/gatewayd systemctl start gatewayd err "Rolled back. Check: journalctl -u gatewayd -n 50" fi exit 0 fi # ── Hand off to the full installer ── INSTALLER_ARGS=( --profile "$PROFILE" --binary "$BINARY_PATH" ) if [ "$NONINTERACTIVE" = "1" ]; then INSTALLER_ARGS+=( --non-interactive ) fi # The installer's questions need a terminal: `curl … | sudo bash` leaves # stdin on the pipe this script came through, where the first question met # its end and the installer stopped without a word. Ask on the terminal, or # install with the defaults when there is none. if [ "$NONINTERACTIVE" != "1" ] && [ ! -t 0 ]; then if { : < /dev/tty; } 2>/dev/null; then log "Handing off to install-gateway.sh ${INSTALLER_ARGS[*]} (questions on the terminal)" exec bash "$INSTALLER" "${INSTALLER_ARGS[@]}" < /dev/tty fi warn "No terminal to ask on: installing with the defaults (as with GATEWAY_NONINTERACTIVE=1)" INSTALLER_ARGS+=( --non-interactive ) fi log "Handing off to install-gateway.sh ${INSTALLER_ARGS[*]}" exec bash "$INSTALLER" "${INSTALLER_ARGS[@]}"