#!/bin/bash # ============================================================================== # Wallarm Deployment Setup Script # ============================================================================== # Downloads all necessary Wallarm deployment scripts from the Git repository # and makes them executable. # # The repository supports two deployment types: # 1. docker - Wallarm filtering node as a Docker container # 2. native - Wallarm filtering node installed directly on the OS (no Docker) # # Usage: curl -fsSL "https://git.sechpoint.app/customer-engineering/wallarm/raw/branch/main/setup.sh" | bash # DEPLOYMENT_TYPE=native curl -fsSL ".../setup.sh" | bash (non-interactive) # ============================================================================== 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-ct-check.sh" "wallarm-ct-deploy.sh" "wallarm-ct-reconfigure.sh" "wallarm-ct-uninstall.sh" "wallarm-native.sh" ) # Detect download command if command -v curl >/dev/null 2>&1; then DOWNLOAD_CMD="curl -fL -O" DOWNLOAD_NAME="curl" elif command -v wget >/dev/null 2>&1; then DOWNLOAD_CMD="wget -q" 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 # Select the deployment type (interactive or via DEPLOYMENT_TYPE env var) select_deployment_type() { if [[ "${DEPLOYMENT_TYPE:-}" =~ ^(docker|native)$ ]]; then DEPLOY_TYPE="$DEPLOYMENT_TYPE" echo -e "${GREEN}Deployment type: $DEPLOY_TYPE${NC}" return 0 fi echo -e "${CYAN}${BOLD}Select the deployment type:${NC}" echo -e " 1. ${YELLOW}docker${NC} - Wallarm filtering node as a Docker container (LXC-optimized)" echo -e " 2. ${YELLOW}native${NC} - Wallarm filtering node installed directly on the OS (no Docker)" read -r -p "$(echo -e "${YELLOW}Enter choice [1/2] (default: docker): ${NC}")" choice case "${choice:-1}" in 1|docker) DEPLOY_TYPE="docker" ;; 2|native) DEPLOY_TYPE="native" ;; *) DEPLOY_TYPE="docker" ;; esac } download_file() { local url="$1" local dest="$2" local description="$3" echo -e "${YELLOW}Downloading ${description}...${NC}" if [ "$DOWNLOAD_NAME" = "curl" ]; then curl -fL "$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 } # Main clear echo -e "${BLUE}${BOLD}" echo "╔══════════════════════════════════════════════════════════════╗" echo "║ WALLARM DEPLOYMENT SETUP SCRIPT ║" echo "║ Downloads all necessary deployment tools ║" echo "╚══════════════════════════════════════════════════════════════╝${NC}" echo # Select deployment type select_deployment_type # Determine target directories COMMON_DIR="common" TARGET_DIR="$DEPLOY_TYPE" echo -e "${BLUE}Target directory: ${TARGET_DIR}/${NC}" # Check for existing scripts if ls "$TARGET_DIR"/wallarm-ct-*.sh 2>/dev/null | grep -q .; then echo -e "${YELLOW}Existing $DEPLOY_TYPE Wallarm scripts found.${NC}" echo -e "${YELLOW}Do you want to re-download all? (y/N)${NC}" read -r answer if [[ ! "$answer" =~ ^[Yy]$ ]]; then echo -e "${BLUE}Exiting without changes.${NC}" exit 0 fi fi # Select the script list for the chosen deployment type case "$DEPLOY_TYPE" in native) SCRIPTS=("${NATIVE_SCRIPTS[@]}") ;; *) SCRIPTS=("${DOCKER_SCRIPTS[@]}") ;; esac # Create target directories mkdir -p "$TARGET_DIR" "$COMMON_DIR" # Download shared library download_file "${GIT_BASE}common/wallarm-lib.sh" "${COMMON_DIR}/wallarm-lib.sh" "shared library (${COMMON_DIR}/wallarm-lib.sh)" # Download the deployment type scripts for script in "${SCRIPTS[@]}"; do download_file "${GIT_BASE}${TARGET_DIR}/${script}" "${TARGET_DIR}/${script}" "$DEPLOY_TYPE/$script" done echo echo -e "${GREEN}${BOLD}All $DEPLOY_TYPE scripts downloaded successfully!${NC}" echo if [ "$DEPLOY_TYPE" = "native" ]; then echo -e "${CYAN}Next steps:${NC}" echo -e " 1. Run the preflight check: ${YELLOW}./native/wallarm-ct-check.sh${NC}" echo -e " 2. Deploy a Wallarm node: ${YELLOW}./native/wallarm-ct-deploy.sh${NC}" echo -e " 3. Unified node manager: ${YELLOW}./native/wallarm-native.sh --preflight${NC} (then --install)" echo -e " 4. Reconfigure existing node: ${YELLOW}./native/wallarm-ct-reconfigure.sh${NC}" echo -e " 5. Uninstall a node: ${YELLOW}./native/wallarm-ct-uninstall.sh${NC}" else echo -e "${CYAN}Next steps:${NC}" echo -e " 1. Run the preflight check: ${YELLOW}./docker/wallarm-ct-check.sh${NC}" echo -e " 2. Deploy a Wallarm node: ${YELLOW}./docker/wallarm-ct-deploy.sh${NC}" echo -e " 3. Reconfigure existing node: ${YELLOW}./docker/wallarm-ct-reconfigure.sh${NC}" echo -e " 4. Uninstall a node: ${YELLOW}./docker/wallarm-ct-uninstall.sh${NC}" fi echo echo -e "${YELLOW}Note: Some scripts require sudo. Run them with: sudo ./