wallarm/setup.sh
admin 68fbb25db2 fix: interactive deploy type selection, flat deploy/ dir, set -u crash fix
- setup.sh: ask user which deployment type (docker/native/both) instead
  of silently downloading everything; uses env var for piped mode
- All scripts now download to single flat deploy/ directory instead of
  separate common/docker/native dirs
- Post-download sed patch fixes library sourcing path until repo is
  synced
- wallarm-native.sh: fix set -u crash when declare -a used without =()
  (user hitting blank node name triggered unbound variable crash)
- All deployment scripts: library source path changed from
  ../common/wallarm-lib.sh to same-directory wallarm-lib.sh
2026-08-01 08:44:38 +00:00

183 lines
7 KiB
Bash
Executable file

#!/bin/bash
# ==============================================================================
# Wallarm Deployment Setup Script
# ==============================================================================
# Downloads Wallarm deployment scripts from the Git repository and makes them
# executable.
#
# When run interactively (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)
#
# When piped (curl ... | bash), downloads BOTH by default for backward
# compatibility. Override with the DEPLOYMENT_TYPE env var:
# DEPLOYMENT_TYPE=native curl -fsSL ".../setup.sh" | bash
# DEPLOYMENT_TYPE=docker curl -fsSL ".../setup.sh" | bash
# ==============================================================================
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 URL base
GIT_BASE="https://git.sechpoint.app/customer-engineering/wallarm/raw/branch/main/"
# Per-deployment-type scripts
DOCKER_SCRIPTS=(
"wallarm-ct-check.sh"
"wallarm-ct-deploy.sh"
"wallarm-ct-reconfigure.sh"
"wallarm-ct-uninstall.sh"
)
NATIVE_SCRIPTS=(
"wallarm-native.sh"
)
# 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
download_file() {
local url="$1"
local dest="$2"
local description="$3"
echo -e "${YELLOW}Downloading ${description}...${NC}"
if [ "$DOWNLOAD_NAME" = "curl" ]; then
curl -fsSL "$url" -o "$dest"
else
wget -q "$url" -O "$dest"
fi
if [ -s "$dest" ]; then
chmod +x "$dest"
echo -e "${GREEN} Success: ${description} downloaded to ${dest}${NC}"
else
rm -f "$dest"
echo -e "${RED} Failed to download ${description}. Check network connectivity.${NC}"
exit 1
fi
}
download_deployment_type() {
local type="$1"
local scripts
case "$type" in
native) scripts=("${NATIVE_SCRIPTS[@]}") ;;
docker) scripts=("${DOCKER_SCRIPTS[@]}") ;;
*) err "Unknown deployment type: $type"; exit 1 ;;
esac
mkdir -p "deploy"
for script in "${scripts[@]}"; do
download_file "${GIT_BASE}${type}/${script}" "deploy/${script}" "deploy/${script}"
done
}
# 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: interactive terminal — ask the user
elif [[ -t 0 ]]; 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
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
# Priority 3: piped (non-interactive) — default to both for backward compatibility
else
DEPLOY_TYPES+=("docker" "native")
echo -e "${CYAN}Non-interactive run: downloading BOTH deployment types.${NC}"
echo -e "${YELLOW}To download only one type, set DEPLOYMENT_TYPE=docker or DEPLOYMENT_TYPE=native${NC}"
fi
echo
# Download shared library (required by all deployment scripts)
mkdir -p "deploy"
download_file "${GIT_BASE}common/wallarm-lib.sh" "deploy/wallarm-lib.sh" "shared library (deploy/wallarm-lib.sh)"
# Download the selected deployment type(s)
for type in "${DEPLOY_TYPES[@]}"; do
download_deployment_type "$type"
done
# Patch library sourcing path for flat deploy/ structure
# (needed until the source scripts in the repo are 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-ct-check.sh${NC}"
echo -e " 2. Deploy a Wallarm node: ${YELLOW}./deploy/wallarm-ct-deploy.sh${NC}"
echo -e " 3. Reconfigure existing node: ${YELLOW}./deploy/wallarm-ct-reconfigure.sh${NC}"
echo -e " 4. Uninstall a node: ${YELLOW}./deploy/wallarm-ct-uninstall.sh${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}"