auth-runtime/install.sh

66 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Install auth-rt binary.
#
# Mode 1 (local build): ./install.sh [bin-dir]
# Requires Go. Compiles from source and installs.
#
# Mode 2 (download): ./install.sh --download [bin-dir]
# Downloads pre-built binary from Forgejo release.
#
# Default bin dir: ~/.local/bin
set -euo pipefail
FORGEJO="http://192.168.0.108:3030"
REPO="agent-skills/auth-runtime"
BIN_DIR="$HOME/.local/bin"
MODE="local"
for arg in "$@"; do
case "$arg" in
--download) MODE="download" ;;
-*) echo "Unknown flag: $arg"; exit 1 ;;
*) BIN_DIR="$arg" ;;
esac
done
mkdir -p "$BIN_DIR"
if [ "$MODE" = "download" ]; then
# Detect platform
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
esac
ASSET="auth-rt-${OS}-${ARCH}"
URL="$FORGEJO/$REPO/releases/download/latest/$ASSET"
echo "Downloading $ASSET..."
if command -v curl &>/dev/null; then
curl -fsSL "$URL" -o "$BIN_DIR/auth-rt"
elif command -v wget &>/dev/null; then
wget -q "$URL" -O "$BIN_DIR/auth-rt"
else
echo "ERROR: curl or wget required"; exit 1
fi
chmod +x "$BIN_DIR/auth-rt"
echo "Installed: $BIN_DIR/auth-rt (downloaded)"
else
# Local build
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CLI_DIR="$SCRIPT_DIR/cli"
if ! command -v go &>/dev/null; then
echo "Go not found. Use --download to fetch pre-built binary instead."
exit 1
fi
echo "Building auth-rt..."
cd "$CLI_DIR"
go build -ldflags="-s -w" -o "$BIN_DIR/auth-rt" .
echo "Installed: $BIN_DIR/auth-rt (built from source)"
fi