#!/bin/bash set -euo pipefail gateway_origin='https://unlimit.leeh.dev' editor_sha256='39bbbd1d159fd5a3b6aa3e31e0fee00f67169b84e07ac28ceec016d7e53e56ce' gateway_key='' if [ "$#" -gt 0 ]; then if [ "$#" -ne 2 ] || [ "$1" != '--key' ]; then echo 'Usage: bash install.sh [--key cgw_...]' >&2; exit 1; fi gateway_key="$2" else printf 'Gateway key (cgw_...): ' >/dev/tty IFS= read -r -s gateway_key /dev/tty fi if ! [[ "$gateway_key" =~ ^cgw_[A-Za-z0-9_-]{43}$ ]]; then echo 'Invalid gateway key. Paste the complete cgw_ key.' >&2; exit 1; fi if [ "$(uname -s)" != 'Darwin' ]; then echo 'This installer requires macOS.' >&2; exit 1; fi umask 077 installer_temp=$(mktemp -d "${TMPDIR:-/tmp}/gateway-install.XXXXXXXX") trap 'unset gateway_key; rm -rf -- "$installer_temp"' EXIT curl --proto '=https' --tlsv1.2 -fsSL "$gateway_origin/install/configure.cjs" -o "$installer_temp/configure.cjs" printf '%s %s\n' "$editor_sha256" "$installer_temp/configure.cjs" | shasum -a 256 -c - >/dev/null node_path=$(command -v node || true) if [ -n "$node_path" ] && ! "$node_path" -e 'process.exit(Number(process.versions.node.split(".")[0]) >= 20 ? 0 : 1)'; then node_path=''; fi if [ -z "$node_path" ]; then echo 'Downloading a temporary Node.js runtime...' case "$(uname -m)" in arm64) node_arch=arm64 ;; x86_64) node_arch=x64 ;; *) echo 'Unsupported Mac architecture.' >&2; exit 1 ;; esac release_root='https://nodejs.org/dist/latest-v24.x' curl --proto '=https' --tlsv1.2 -fsSL "$release_root/SHASUMS256.txt" -o "$installer_temp/SHASUMS256.txt" archive_name=$(awk -v arch="$node_arch" '$2 ~ ("^node-v24\\.[0-9]+\\.[0-9]+-darwin-" arch "\\.tar\\.gz$") { print $2; exit }' "$installer_temp/SHASUMS256.txt") if [ -z "$archive_name" ]; then echo 'Could not find the Node.js runtime checksum.' >&2; exit 1; fi curl --proto '=https' --tlsv1.2 -fsSL "$release_root/$archive_name" -o "$installer_temp/$archive_name" (cd "$installer_temp"; awk -v name="$archive_name" '$2 == name' SHASUMS256.txt | shasum -a 256 -c - >/dev/null) tar -xzf "$installer_temp/$archive_name" -C "$installer_temp" node_path="$installer_temp/${archive_name%.tar.gz}/bin/node" fi printf '%s\n' "$gateway_key" | "$node_path" "$installer_temp/configure.cjs" "$gateway_origin"