#!/bin/sh set -e BASE_URL="https://get.wrapd.sh" BINARY="wrapd-agent" INSTALL_DIR="/usr/local/bin" TOKEN="${WRAPD_TOKEN:-}" # Detect OS and architecture OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) case "$OS" in linux) OS_NAME="linux" ;; darwin) OS_NAME="darwin" ;; *) echo "Error: unsupported OS: $OS" exit 1 ;; esac case "$ARCH" in x86_64|amd64) ARCH_NAME="amd64" ;; aarch64|arm64) ARCH_NAME="arm64" ;; *) echo "Error: unsupported architecture: $ARCH" exit 1 ;; esac ASSET="${BINARY}-${OS_NAME}-${ARCH_NAME}.tar.gz" echo "Downloading ${BINARY} (${OS_NAME}/${ARCH_NAME})..." TMPDIR=$(mktemp -d) curl -fsSL "${BASE_URL}/releases/${ASSET}" -o "${TMPDIR}/${ASSET}" echo "Installing to ${INSTALL_DIR}..." tar xzf "${TMPDIR}/${ASSET}" -C "${TMPDIR}" if [ -w "$INSTALL_DIR" ]; then mv "${TMPDIR}/${BINARY}-${OS_NAME}-${ARCH_NAME}" "${INSTALL_DIR}/${BINARY}" else sudo mv "${TMPDIR}/${BINARY}-${OS_NAME}-${ARCH_NAME}" "${INSTALL_DIR}/${BINARY}" fi chmod +x "${INSTALL_DIR}/${BINARY}" rm -rf "$TMPDIR" # Set up systemd service on Linux if [ "$OS_NAME" = "linux" ] && command -v systemctl >/dev/null 2>&1; then sudo tee /etc/systemd/system/wrapd-agent.service >/dev/null <<'UNIT' [Unit] Description=Wrapd Agent After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/local/bin/wrapd-agent Restart=always RestartSec=5 EnvironmentFile=-/etc/wrapd/agent.env [Install] WantedBy=multi-user.target UNIT sudo mkdir -p /etc/wrapd if [ -n "$TOKEN" ]; then echo "WRAPD_TOKEN=${TOKEN}" | sudo tee /etc/wrapd/agent.env >/dev/null elif [ ! -f /etc/wrapd/agent.env ] || ! grep -q 'WRAPD_TOKEN=' /etc/wrapd/agent.env 2>/dev/null; then echo "# WRAPD_TOKEN=your_token_here" | sudo tee /etc/wrapd/agent.env >/dev/null fi sudo systemctl daemon-reload sudo systemctl enable wrapd-agent >/dev/null 2>&1 if [ -n "$TOKEN" ]; then sudo systemctl restart wrapd-agent echo "" echo " wrapd-agent installed and running." echo " Status: sudo systemctl status wrapd-agent" echo "" else echo "" echo " wrapd-agent installed. Set your token and start:" echo "" echo " curl -fsSL https://get.wrapd.sh | WRAPD_TOKEN=your_token sh" echo "" fi # macOS launchd elif [ "$OS_NAME" = "darwin" ]; then PLIST="$HOME/Library/LaunchAgents/sh.wrapd.agent.plist" mkdir -p "$HOME/Library/LaunchAgents" PLIST_TOKEN="${TOKEN:-YOUR_TOKEN_HERE}" cat > "$PLIST" < Label sh.wrapd.agent ProgramArguments /usr/local/bin/wrapd-agent RunAtLoad KeepAlive StandardOutPath /tmp/wrapd-agent.log StandardErrorPath /tmp/wrapd-agent.log EnvironmentVariables WRAPD_TOKEN ${PLIST_TOKEN} PLIST if [ -n "$TOKEN" ]; then launchctl unload "$PLIST" 2>/dev/null || true launchctl load "$PLIST" echo "" echo " wrapd-agent installed and running." echo " Logs: tail -f /tmp/wrapd-agent.log" echo "" else echo "" echo " wrapd-agent installed. Set your token and start:" echo "" echo " curl -fsSL https://get.wrapd.sh | WRAPD_TOKEN=your_token sh" echo "" fi else echo "" echo " wrapd-agent installed to ${INSTALL_DIR}/${BINARY}" echo " Run: ${BINARY} --token YOUR_TOKEN" echo "" fi