From ee49ab9ea93947e3e78c2fd2565bf1e28cddb7b0 Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Thu, 29 Jan 2026 01:01:05 +0100 Subject: Rewrite fetchpk3 script This commit makes the fetchpk3 script more bulletproof. The logic was separated into functions with proper sanity checks. The script now downloads also the custom map files. I plan on adding another script that will copy/move the maps into the /var/www/xyz folder, so players could actually use their autodownload. Remove redundant server.cfg My servers will only run modded version of quake3 so there is no need for vanilla config Signed-off-by: Filip Wandzio --- fetchpk3.sh | 60 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'fetchpk3.sh') diff --git a/fetchpk3.sh b/fetchpk3.sh index 7c2394e..fae9520 100755 --- a/fetchpk3.sh +++ b/fetchpk3.sh @@ -5,15 +5,53 @@ exit 1 } -mkdir -p "$DIR" - -wget -nc -nd -r -l1 --no-parent -A '*.pk3' -P "$DIR" "$URL" \ -|| { - echo "wget not present, fallback to curl..." - curl -s "$URL" \ - | grep -o 'href="[^"]*\.pk3"' \ - | cut -d'"' -f2 \ - | while read -r f; do - [ -f "$DIR/$f" ] || curl -# -o "$DIR/$f" "$URL/$f" - done +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 -- cgit v1.2.3