refactor: download repo archive once, copy selected folders to deploy
- Replaces per-file curl downloads with single archive download (tar.gz from Gitea), extracts only common/ + selected type folder. - Interactive prompt uses /dev/tty when stdin is piped (curl|bash). - Falls back to both only when fully headless. - Post-extract sed patch fixes library sourcing path for flat deploy/ until source scripts are updated in the repo.
This commit is contained in:
parent
68fbb25db2
commit
0ee73f5af3
1 changed files with 77 additions and 70 deletions
117
setup.sh
117
setup.sh
|
|
@ -2,18 +2,22 @@
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Wallarm Deployment Setup Script
|
# Wallarm Deployment Setup Script
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
# Downloads Wallarm deployment scripts from the Git repository and makes them
|
# Downloads Wallarm deployment scripts from the Git repository and places
|
||||||
# executable.
|
# them in a single deploy/ directory.
|
||||||
#
|
#
|
||||||
# When run interactively (terminal), asks which deployment type to download:
|
# 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
|
# 1. docker - Wallarm filtering node as a Docker container
|
||||||
# 2. native - Wallarm filtering node installed directly on the OS (no Docker)
|
# 2. native - Wallarm filtering node installed directly on the OS (no Docker)
|
||||||
# 3. both - All scripts (docker + native)
|
# 3. both - All scripts (docker + native)
|
||||||
#
|
#
|
||||||
# When piped (curl ... | bash), downloads BOTH by default for backward
|
# Falls back to downloading BOTH only when fully headless (no /dev/tty).
|
||||||
# compatibility. Override with the DEPLOYMENT_TYPE env var:
|
# Override with the DEPLOYMENT_TYPE env var:
|
||||||
# DEPLOYMENT_TYPE=native curl -fsSL ".../setup.sh" | bash
|
# DEPLOYMENT_TYPE=native curl -fsSL ".../setup.sh" | bash
|
||||||
# DEPLOYMENT_TYPE=docker 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
|
set -euo pipefail
|
||||||
|
|
@ -27,20 +31,12 @@ CYAN='\033[0;36m'
|
||||||
BOLD='\033[1m'
|
BOLD='\033[1m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
# Git repository URL base
|
# Git repository archive URL (Gitea-style)
|
||||||
GIT_BASE="https://git.sechpoint.app/customer-engineering/wallarm/raw/branch/main/"
|
REPO_ARCHIVE="https://git.sechpoint.app/customer-engineering/wallarm/archive/main.tar.gz"
|
||||||
|
|
||||||
# Per-deployment-type scripts
|
# Temp directory for extracted archive
|
||||||
DOCKER_SCRIPTS=(
|
TEMP_DIR=$(mktemp -d /tmp/wallarm-setup.XXXXXX)
|
||||||
"wallarm-ct-check.sh"
|
trap 'rm -rf "$TEMP_DIR"' EXIT
|
||||||
"wallarm-ct-deploy.sh"
|
|
||||||
"wallarm-ct-reconfigure.sh"
|
|
||||||
"wallarm-ct-uninstall.sh"
|
|
||||||
)
|
|
||||||
|
|
||||||
NATIVE_SCRIPTS=(
|
|
||||||
"wallarm-native.sh"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Detect download command
|
# Detect download command
|
||||||
if command -v curl >/dev/null 2>&1; then
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
|
@ -53,43 +49,39 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
download_file() {
|
# --- Archive download and extraction ---
|
||||||
local url="$1"
|
|
||||||
local dest="$2"
|
|
||||||
local description="$3"
|
|
||||||
|
|
||||||
echo -e "${YELLOW}Downloading ${description}...${NC}"
|
download_archive() {
|
||||||
|
echo -e "${YELLOW}Downloading deployment scripts from repository...${NC}"
|
||||||
if [ "$DOWNLOAD_NAME" = "curl" ]; then
|
if [ "$DOWNLOAD_NAME" = "curl" ]; then
|
||||||
curl -fsSL "$url" -o "$dest"
|
curl -fsSL "$REPO_ARCHIVE" | tar -xz --strip-components=1 -C "$TEMP_DIR" 2>/dev/null
|
||||||
else
|
else
|
||||||
wget -q "$url" -O "$dest"
|
wget -qO- "$REPO_ARCHIVE" | tar -xz --strip-components=1 -C "$TEMP_DIR" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -s "$dest" ]; then
|
if [[ ! -d "$TEMP_DIR/common" ]]; then
|
||||||
chmod +x "$dest"
|
echo -e "${RED}${BOLD}ERROR:${NC} Failed to download or extract repository archive."
|
||||||
echo -e "${GREEN} Success: ${description} downloaded to ${dest}${NC}"
|
echo -e "Check network connectivity to: ${REPO_ARCHIVE}"
|
||||||
else
|
|
||||||
rm -f "$dest"
|
|
||||||
echo -e "${RED} Failed to download ${description}. Check network connectivity.${NC}"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
echo -e "${GREEN} Success: archive downloaded and extracted.${NC}"
|
||||||
}
|
}
|
||||||
|
|
||||||
download_deployment_type() {
|
deploy_type() {
|
||||||
local type="$1"
|
local type="$1"
|
||||||
local scripts
|
|
||||||
|
|
||||||
case "$type" in
|
# Copy common library (always needed)
|
||||||
native) scripts=("${NATIVE_SCRIPTS[@]}") ;;
|
cp "$TEMP_DIR/common/"* "deploy/" 2>/dev/null || true
|
||||||
docker) scripts=("${DOCKER_SCRIPTS[@]}") ;;
|
|
||||||
*) err "Unknown deployment type: $type"; exit 1 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
mkdir -p "deploy"
|
# Copy the selected deployment type's folder
|
||||||
|
if [[ -d "$TEMP_DIR/$type" ]]; then
|
||||||
for script in "${scripts[@]}"; do
|
cp "$TEMP_DIR/$type/"* "deploy/" 2>/dev/null || true
|
||||||
download_file "${GIT_BASE}${type}/${script}" "deploy/${script}" "deploy/${script}"
|
chmod +x deploy/*.sh 2>/dev/null || true
|
||||||
done
|
echo -e "${GREEN} Copied: common + ${type} scripts → deploy/${NC}"
|
||||||
|
else
|
||||||
|
echo -e "${RED} Folder '$type' not found in archive.${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
|
|
@ -109,15 +101,28 @@ if [[ "${DEPLOYMENT_TYPE:-}" =~ ^(docker|native)$ ]]; then
|
||||||
DEPLOY_TYPES+=("$DEPLOYMENT_TYPE")
|
DEPLOY_TYPES+=("$DEPLOYMENT_TYPE")
|
||||||
echo -e "${GREEN}Downloading only: $DEPLOYMENT_TYPE (from DEPLOYMENT_TYPE env var)${NC}"
|
echo -e "${GREEN}Downloading only: $DEPLOYMENT_TYPE (from DEPLOYMENT_TYPE env var)${NC}"
|
||||||
|
|
||||||
# Priority 2: interactive terminal — ask the user
|
# Priority 2 + 3: try interactive prompt via terminal or /dev/tty
|
||||||
elif [[ -t 0 ]]; then
|
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 "${CYAN}Which deployment type do you need?${NC}"
|
||||||
echo -e " ${YELLOW}1${NC}) Docker only — Wallarm node as a container"
|
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}2${NC}) Native only — Wallarm node directly on this OS (no Docker)"
|
||||||
echo -e " ${YELLOW}3${NC}) Both — docker + native scripts"
|
echo -e " ${YELLOW}3${NC}) Both — docker + native scripts"
|
||||||
echo
|
echo
|
||||||
while true; do
|
while true; do
|
||||||
read -r -p "$(echo -e "${YELLOW}Enter choice [1/2/3]: ${NC}")" choice
|
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
|
case "$choice" in
|
||||||
1) DEPLOY_TYPES+=("docker"); break ;;
|
1) DEPLOY_TYPES+=("docker"); break ;;
|
||||||
2) DEPLOY_TYPES+=("native"); break ;;
|
2) DEPLOY_TYPES+=("native"); break ;;
|
||||||
|
|
@ -126,26 +131,28 @@ elif [[ -t 0 ]]; then
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
|
else
|
||||||
# Priority 3: piped (non-interactive) — default to both for backward compatibility
|
# Fully headless — default to both
|
||||||
else
|
|
||||||
DEPLOY_TYPES+=("docker" "native")
|
DEPLOY_TYPES+=("docker" "native")
|
||||||
echo -e "${CYAN}Non-interactive run: downloading BOTH deployment types.${NC}"
|
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}"
|
echo -e "${YELLOW}To download only one type, set DEPLOYMENT_TYPE=docker or DEPLOYMENT_TYPE=native${NC}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Download shared library (required by all deployment scripts)
|
# Download archive once, then copy only the selected folders
|
||||||
|
echo
|
||||||
mkdir -p "deploy"
|
mkdir -p "deploy"
|
||||||
download_file "${GIT_BASE}common/wallarm-lib.sh" "deploy/wallarm-lib.sh" "shared library (deploy/wallarm-lib.sh)"
|
download_archive
|
||||||
|
|
||||||
# Download the selected deployment type(s)
|
|
||||||
for type in "${DEPLOY_TYPES[@]}"; do
|
for type in "${DEPLOY_TYPES[@]}"; do
|
||||||
download_deployment_type "$type"
|
deploy_type "$type"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Clean exit trap removes temp dir
|
||||||
|
|
||||||
# Patch library sourcing path for flat deploy/ structure
|
# Patch library sourcing path for flat deploy/ structure
|
||||||
# (needed until the source scripts in the repo are updated)
|
# (repo scripts still reference ../common/ — fix until they're updated)
|
||||||
for script in deploy/*.sh; do
|
for script in deploy/*.sh; do
|
||||||
[[ "$script" == "deploy/wallarm-lib.sh" ]] && continue
|
[[ "$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|source "\$SCRIPT_DIR/\.\./common/wallarm-lib\.sh"|source "$SCRIPT_DIR/wallarm-lib.sh"|' "$script"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue