forked from dwurf/docker-kf2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_kf2.sh
175 lines (147 loc) · 6 KB
/
start_kf2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env bash
cd /home/steam/kf2server || exit 1
STEAM_UID=${PUID:=1000}
STEAM_GID=${PGID:=1000}
log() {
PREFIX="[Killing Floor 2][steam]"
printf "%-16s: %s\n" "${PREFIX}" "$1"
}
line() {
log "###########################################################################"
}
initialize() {
line
log "Killing Floor 2 Server - $(date)"
log "STEAM_UID ${STEAM_UID} - STEAM_GUID ${STEAM_GID}"
log "$1"
line
}
log "Variables loaded..."
log "Port: ${KF_PORT}"
log "Name: ${KF_SERVER_NAME}"
log "Mode: ${KF_GAME_MODE}"
log "Length: ${KF_GAME_LENGTH}"
log "Difficulty: ${KF_DIFFICULTY}"
log "Password: (REDACTED)"
log "Running Install... (be patient, 16 GB+)"
# Install server using steamcmd
if [[ ! -f "/home/steam/kf2server/Binaries/Win64/KFGameSteamServer.bin.x86_64" ]]; then
cd "/home/steam/steamcmd" || exit 1
steamcmd="./steamcmd.sh"
steamcmd+=" +force_install_dir /home/steam/kf2server"
steamcmd+=" +login anonymous"
steamcmd+=" +app_update 232130"
[[ "${KF_ENABLE_BETA}" == "true" ]] && steamcmd+=" -beta preview"
[[ "${KF_UPDATE_SERVER}" == "true" ]] && steamcmd+=" update"
steamcmd+=" validate"
steamcmd+=" +exit"
eval $steamcmd
else
log "Skipping install process, looks like kf2server is already installed"
fi
cp --force /home/steam/steamcmd/linux64/steamclient.so /home/steam/kf2server/Binaries/Win64/lib64/steamclient.so
cp --force /home/steam/steamcmd/linux64/steamclient.so /home/steam/kf2server/linux64/steamclient.so
cp --force /home/steam/steamcmd/linux64/steamclient.so /home/steam/kf2server/steamclient.so
# Generate configuration files
if [[ ! -f "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" ]]; then
log "It appears the config file is missing, generating..."
"/home/steam/kf2server/Binaries/Win64/KFGameSteamServer.bin.x86_64" kf-bioticslab?difficulty=0?adminpassword=secret?gamepassword=secret -port=7777 &
sleep 20
KFPID=$(pgrep -f port=7777)
kill "${KFPID}"
log "Configuration files generated"
fi
# Install KF2ServerToolCMD
if [[ ! -f "/home/steam/kf2server/KF2ServerToolCMD" ]]; then
log "Downloading KF2ServerToolCMD..."
wget --quiet "https://github.com/darkdks/KF2ServerTool/raw/master/code/KF2ServerToolCMD" -O "/usr/local/bin/KF2ServerToolCMD"
chmod +x "/usr/local/bin/KF2ServerToolCMD"
log "KF2ServerToolCMD has been download"
else
if [[ ! -f "/home/steam/kf2server/KFServerToolCMD.ini" ]]; then
log "It appears the KFServerToolCMD.ini is missing, generating..."
cd "/home/steam/kf2server" || exit 1
KF2ServerToolCMD -list
crudini --set --existing "KFServerToolCMD.ini" PATHS SteamCmdTool "/home/steam/steamcmd/steamcmd.sh"
log "KF2ServerToolCMD.ini has been generated"
fi
fi
# Update configuration files
if [[ -f "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" ]] ||
[[ -f "/home/steam/kf2server/KFGame/Config/LinuxServer-KFEngine.ini" ]] ||
[[ -f "/home/steam/kf2server/KFGame/Config/LinuxServer-KFWeb.ini" ]]; then
log "Updating configuration files..."
if [[ "${KF_GAME_MODE}" == 'VersusSurvival' ]]; then
KF_GAME_MODE='VersusSurvival?maxplayers=12';
fi
# Get game length
case "${KF_GAME_LENGTH}" in
Short)
KF_GAME_LENGTH_INT=0
;;
Normal)
KF_GAME_LENGTH_INT=1
;;
Long)
KF_GAME_LENGTH_INT=2
;;
*)
log "Unknown game length value. Exiting.."
exit 1
esac
# Get difficulty
case "${KF_DIFFICULTY}" in
Normal)
KF_DIFFICULTY_INT=0
;;
Hard)
KF_DIFFICULTY_INT=1
;;
Suicidal)
KF_DIFFICULTY_INT=2
;;
HellOnEarth)
KF_DIFFICULTY_INT=3
;;
*)
log "Unknown difficulty value. Exiting.."
exit 1
esac
# default to $(($KF_PORT + 19238))
[[ -z "${KF_QUERY_PORT}" ]] && export KF_QUERY_PORT="$((KF_PORT + 19238))"
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" KFGame.KFGameInfo GameLength "${KF_GAME_LENGTH_INT}"
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" Engine.GameReplicationInfo ServerName "${KF_SERVER_NAME}"
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" KFGame.KFGameInfo BannerLink "${KF_BANNER_LINK}"
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" KFGame.KFGameInfo ServerMOTD "${KF_MOTD}"
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFGame.ini" KFGame.KFGameInfo WebsiteLink "${KF_WEBSITE_LINK}"
crudini --set --existing "/home/steam/kf2server/KFGame/Config/KFWeb.ini" IpDrv.WebServer bEnabled "${KF_ENABLE_WEB}"
# remove both existing DownloadManagers parameters
crudini --del "/home/steam/kf2server/KFGame/Config/LinuxServer-KFEngine.ini" IpDrv.TcpNetDriver DownloadManagers
crudini --set "/home/steam/kf2server/KFGame/Config/LinuxServer-KFEngine.ini" IpDrv.TcpNetDriver DownloadManagers OnlineSubsystemSteamworks.SteamWorkshopDownload
if [[ "${KF_DISABLE_TAKEOVER}" == 'true' ]]; then
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFEngine.ini" Engine.GameEngine bUsedForTakeover "FALSE"
else
crudini --set --existing "/home/steam/kf2server/KFGame/Config/LinuxServer-KFEngine.ini" Engine.GameEngine bUsedForTakeover "TRUE"
fi
log "All configuration files have been updated"
# Install MaxPlayer mutator mod
cd "/home/steam/kf2server" || exit 1
KF2ServerToolCMD -addmod "2143104493" -ig
else
log "One or several configuration files are not present. Exiting.."
exit 1
fi
line
log "Launching the server"
export WINEDEBUG=fixme-all
cmd="/home/steam/kf2server/Binaries/Win64/KFGameSteamServer.bin.x86_64 "
cmd+="${KF_MAP}?Game=KFGameContent.KFGameInfo_${KF_GAME_MODE}"
cmd+="?Difficulty=${KF_DIFFICULTY_INT}"
cmd+="?AdminPassword=${KF_ADMIN_PASS}"
[[ -z "${MULTIHOME_IP}" ]] || cmd+="?Multihome=${MULTIHOME_IP}"
[[ -z "${KF_MUTATORS}" ]] || cmd+="?Mutator=${KF_MUTATORS}"
[[ -z "${KF_GAME_PASS}" ]] || cmd+="?GamePassword=${KF_GAME_PASS}"
cmd+=" -Port=${KF_PORT}"
cmd+=" -WebAdminPort=${KF_WEBADMIN_PORT}"
cmd+=" -QueryPort=${KF_QUERY_PORT}"
exec $cmd