2019-07-21 23:04:00 +02:00
#!/bin/bash
if [ " ${ DEBUGGING } " = "true" ] ; then
set -o xtrace
fi
set -o errexit
set -o nounset
set -o pipefail
2019-10-15 14:32:24 +02:00
CFG_PATH = " ${ SERVER_PATH } /garrysmod/cfg/gmodserver.cfg "
2019-07-21 23:04:00 +02:00
function configReplace( ) {
source = " $1 "
2020-09-27 20:46:33 +02:00
target = " \" $2 \" "
2023-11-30 14:17:29 +01:00
2023-12-04 11:49:55 +01:00
if ! echo " $2 " | grep -qe " ^[a-zA-Z0-9_ -]* $" ; then
2023-11-30 14:17:29 +01:00
echo " [initConfig.sh]Warning your configured value for $source doesn't match regex ^[a-zA-Z0-9_-]+ $. Special symbols could crash this script because they are not sanitized. "
fi
2019-07-21 23:04:00 +02:00
2023-11-30 14:05:43 +01:00
count = $( grep -Poc " ( $source ).+ " " ${ CFG_PATH } " || echo 0)
2019-07-21 23:04:00 +02:00
2019-10-15 14:32:24 +02:00
echo " [initConfig.sh]Request for replacing $source to $target , source is found $count times "
2019-07-21 23:04:00 +02:00
if [ " $count " = = "1" ] ; then
2020-09-27 21:32:03 +02:00
sed -Ei " / ${ source } .*/d " " ${ CFG_PATH } "
2020-10-12 22:39:42 +02:00
echo " $source $target " >> " ${ CFG_PATH } "
2019-07-21 23:04:00 +02:00
elif [ " $count " = = "0" ] ; then
2019-10-15 14:32:24 +02:00
echo "" >> " ${ CFG_PATH } "
2020-10-12 22:39:42 +02:00
echo " $source $target " >> " ${ CFG_PATH } "
2019-07-21 23:04:00 +02:00
else
2019-10-15 14:32:24 +02:00
echo " [initConfig.sh]can't set $1 because there are multiple in "
2019-07-21 23:04:00 +02:00
fi
}
#create default server.config
# not empty: grep -q '[^[:space:]]' < 'server.cfg' && echo "not empty"
2019-10-15 14:32:24 +02:00
if [ ! -e " ${ CFG_PATH } " ] || [ "0" = " $( grep -oc '[^[:space:]]' " ${ CFG_PATH } " ) " ] ; then
2019-07-21 23:04:00 +02:00
mkdir -p " ${ SERVER_PATH } /garrysmod/cfg " || true
2019-10-15 14:32:24 +02:00
cp -f "/home/server.cfg.default" " ${ CFG_PATH } "
chown " $USER_ID : $GROUP_ID " " ${ CFG_PATH } "
chmod u+rw " ${ CFG_PATH } "
2019-07-21 23:04:00 +02:00
fi
2019-10-15 14:32:24 +02:00
# set hostname & password, working if only one entry is in
2019-07-21 23:04:00 +02:00
if [ -n " ${ SERVER_NAME } " ] ; then
configReplace "hostname" " $SERVER_NAME "
fi
if [ -n " ${ SERVER_PASSWORD } " ] ; then
configReplace "sv_password" " $SERVER_PASSWORD "
fi
2019-10-15 14:56:24 +02:00
if [ -n " ${ SERVER_RCON_PASSWORD } " ] ; then
configReplace "rcon_password" " $SERVER_RCON_PASSWORD "
fi
2019-07-21 23:04:00 +02:00
if [ -n " ${ SERVER_VOICE_ENABLE } " ] ; then
configReplace "sv_voiceenable" " $SERVER_VOICE_ENABLE "
2019-10-17 00:35:49 +02:00
fi