Skip to content

Instantly share code, notes, and snippets.

@CanadianJeff
Last active March 7, 2021 23:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CanadianJeff/c62182bf57dfc0f4ef4a105f1ea6db7f to your computer and use it in GitHub Desktop.
Save CanadianJeff/c62182bf57dfc0f4ef4a105f1ea6db7f to your computer and use it in GitHub Desktop.
Starting a SRCDS Server From Shell
#!/usr/bin/env bash
export NCURSES_NO_UTF8_ACS=1
## Variables
conport=27016
wsid=1552032032
maxplayers=25
steampath="/opt/steam"
TERMINAL="/dev/tty"
HEIGHT=20
WIDTH=115
CHOICE_HEIGHT=15
BACKTITLE=""
TITLE=""
## Functions
menu()
{
MENU="Choose "
MENU+="$1"
}
## Library Path
LD_LIBRARY_PATH="$steampath/linux32/i386-linux-gnu:$steampath/linux64:$steampath/linux32"
gen_menu()
{
(( i=0 )) #Index counter for adding to array
while read -r line;
do
(( i++ ))
array+=("$i" "$line")
done < <(find "$1" -type f -name "$2")
gen_dialog
}
gen_dialog()
{
choices=$(dialog \
--nocancel \
--no-lines \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${array[@]}" \
3>&1 1>&2 2>&3 )
choices=${array[2*choices - 1]}
#clear
}
declare -a array=()
TITLE="SRCDS SERVER BIN"
menu "one of the following options:"
gen_menu "$steampath" "srcds_run"
BIN="$choices"
if [ -n "$BIN" ]; then
echo "you have picked: $BIN"
else
echo "No Server Selected, Good Bye!"
exit 1
fi
game_path="$(dirname "$BIN")"
declare -A maps=(); choices=();
array=();
(( i=0 )) #Index counter for adding to array
while IFS= read -rd '' file; do
base=${file##*/}
maps[$base]=$file
(( i++ ))
array+=("$i" "$file")
done < <(find "$game_path" -path "*/maps/*" -name "*.bsp" -print0 | sort -z)
TITLE="CHOOSE A MAP?"
menu "one of the following options:"
gen_dialog
map=$(basename "$choices")
## Final EXE :)
set -x
LD_LIBRARY_PATH="$LD_LIBRARY_PATH" \
"$BIN" \
-netconport $conport \
-norestart \
+host_workshop_collection $wsid \
+maxplayers $maxplayers \
+map "$map" \
1>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment