wallarm/setup.sh
admin dfd7180556 feat: bubbletea TUI — wizard + dashboard
- Wizard: type pick → cloud region → token → node config (huh forms)
- Dashboard: node list with status, action shortcuts
- Auto-routes based on ~/.wallarm/state.json existence
- Replaces text stubs with proper interactive TUI
2026-08-01 13:16:08 +00:00

191 lines
7.8 KiB
Bash
Executable file

#!/bin/bash
# ==============================================================================
# Wallarm Deployment Setup Script
# ==============================================================================
# Downloads Wallarm deployment scripts from the Git repository and places
# them in a single deploy/ directory.
#
# When run interactively (or piped via curl|bash to a terminal), asks which
# deployment type to download:
# 1. docker - Wallarm filtering node as a Docker container
# 2. native - Wallarm filtering node installed directly on the OS (no Docker)
# 3. both - All scripts (docker + native)
#
# Falls back to downloading BOTH only when fully headless (no /dev/tty).
# Override with the DEPLOYMENT_TYPE env var:
# DEPLOYMENT_TYPE=native curl -fsSL ".../setup.sh" | bash
# DEPLOYMENT_TYPE=docker curl -fsSL ".../setup.sh" | bash
#
# Downloads the repo archive once, then copies only the needed folders
# (common + docker and/or native) into deploy/. No per-file curl calls.
# ==============================================================================
set -euo pipefail
# Color definitions
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# Git repository archive URL (Gitea-style)
REPO_ARCHIVE="https://git.sechpoint.app/customer-engineering/wallarm/archive/main.tar.gz"
# Temp directory for extracted archive
TEMP_DIR=$(mktemp -d /tmp/wallarm-setup.XXXXXX)
trap 'rm -rf "$TEMP_DIR"' EXIT
# Detect download command
if command -v curl >/dev/null 2>&1; then
DOWNLOAD_NAME="curl"
elif command -v wget >/dev/null 2>&1; then
DOWNLOAD_NAME="wget"
else
echo -e "${RED}${BOLD}ERROR:${NC} Neither curl nor wget is installed."
echo -e "Please install one of them and run this script again."
exit 1
fi
# --- Archive download and extraction ---
download_archive() {
echo -e "${YELLOW}Downloading deployment scripts from repository...${NC}"
if [ "$DOWNLOAD_NAME" = "curl" ]; then
curl -fsSL "$REPO_ARCHIVE" | tar -xz --strip-components=1 -C "$TEMP_DIR" 2>/dev/null
else
wget -qO- "$REPO_ARCHIVE" | tar -xz --strip-components=1 -C "$TEMP_DIR" 2>/dev/null
fi
if [[ ! -d "$TEMP_DIR/common" ]]; then
echo -e "${RED}${BOLD}ERROR:${NC} Failed to download or extract repository archive."
echo -e "Check network connectivity to: ${REPO_ARCHIVE}"
exit 1
fi
echo -e "${GREEN} Success: archive downloaded and extracted.${NC}"
}
deploy_type() {
local type="$1"
# Copy common library (always needed)
cp "$TEMP_DIR/common/"* "deploy/" 2>/dev/null || true
# Copy the selected deployment type's folder
if [[ -d "$TEMP_DIR/$type" ]]; then
cp "$TEMP_DIR/$type/"* "deploy/" 2>/dev/null || true
chmod +x deploy/*.sh 2>/dev/null || true
echo -e "${GREEN} Copied: common + ${type} scripts → deploy/${NC}"
else
echo -e "${RED} Folder '$type' not found in archive.${NC}"
exit 1
fi
}
# Main
clear 2>/dev/null || true
echo -e "${BLUE}${BOLD}"
echo "╔══════════════════════════════════════════════════════════════╗"
echo "║ WALLARM DEPLOYMENT SETUP SCRIPT ║"
echo "║ Downloads all necessary deployment tools ║"
echo "╚══════════════════════════════════════════════════════════════╝${NC}"
echo
# Decide which deployment type(s) to download
DEPLOY_TYPES=()
# Priority 1: explicit DEPLOYMENT_TYPE env var (non-interactive override)
if [[ "${DEPLOYMENT_TYPE:-}" =~ ^(docker|native)$ ]]; then
DEPLOY_TYPES+=("$DEPLOYMENT_TYPE")
echo -e "${GREEN}Downloading only: $DEPLOYMENT_TYPE (from DEPLOYMENT_TYPE env var)${NC}"
# Priority 2 + 3: try interactive prompt via terminal or /dev/tty
else
# Determine where we can read user input from
INTERACTIVE=""
if [[ -t 0 ]]; then
INTERACTIVE="/dev/stdin"
elif [[ -c /dev/tty ]]; then
INTERACTIVE="/dev/tty"
fi
if [[ -n "$INTERACTIVE" ]]; then
echo -e "${CYAN}Which deployment type do you need?${NC}"
echo -e " ${YELLOW}1${NC}) Docker only — Wallarm node as a container"
echo -e " ${YELLOW}2${NC}) Native only — Wallarm node directly on this OS (no Docker)"
echo -e " ${YELLOW}3${NC}) Both — docker + native scripts"
echo
while true; do
read -r -p "$(echo -e "${YELLOW}Enter choice [1/2/3]: ${NC}")" choice <"$INTERACTIVE" 2>/dev/null || {
echo -e "${YELLOW}Input unavailable, defaulting to BOTH.${NC}"
DEPLOY_TYPES+=("docker" "native")
break
}
case "$choice" in
1) DEPLOY_TYPES+=("docker"); break ;;
2) DEPLOY_TYPES+=("native"); break ;;
3) DEPLOY_TYPES+=("docker" "native"); break ;;
*) echo -e "${RED}Invalid choice. Enter 1, 2, or 3.${NC}" ;;
esac
done
echo
else
# Fully headless — default to both
DEPLOY_TYPES+=("docker" "native")
echo -e "${CYAN}No terminal available: downloading BOTH deployment types.${NC}"
echo -e "${YELLOW}To download only one type, set DEPLOYMENT_TYPE=docker or DEPLOYMENT_TYPE=native${NC}"
fi
fi
echo
# Download archive once, then copy only the selected folders
echo
mkdir -p "deploy"
download_archive
for type in "${DEPLOY_TYPES[@]}"; do
deploy_type "$type"
done
# Clean exit trap removes temp dir
# Patch library sourcing path for flat deploy/ structure
# (repo scripts still reference ../common/ — fix until they're updated)
for script in deploy/*.sh; do
[[ "$script" == "deploy/wallarm-lib.sh" ]] && continue
sed -i 's|source "\$SCRIPT_DIR/\.\./common/wallarm-lib\.sh"|source "$SCRIPT_DIR/wallarm-lib.sh"|' "$script"
sed -i 's|# shellcheck source=\.\./common/wallarm-lib\.sh|# shellcheck source=./wallarm-lib.sh|' "$script"
done
echo
echo -e "${GREEN}${BOLD}Setup complete - requested scripts downloaded!${NC}"
echo
# Show next steps only for the deployment types that were downloaded
for deploy_type in "${DEPLOY_TYPES[@]}"; do
case "$deploy_type" in
docker)
echo -e "${CYAN}Docker deployment next steps:${NC}"
echo -e " 1. Run the preflight check: ${YELLOW}./deploy/wallarm-docker.sh --preflight${NC}"
echo -e " 2. Deploy a Wallarm node: ${YELLOW}sudo ./deploy/wallarm-docker.sh --install${NC}"
echo -e " 3. Reconfigure existing node: ${YELLOW}sudo ./deploy/wallarm-docker.sh --config${NC}"
echo -e " 4. Uninstall a node: ${YELLOW}sudo ./deploy/wallarm-docker.sh --remove${NC}"
echo -e " 5. Show node status: ${YELLOW}./deploy/wallarm-docker.sh --status${NC}"
echo
;;
native)
echo -e "${CYAN}Native deployment next steps (no Docker):${NC}"
echo -e " 1. Run the preflight check: ${YELLOW}sudo ./deploy/wallarm-native.sh --preflight${NC}"
echo -e " 2. Deploy Wallarm nodes: ${YELLOW}sudo ./deploy/wallarm-native.sh --install${NC}"
echo -e " 3. Update a node's config: ${YELLOW}sudo ./deploy/wallarm-native.sh --config --node NAME --address IP:PORT${NC}"
echo -e " 4. Remove a node: ${YELLOW}sudo ./deploy/wallarm-native.sh --remove --node NAME${NC}"
echo -e " 5. Show node status: ${YELLOW}./deploy/wallarm-native.sh --status${NC}"
echo
;;
esac
done
echo -e "${YELLOW}Note: Some scripts require sudo. Run them with: sudo ./<script>${NC}"
echo -e "${YELLOW}Make sure you have the required information ready (see documentation).${NC}"