#!/bin/sh
# ingex installer — downloads the binary from the releases host and installs the
# tool (the one privileged step, via sudo). Then join your edge with `ingex auth`.
#
#   curl -fsSL https://ingex.<your-edge>/install.sh | bash          # edge redirects here
#   curl -fsSL https://downloads.renzat.work/ingex/releases/install.sh | bash
#
# Env: INGEX_RELEASES_URL (releases base), INGEX_VERSION (default "latest").
set -e

RELEASES="${INGEX_RELEASES_URL:-https://downloads.renzat.work/ingex/releases}"
VERSION="${INGEX_VERSION:-latest}"
BIN="$(mktemp)"
trap 'rm -f "$BIN"' EXIT

echo "Downloading ingex ($VERSION) from $RELEASES ..."
curl -fsSL "$RELEASES/$VERSION/ingex" -o "$BIN"
chmod +x "$BIN"

echo "Installing (copies to /usr/local/bin, grants CAP_NET_ADMIN, loads the wg module):"
if [ "$(id -u)" -eq 0 ]; then
  "$BIN" install
else
  sudo "$BIN" install
fi

echo
echo "Next (no sudo needed):"
echo "  ingex auth --server https://ingex.<your-edge> --token <token>"
echo "  ingex up"
