wallarm/deploy.sh
admin 58faccbb27 fix: source-based deploy.sh — clones repo, builds binary
Gitea server has strict HTTP body limits (~1MB) preventing binary
uploads.  deploy.sh now clones the repo and builds from source using
Go (auto-installed if missing).

Build takes ~30 seconds.  Binary is ~7MB stripped, ~2MB with UPX.
2026-08-01 14:37:28 +00:00

90 lines
3.2 KiB
Bash

#!/bin/bash
# ==============================================================================
# Wallarm Deployment — Source-based Bootstrap
# ==============================================================================
# Clones the repository and builds the wallarm binary from source.
# One command to get started:
#
# curl -fsSL ".../deploy.sh" | bash
# sudo ./deploy/wallarm
#
# Requires: git, go (auto-installed if missing on apt/yum systems)
# ==============================================================================
set -euo pipefail
BOLD='\033[1m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
REPO_URL="https://git.sechpoint.app/customer-engineering/wallarm.git"
DEPLOY_DIR="${HOME:-/root}/deploy"
BUILD_DIR="/tmp/wallarm-build-$$"
cleanup() { rm -rf "$BUILD_DIR"; }
trap cleanup EXIT
echo -e "${BOLD}Wallarm Deployment Bootstrap${NC}"
echo
# ── Ensure prerequisites ─────────────────────────────────────────────
install_go() {
echo -e "${YELLOW}Installing Go...${NC}"
if command -v apt-get >/dev/null 2>&1; then
apt-get update -qq && apt-get install -y -qq golang-go
elif command -v yum >/dev/null 2>&1; then
yum install -y golang
elif command -v dnf >/dev/null 2>&1; then
dnf install -y golang
elif command -v apk >/dev/null 2>&1; then
apk add --no-cache go
else
echo -e "${RED}Cannot install Go automatically. Install Go 1.21+ manually.${NC}"
exit 1
fi
}
# Ensure git
if ! command -v git >/dev/null 2>&1; then
echo -e "${YELLOW}Installing git...${NC}"
apt-get update -qq 2>/dev/null && apt-get install -y -qq git 2>/dev/null || true
fi
# Ensure Go
if ! command -v go >/dev/null 2>&1; then
install_go
fi
echo -e "${GREEN} git: $(git --version | cut -d' ' -f3)${NC}"
echo -e "${GREEN} go: $(go version | cut -d' ' -f3)${NC}"
# ── Clone and build ───────────────────────────────────────────────────
echo
echo -e "${YELLOW}Cloning repository...${NC}"
git clone --depth 1 "$REPO_URL" "$BUILD_DIR" 2>/dev/null
echo -e "${YELLOW}Building wallarm (this takes ~30 seconds)...${NC}"
cd "$BUILD_DIR"
go build -ldflags="-s -w -X main.version=$(git describe --tags --always 2>/dev/null || echo 'dev')" -o wallarm ./cmd/wallarm/
# Optional: compress with UPX if available
if command -v upx >/dev/null 2>&1; then
upx --best --lzma wallarm -o wallarm.tmp 2>/dev/null && mv wallarm.tmp wallarm || true
fi
# ── Install ───────────────────────────────────────────────────────────
mkdir -p "$DEPLOY_DIR"
cp wallarm "$DEPLOY_DIR/wallarm"
chmod +x "$DEPLOY_DIR/wallarm"
echo
echo -e "${GREEN}${BOLD}Ready!${NC}"
echo
echo -e " ${CYAN}sudo ${DEPLOY_DIR}/wallarm${NC} — Start the TUI"
echo -e " ${CYAN}${DEPLOY_DIR}/wallarm --help${NC} — Show all commands"
echo -e " ${CYAN}${DEPLOY_DIR}/wallarm --tunnel${NC} — Start remote tunnel"
echo
ls -lh "$DEPLOY_DIR/wallarm"