Skip to content

Commit 658906e

Browse files
committed
feat(etl): add downloader and update support for ET: Legacy
Refactors ET: Legacy to use a dedicated update module instead of hardcoded installation files. The new update_etl.sh module leverages the GitHub API to check for, download, and apply the latest builds from GameServerManagers/etlserver-build.
1 parent 2a177a8 commit 658906e

File tree

4 files changed

+173
-8
lines changed

4 files changed

+173
-8
lines changed

lgsm/modules/command_check_update.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ elif [ "${shortname}" == "ut99" ]; then
3434
update_ut99.sh
3535
elif [ "${shortname}" == "xnt" ]; then
3636
update_xnt.sh
37+
elif [ "${shortname}" == "etl" ]; then
38+
update_etl.sh
3739
else
3840
update_steamcmd.sh
3941
fi

lgsm/modules/command_update.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ elif [ "${shortname}" == "ut99" ]; then
3535
update_ut99.sh
3636
elif [ "${shortname}" == "xnt" ]; then
3737
update_xnt.sh
38+
elif [ "${shortname}" == "etl" ]; then
39+
update_etl.sh
3840
else
3941
update_steamcmd.sh
4042
fi

lgsm/modules/install_server_files.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ fn_install_server_files() {
8080
run="norun"
8181
force="noforce"
8282
md5="2c6be1bb66ea631b9b2e7ae6216c6680"
83-
elif [ "${shortname}" == "etl" ]; then
84-
remote_fileurl="http://linuxgsm.download/WolfensteinEnemyTerritory/etlegacy-v2.78.1-i386-et-260b.tar.xz"
85-
local_filedir="${tmpdir}"
86-
local_filename="etlegacy-v2.78.1-i386-et-260b.tar.xz"
87-
chmodx="nochmodx"
88-
run="norun"
89-
force="noforce"
90-
md5="7c08b52cb09b30eadb98ea05ef780fc7"
9183
elif [ "${shortname}" == "mohaa" ]; then
9284
remote_fileurl="http://linuxgsm.download/MedalofHonorAlliedAssault/moh_revival_v1.12_RC3.5.1.tar.xz"
9385
local_filedir="${tmpdir}"
@@ -280,6 +272,8 @@ elif [ "${shortname}" == "ut99" ]; then
280272
update_ut99.sh
281273
elif [ "${shortname}" == "xnt" ]; then
282274
update_xnt.sh
275+
elif [ "${shortname}" == "etl" ]; then
276+
update_etl.sh
283277
elif [ -z "${appid}" ] || [ "${shortname}" == "ahl" ] || [ "${shortname}" == "bb" ] || [ "${shortname}" == "q4" ] || [ "${shortname}" == "ns" ] || [ "${shortname}" == "sfc" ] || [ "${shortname}" == "ts" ] || [ "${shortname}" == "vs" ] || [ "${shortname}" == "zmr" ]; then
284278
if [ "${shortname}" == "ut" ]; then
285279
install_eula.sh

lgsm/modules/update_etl.sh

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#!/bin/bash
2+
# LinuxGSM update_etl.sh module
3+
# Author: Daniel Gibbs
4+
# Contributors: https://linuxgsm.com/contrib
5+
# Website: https://linuxgsm.com
6+
# Description: Handles updating of ET: Legacy servers.
7+
8+
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
9+
10+
fn_update_dl() {
11+
# Download and extract files to serverfiles.
12+
fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "nochmodx" "norun" "force" "${remotebuildhash}"
13+
fn_dl_extract "${tmpdir}" "${remotebuildfilename}" "${serverfiles}"
14+
echo "${remotebuild}" > "${serverfiles}/build.txt"
15+
fn_clear_tmp
16+
}
17+
18+
fn_update_localbuild() {
19+
# Gets local build info.
20+
fn_print_dots "Checking local build: ${remotelocation}"
21+
# Uses build file to get local build.
22+
localbuild=$(head -n 1 "${serverfiles}/build.txt" 2> /dev/null)
23+
if [ -z "${localbuild}" ]; then
24+
fn_print_error "Checking local build: ${remotelocation}: missing local build info"
25+
fn_script_log_error "Missing local build info"
26+
fn_script_log_error "Set localbuild to 0"
27+
localbuild="0"
28+
else
29+
fn_print_ok "Checking local build: ${remotelocation}"
30+
fn_script_log_pass "Checking local build"
31+
fi
32+
}
33+
34+
fn_update_remotebuild() {
35+
# Gets remote build info.
36+
apiurl="https://api.github.com/repos/GameServerManagers/etlserver-build/releases/latest"
37+
remotebuildresponse=$(curl -s "${apiurl}")
38+
remotebuildfilename=$(echo "${remotebuildresponse}" | jq -r '.assets[] | select(.browser_download_url | contains("i386-et-260b")) | .name')
39+
remotebuildurl=$(echo "${remotebuildresponse}" | jq -r '.assets[] | select(.browser_download_url | contains("i386-et-260b")) | .browser_download_url')
40+
remotebuild=$(echo "${remotebuildresponse}" | jq -r '.tag_name')
41+
remotebuildhash=$(echo "${remotebuildresponse}" | jq -r '.body' | grep 'MD5' | awk '{print $NF}')
42+
43+
if [ "${firstcommandname}" != "INSTALL" ]; then
44+
fn_print_dots "Checking remote build: ${remotelocation}"
45+
# Checks if remotebuild variable has been set.
46+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
47+
fn_print_fail "Checking remote build: ${remotelocation}"
48+
fn_script_log_fail "Checking remote build"
49+
core_exit.sh
50+
else
51+
fn_print_ok "Checking remote build: ${remotelocation}"
52+
fn_script_log_pass "Checking remote build"
53+
fi
54+
else
55+
# Checks if remotebuild variable has been set.
56+
if [ -z "${remotebuild}" ] || [ "${remotebuild}" == "null" ]; then
57+
fn_print_failure "Unable to get remote build"
58+
fn_script_log_fail "Unable to get remote build"
59+
core_exit.sh
60+
fi
61+
fi
62+
}
63+
64+
fn_update_compare() {
65+
fn_print_dots "Checking for update: ${remotelocation}"
66+
# Update has been found or force update.
67+
if [ "${localbuild}" != "${remotebuild}" ] || [ "${forceupdate}" == "1" ]; then
68+
# Create update lockfile.
69+
date '+%s' > "${lockdir:?}/update.lock"
70+
fn_print_ok_nl "Checking for update: ${remotelocation}"
71+
fn_print "\n"
72+
fn_print_nl "${bold}${underline}Update${default} available"
73+
fn_print_nl "* Local build: ${red}${localbuild}${default}"
74+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
75+
if [ -n "${branch}" ]; then
76+
fn_print_nl "* Branch: ${branch}"
77+
fi
78+
if [ -f "${rootdir}/.dev-debug" ]; then
79+
fn_print_nl "Remote build info"
80+
fn_print_nl "* apiurl: ${apiurl}"
81+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
82+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
83+
fn_print_nl "* remotebuild: ${remotebuild}"
84+
fi
85+
fn_print "\n"
86+
fn_script_log_info "Update available"
87+
fn_script_log_info "Local build: ${localbuild}"
88+
fn_script_log_info "Remote build: ${remotebuild}"
89+
if [ -n "${branch}" ]; then
90+
fn_script_log_info "Branch: ${branch}"
91+
fi
92+
fn_script_log_info "${localbuild} > ${remotebuild}"
93+
94+
if [ "${commandname}" == "UPDATE" ]; then
95+
date +%s > "${lockdir:?}/last-updated.lock"
96+
unset updateonstart
97+
check_status.sh
98+
# If server stopped.
99+
if [ "${status}" == "0" ]; then
100+
fn_update_dl
101+
if [ "${localbuild}" == "0" ]; then
102+
exitbypass=1
103+
command_start.sh
104+
fn_firstcommand_reset
105+
exitbypass=1
106+
fn_sleep_time_5
107+
command_stop.sh
108+
fn_firstcommand_reset
109+
fi
110+
# If server started.
111+
else
112+
fn_print_restart_warning
113+
exitbypass=1
114+
command_stop.sh
115+
fn_firstcommand_reset
116+
exitbypass=1
117+
fn_update_dl
118+
exitbypass=1
119+
command_start.sh
120+
fn_firstcommand_reset
121+
fi
122+
unset exitbypass
123+
alert="update"
124+
elif [ "${commandname}" == "CHECK-UPDATE" ]; then
125+
alert="check-update"
126+
fi
127+
alert.sh
128+
else
129+
fn_print_ok_nl "Checking for update: ${remotelocation}"
130+
fn_print "\n"
131+
fn_print_nl "${bold}${underline}No update${default} available"
132+
fn_print_nl "* Local build: ${green}${localbuild}${default}"
133+
fn_print_nl "* Remote build: ${green}${remotebuild}${default}"
134+
if [ -n "${branch}" ]; then
135+
fn_print_nl "* Branch: ${branch}"
136+
fi
137+
fn_print "\n"
138+
fn_script_log_info "No update available"
139+
fn_script_log_info "Local build: ${localbuild}"
140+
fn_script_log_info "Remote build: ${remotebuild}"
141+
if [ -n "${branch}" ]; then
142+
fn_script_log_info "Branch: ${branch}"
143+
fi
144+
if [ -f "${rootdir}/.dev-debug" ]; then
145+
fn_print_nl "Remote build info"
146+
fn_print_nl "* apiurl: ${apiurl}"
147+
fn_print_nl "* remotebuildfilename: ${remotebuildfilename}"
148+
fn_print_nl "* remotebuildurl: ${remotebuildurl}"
149+
fn_print_nl "* remotebuild: ${remotebuild}"
150+
fi
151+
fi
152+
}
153+
154+
# The location where the builds are checked and downloaded.
155+
remotelocation="github.com"
156+
157+
if [ "${firstcommandname}" == "INSTALL" ]; then
158+
fn_update_remotebuild
159+
fn_update_dl
160+
else
161+
fn_print_dots "Checking for update"
162+
fn_print_dots "Checking for update: ${remotelocation}"
163+
fn_script_log_info "Checking for update: ${remotelocation}"
164+
fn_update_localbuild
165+
fn_update_remotebuild
166+
fn_update_compare
167+
fi

0 commit comments

Comments
 (0)