#!/bin/sh . ./.env || { echo ".env file not found or failed to load" exit 1 } SCRIPT_DIR=$(cd "$(dirname "$0")" 2>/dev/null && pwd) DIR="$SCRIPT_DIR/$DIR" setup() { mkdir -p "$DIR" command -v wget >/dev/null 2>&1 \ || command -v curl >/dev/null 2>&1 \ || { echo "Error: neither wget nor curl is installed." echo "Please install wget or curl." exit 1 } } fetch_pk3() { SRC_URL="$1" echo "Source: $SRC_URL" command -v wget >/dev/null 2>&1 \ && wget -nc -nd -r -l1 --no-parent -A '*.pk3' -P "$DIR" "$SRC_URL" \ && return echo "wget not available, using curl..." curl -s "$SRC_URL" \ | grep '\.pk3"' \ | cut -d'"' -f2 \ | while read -r f; do TARGET="$DIR/$f" [ -s "$TARGET" ] && echo "✓ exists: $f" && continue echo "↓ downloading: $f" curl -s -o "$TARGET" "$SRC_URL/$f" done } game() { echo "Fetching base game pk3 files..." fetch_pk3 "$URL" } maps() { echo "Fetching baseq3 pk3 files (maps + base)..." fetch_pk3 "$MAP_URL" } main() { setup game maps echo "All pk3 files fetched into $DIR" } main