scraketools

administrative aid for hosting multiple Killing Floor 1 dedicated servers
git clone git://git.boymiasma.net/scraketools
Log | Files | Refs | README

commit 84216d86cb683bcb8c0a9f8dd05f45feea64f765
parent f68c36a9a0f55ac07dc7faa92b1e7218850477ac
Author: giygas <giygas@boymiasma.net>
Date:   Sun, 12 Oct 2025 23:43:40 +0200

Command-line interface, bugfixes

Diffstat:
Mscrake.sh | 74++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 36 insertions(+), 38 deletions(-)

diff --git a/scrake.sh b/scrake.sh @@ -19,7 +19,7 @@ fatal() { clean() { if [ -e "$FIRSTRUN_FIFO" ]; then rm "$FIRSTRUN_FIFO" 2>&-; fi } -trap "clean" TERM INT +trap "clean" EXIT TERM INT init_paths() { if [ ! -d "$STEAM_ROOT" ]; then @@ -33,14 +33,17 @@ init_paths() { fi if [ ! -d "$SCRAKE_ROOT" ]; then - mkdir -p "$SCRAKE_ROOT" || exit 1 - mkdir "$SCRAKE_ROOT/"{Servers,Mutators,Maps} || exit 1 + mkdir $VERBOSE -p "$SCRAKE_ROOT" || exit 1 + mkdir $VERBOSE "$SCRAKE_ROOT/"{Servers,Mutators,Maps} || exit 1 fi + + if [ ! -f "$SCRAKE_CFG" ]; then echo "[Scrake]" >"$SCRAKE_CFG"; fi } # Usage: init_base username [path] init_base() { typeset STEAM_LOGIN PID + if [ "$1" == "-N" ]; then NO_FIRSTRUN=1; shift; fi if [ $# -lt 1 ] || [ $# -gt 2 ]; then fatal "usage: init_base username [path]"; fi if [ -e "$FIRSTRUN_FIFO" ]; then fatal "init_base: '$FIRSTRUN_FIFO' exists"; fi STEAM_LOGIN="$1" @@ -58,13 +61,15 @@ init_base() { SCRAKE_BASE="$INSTALL_DIR" fi + if [ ! -z "$NO_FIRSTRUN" ]; then exit; fi + notify "init_base: allowing the server to run once to initialise the default configuration (this will take a second)" mkfifo "$FIRSTRUN_FIFO" run_server "$SCRAKE_BASE" server KF-Forgotten?game=KFmod.KFGameType -nohomedir >"$FIRSTRUN_FIFO" & PID=$! notify "init_base: first-run pid: $PID" cat "$FIRSTRUN_FIFO" | while read -r LINE; do - echo "$LINE" + if [ ! -z "$VERBOSE" ]; then echo "$LINE"; fi if echo "$LINE" | grep -q '^Webserver is not enabled.'; then kill -9 "$PID" break @@ -128,7 +133,7 @@ new_instance() { done } -usage_mod_instance() { echo "mod_instance instance [map|mutator] [add|remove] component"; } +usage_mod_instance() { echo "mod_instance instance [map|mutator] [add|remove] component ..."; } mod_instance() { typeset TARGET WHAT ACTION SRC DST if [ $# -lt 3 ]; then fatal "$(usage_mod_instance)"; exit 1; fi @@ -175,11 +180,10 @@ inimerge() { -f <(sed -n '/^## begin inimerge.awk/,$p' "$0") } -# usage: sync_cfg inifile instance_name ..." +usage_sync_instance() { echo "usage: sync_cfg instance_name ..."; } sync_cfg() { - typeset DST INIFILE - if [ "$#" -lt 2 ]; then fatal "usage: sync_cfg inifile instance_name ..."; fi - INIFILE="$1"; shift + typeset DST + if [ "$#" -lt 1 ]; then fatal "$(usage_sync_instance)"; fi while [ "$#" -ge 1 ]; do DST="$(realpath "$SCRAKE_ROOT/Servers/$1")" @@ -191,7 +195,7 @@ sync_cfg() { find "$DST" -name '*.ini.defaults' | while read FILE; do BASENAME="$(echo "$FILE" | sed 's/\.defaults$//')" notify "sync_cfg: applying overrides from '$1' to $BASENAME" - inimerge "$INIFILE" "$1" "$FILE" >"$BASENAME" + inimerge "$SCRAKE_CFG" "$1" "$FILE" >"$BASENAME" done shift @@ -219,24 +223,30 @@ run_instance() { usage_scrake() { cat <<EOF usage: - $PROGNAME [global-options] create instance_name + $PROGNAME [global-options] init [-N] steam_username [alt_install_dir] + $PROGNAME [global-options] create instance_name ... $PROGNAME [global-options] mod instance_name mutator add|remove mutname ... $PROGNAME [global-options] mod instance_name map add|remove mapname ... - $PROGNAME [global-options] sync [-i inifile] instance_name ... + $PROGNAME [global-options] sync cfg instance_name ... + $PROGNAME [global-options] sync bans instance_name ... + $PROGNAME [global-options] run instance_name map_name global options: -h show this help message -s alternative steam install directory (overrides STEAM_ROOT) -b alternative server base directory (overrides SCRAKE_BASE) -r alternative scrake root directory (overrides SCRAKE_ROOT) - -v verbose flag -sync options: -i alternative configuration override file (overrides SCRAKE_CFG) + -v verbose flag +init options: + -N do not perform the automatic server first-run EOF } -while getopts "b:hr:s:v" OPT; do +while getopts "b:i:Nhr:s:v" OPT; do case "$OPT" in b) SCRAKE_BASE="${OPTARG}";; h) usage_scrake; exit;; + i) SCRAKE_CFG="${OPTARG}";; + N) NO_FIRSTRUN=1;; r) SCRAKE_ROOT="${OPTARG}";; s) STEAM_ROOT="${OPTARG}";; v) VERBOSE="-v";; @@ -245,29 +255,15 @@ while getopts "b:hr:s:v" OPT; do done shift $((OPTIND-1)) -init_base "STEAMUSERNAME" -init_paths -new_instance "Normal" "Hard" "Suicidal" -mod_instance "Normal" mutator add "CustomServerDetails" "ReloadOptions" "MutKillMessage" -mod_instance "Hard" mutator add "CustomServerDetails" "ReloadOptions" "MutKillMessage" -mod_instance "Suicidal" mutator add "CustomServerDetails" "ReloadOptions" "MutKillMessage" -sync_cfg "$HOME/scrake.ini" "Normal" "Hard" "Suicidal" -run_instance "$1" "KF-Forgotten.rom" - -bullshit_debug() { - new_server T - mod_server "T" mutator add "CustomServerDetails" "ReloadOptions" "MutKillMessage" - mod_server "T" map add KF-Affairs KF-Awe KF-Headquarters - cd "$SCRAKE_ROOT/Servers/T" - echo "Inspect and ctrl+d when done.." - bash - mod_server "T" mutator remove "CustomServerDetails" "ReloadOptions" "MutKillMessage" - mod_server "T" map remove KF-Affairs KF-Awe KF-Headquarters - echo "Inspect and ctrl+d when done.." - bash - rm -r "$SCRAKE_ROOT/Servers/T" - echo "all done.." -} +VERB="$1"; shift +case "$VERB" in +init) init_base $*;; +create) init_paths; new_instance $*;; +mod) init_paths; mod_instance $*;; +sync) init_paths; sync_cfg $*;; +run) init_paths; run_instance $*;; +*) fatal "$(usage_scrake)";; +esac clean exit @@ -279,6 +275,8 @@ BEGIN { FS=IFS=OFS="=" while (getline <overrides) { split($1, parts, "/"); + for (i=3;i<=length(parts);i++) + parts[2]=parts[2] "/" parts[i] value=substr($0, length($1)+2) switch(parts[1]) {