wallarm/setup.sh
admin 83f73c0e9c simplify: setup.sh just builds and drops binary in /opt/fw/
No directory structure creation, no confusing messages.
Deploy binary handles everything else.
2026-08-01 17:00:43 +00:00

59 lines
2.5 KiB
Bash

#!/bin/bash
# ==============================================================================
# Wallarm Deployment Bootstrap
# ==============================================================================
# Builds the deploy binary and installs to /opt/fw/.
# The binary handles everything: symlinks, extraction, setup.
#
# curl -fsSL ".../setup.sh" | bash
# sudo /opt/fw/deploy
# ==============================================================================
set -euo pipefail
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
REPO_URL="https://git.sechpoint.app/customer-engineering/wallarm.git"
WALLARM_DIR="/opt/fw"
BUILD_DIR="/tmp/wallarm-build-$$"
cleanup() { rm -rf "$BUILD_DIR"; }
trap cleanup EXIT
echo -e "${BOLD}Wallarm Bootstrap${NC}"
# ── Prerequisites ─────────────────────────────────────────────────────
if ! command -v git >/dev/null 2>&1; then
apt-get update -qq 2>/dev/null && apt-get install -y -qq git 2>/dev/null || true
fi
if ! command -v go >/dev/null 2>&1; then
echo -e "${YELLOW}Installing Go...${NC}"
apt-get update -qq 2>/dev/null && apt-get install -y -qq golang-go 2>/dev/null || {
echo -e "${RED}Install Go 1.21+ manually.${NC}"; exit 1
}
fi
echo -e "${GREEN}git $(git --version | cut -d' ' -f3) go $(go version | cut -d' ' -f3)${NC}"
# ── Build ─────────────────────────────────────────────────────────────
echo -e "${YELLOW}Cloning...${NC}"
git clone --depth 1 "$REPO_URL" "$BUILD_DIR" 2>/dev/null
echo -e "${YELLOW}Building (~30s)...${NC}"
cd "$BUILD_DIR"
go build -ldflags="-s -w -X main.version=$(git describe --tags --always 2>/dev/null || echo 'dev')" -o deploy ./cmd/deploy/
command -v upx >/dev/null 2>&1 && upx --best --lzma deploy -o deploy.tmp 2>/dev/null && mv deploy.tmp deploy || true
# ── Install ───────────────────────────────────────────────────────────
mkdir -p "$WALLARM_DIR"
cp deploy "$WALLARM_DIR/deploy"
chmod +x "$WALLARM_DIR/deploy"
V=$("$WALLARM_DIR/deploy" --version 2>/dev/null || echo "unknown")
echo
echo -e "${GREEN}${BOLD}Ready!${NC} (${V})"
echo -e " ${GREEN}sudo /opt/fw/deploy${NC}"
ls -lh "$WALLARM_DIR/deploy"