#!/bin/sh # Trident HTTP Cache Proxy - Universal Installer # # Usage: # curl -sSL https://get.trident-cache.com/install.sh | sh # curl -sSL https://get.trident-cache.com/install.sh | sh -s -- --prefix /opt/trident # # Options: # --prefix DIR Installation prefix (default: /usr/local) # --version VER Install specific version (default: latest) # --with-service Install systemd service and default config # --help Show this help set -e REPO="Trident-Cache/trident-cache" PREFIX="/usr/local" VERSION="" INSTALL_SERVICE=false # --------------------------------------------------------------------------- # Helpers # --------------------------------------------------------------------------- info() { printf "\033[1;34m==>\033[0m %s\n" "$1" } error() { printf "\033[1;31mError:\033[0m %s\n" "$1" >&2 exit 1 } need_cmd() { if ! command -v "$1" >/dev/null 2>&1; then error "Required command not found: $1" fi } # --------------------------------------------------------------------------- # Detect platform # --------------------------------------------------------------------------- detect_os() { case "$(uname -s)" in Linux*) echo "linux" ;; Darwin*) echo "macos" ;; MINGW*|MSYS*|CYGWIN*) echo "windows" ;; *) error "Unsupported operating system: $(uname -s)" ;; esac } detect_arch() { case "$(uname -m)" in x86_64|amd64) echo "x64" ;; aarch64|arm64) echo "arm64" ;; *) error "Unsupported architecture: $(uname -m)" ;; esac } # --------------------------------------------------------------------------- # Fetch latest version from GitHub API # --------------------------------------------------------------------------- get_latest_version() { if command -v curl >/dev/null 2>&1; then curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" \ | grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"//;s/".*//' elif command -v wget >/dev/null 2>&1; then wget -qO- "https://api.github.com/repos/${REPO}/releases/latest" \ | grep '"tag_name"' | head -1 | sed 's/.*"tag_name": *"//;s/".*//' else error "Neither curl nor wget found. Please install one of them." fi } # --------------------------------------------------------------------------- # Download file # --------------------------------------------------------------------------- download() { url="$1" dest="$2" if command -v curl >/dev/null 2>&1; then curl -fsSL -o "$dest" "$url" elif command -v wget >/dev/null 2>&1; then wget -qO "$dest" "$url" else error "Neither curl nor wget found." fi } # --------------------------------------------------------------------------- # Parse arguments # --------------------------------------------------------------------------- while [ $# -gt 0 ]; do case "$1" in --prefix) PREFIX="$2" shift 2 ;; --version) VERSION="$2" shift 2 ;; --with-service) INSTALL_SERVICE=true shift ;; --help) sed -n '2,/^$/s/^# \{0,1\}//p' "$0" exit 0 ;; *) error "Unknown option: $1" ;; esac done # --------------------------------------------------------------------------- # Main # --------------------------------------------------------------------------- OS="$(detect_os)" ARCH="$(detect_arch)" info "Detected platform: ${OS}/${ARCH}" # Resolve version if [ -z "$VERSION" ]; then info "Fetching latest release version..." VERSION="$(get_latest_version)" if [ -z "$VERSION" ]; then error "Could not determine latest version. Use --version to specify." fi fi info "Installing Trident ${VERSION}" # Build artifact name ARTIFACT="trident-${OS}-${ARCH}" if [ "$OS" = "windows" ]; then EXT="zip" else EXT="tar.gz" fi DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${ARTIFACT}.${EXT}" # Download TMPDIR="$(mktemp -d)" trap 'rm -rf "$TMPDIR"' EXIT info "Downloading ${DOWNLOAD_URL}" download "$DOWNLOAD_URL" "${TMPDIR}/trident.${EXT}" # Extract info "Extracting..." if [ "$EXT" = "tar.gz" ]; then tar -xzf "${TMPDIR}/trident.${EXT}" -C "$TMPDIR" else need_cmd unzip unzip -q "${TMPDIR}/trident.${EXT}" -d "$TMPDIR" fi # Install binaries info "Installing to ${PREFIX}/bin/" mkdir -p "${PREFIX}/bin" for bin in trident trident-cli trident-snap; do if [ "$OS" = "windows" ]; then bin="${bin}.exe" fi if [ -f "${TMPDIR}/${bin}" ]; then install -m 0755 "${TMPDIR}/${bin}" "${PREFIX}/bin/${bin}" info " Installed ${bin}" fi done # Optionally install systemd service and config if [ "$INSTALL_SERVICE" = true ] && [ "$OS" = "linux" ]; then info "Installing systemd service..." # Download dist files from the release tag BASE_RAW="https://raw.githubusercontent.com/${REPO}/${VERSION}" mkdir -p /etc/trident if [ ! -f /etc/trident/config.json ] && [ ! -f /etc/trident/config.toml ]; then info " Installing default config to /etc/trident/config.json" download "${BASE_RAW}/dist/config.json" /etc/trident/config.json else info " Existing config found, skipping" fi if [ ! -f /etc/default/trident ]; then download "${BASE_RAW}/dist/trident.default" /etc/default/trident fi download "${BASE_RAW}/dist/trident.service" /usr/lib/systemd/system/trident.service # Create system user if ! getent group trident >/dev/null 2>&1; then groupadd --system trident fi if ! getent passwd trident >/dev/null 2>&1; then useradd --system --gid trident --home-dir /var/lib/trident \ --shell /usr/sbin/nologin --comment "Trident HTTP Cache Proxy" trident fi mkdir -p /var/lib/trident /var/log/trident chown trident:trident /var/lib/trident /var/log/trident systemctl daemon-reload info " Service installed. Enable with: systemctl enable --now trident" fi # Verify if command -v "${PREFIX}/bin/trident" >/dev/null 2>&1; then INSTALLED_VERSION="$("${PREFIX}/bin/trident" --version 2>/dev/null || echo "unknown")" info "Trident installed successfully: ${INSTALLED_VERSION}" else info "Trident installed successfully to ${PREFIX}/bin/" fi info "Run 'trident --help' to get started."