Files
UT99-Official/DoConfig.sh
2022-05-18 21:26:21 +00:00

206 lines
5.0 KiB
Bash
Executable File

#/bin/bash
OUTPUT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
CFG_FILE=
DEFAULT_CFG_FILE=UnrealTournament.ini
function add_iniKey() {
crudini --set $OUTPUT_DIR/System/$CFG_FILE $1 __$2 $3
# Warning: ugly hack with sed to allow multiple key instances + to remove space around '='
sed -i "s/[[:space:]]*__$2[[:space:]]*=[[:space:]]*/$2=/g" $OUTPUT_DIR/System/$CFG_FILE
}
function update_iniKey() {
crudini --set $OUTPUT_DIR/System/$CFG_FILE $1 $2 $3
# Warning: ugly hack with sed to remove space around '='
sed -i "s/[[:space:]]*$2[[:space:]]*=[[:space:]]*/$2=/g" $OUTPUT_DIR/System/$CFG_FILE
}
# !!Warning!! section is not considered
function del_iniKey() {
sed -i "/[[:space:]]*$2[[:space:]]*=[[:space:]]*$3/d" $OUTPUT_DIR/System/$CFG_FILE
}
function setPort() {
echo "setting Port to $1"
update_iniKey 'URL' 'Port' $1
}
function setMap() {
echo "setting Map to $1"
update_iniKey 'URL' 'Map' $1
}
function setDefaultServerGame() {
echo "setting DefaultServerGame to $1"
update_iniKey 'Engine.Engine' 'DefaultServerGame' $1
}
function setHostName() {
echo "setting HostName to $1"
update_iniKey 'Engine.GameReplicationInfo' 'ServerName' $1
update_iniKey 'Engine.GameReplicationInfo' 'ShortName' $1
}
function setAdminEmail() {
echo "setting AdminEmail to $1"
update_iniKey 'Engine.GameReplicationInfo' 'AdminEmail' $1
}
function setAdminName() {
echo "setting AdminName to $1"
update_iniKey 'Engine.GameReplicationInfo' 'AdminName' $1
update_iniKey 'UTServerAdmin.UTServerAdmin' 'AdminUsername' $1
}
function setMOTD1() {
echo "setting MOTD1 to $1"
update_iniKey 'Engine.GameReplicationInfo' 'MOTDLine1' $1
}
function setMOTD2() {
echo "setting host MOTD2 $1"
update_iniKey 'Engine.GameReplicationInfo' 'MOTDLine2' $1
}
function setHTTPDownloadServer() {
echo "setting HTTP Download server to $1"
update_iniKey 'IpDrv.HTTPDownload' 'RedirectToURL' $1
update_iniKey 'IpDrv.HTTPDownload' 'UseCompression' True
del_iniKey 'IpDrv.HTTPDownload' 'ProxyServerHost'
del_iniKey 'IpDrv.HTTPDownload' 'ProxyServerPort'
}
function setNetServerMaxTickRate() {
echo "setting NetServerMaxTickRate $1"
update_iniKey 'IpDrv.TcpNetDriver' 'NetServerMaxTickRate' $1
}
function setLanServerMaxTickRate() {
echo "setting LanServerMaxTickRate $1"
update_iniKey 'IpDrv.TcpNetDriver' 'LanServerMaxTickRate' $1
}
function setAdminPassword() {
echo "setting AdminPassword $1"
update_iniKey 'Engine.GameInfo' 'AdminPassword' $1
update_iniKey 'UTServerAdmin.UTServerAdmin' 'AdminPassword' $1
}
function setGamePassword() {
echo "setting GamePassword $1"
update_iniKey 'Engine.GameInfo' 'GamePassword' $1
}
function setMaxPlayers() {
echo "setting MaxPlayers $1"
update_iniKey 'Engine.GameInfo' 'MaxPlayers' $1
}
function setServerLogName() {
echo "setting ServerLogName $1"
update_iniKey 'Engine.GameInfo' 'ServerLogName' $1
}
function enableWebServer() {
echo "enabling WebServer on port $1"
update_iniKey 'UWeb.WebServer' 'ListenPort' $1
update_iniKey 'UWeb.WebServer' 'bEnabled' True
}
function show_help() {
echo
echo "Usage: $0 { setHostName } [<OPT_1>] [<OPT_2>] [<OPT_X>] ..."
echo
}
function check_cfg_file() {
if [ -z ${CFG_FILE} ]
then
echo "CFG_FILE is unset, setting it to $DEFAULT_CFG_FILE"
CFG_FILE=$DEFAULT_CFG_FILE
else
echo "CFG_FILE is set to '$CFG_FILE'"
fi
if [ ! -f $OUTPUT_DIR/System/$CFG_FILE ]
then
echo "$OUTPUT_DIR/System/$CFG_FILE does not exist"
show_help
exit 9999 # die with error code 9999
fi
}
case "$1" in
'enableWebServer')
check_cfg_file
enableWebServer $2
;;
'setGamePassword')
check_cfg_file
setGamePassword $2
;;
'setMaxPlayers')
check_cfg_file
setMaxPlayers $2
;;
'setServerLogName')
check_cfg_file
setServerLogName $2
;;
'setAdminPassword')
check_cfg_file
setAdminPassword $2
;;
'setNetServerMaxTickRate')
check_cfg_file
setNetServerMaxTickRate $2
;;
'setLanServerMaxTickRate')
check_cfg_file
setLanServerMaxTickRate $2
;;
'setDefaultServerGame')
check_cfg_file
setDefaultServerGame $2
;;
'setPort')
check_cfg_file
setPort $2
;;
'setMap')
check_cfg_file
setMap $2
;;
'setHostName')
check_cfg_file
setHostName $2
;;
'setAdminEmail')
check_cfg_file
setAdminEmail $2
;;
'setAdminName')
check_cfg_file
setAdminName $2
;;
'setMOTD1')
check_cfg_file
setMOTD1 $2
;;
'setMOTD2')
check_cfg_file
setMOTD2 $2
;;
'setHTTPDownloadServer')
check_cfg_file
setHTTPDownloadServer $2
;;
*)
show_help
exit 1
;;
esac
exit 0