-
-
Notifications
You must be signed in to change notification settings - Fork 859
Expand file tree
/
Copy pathcommand_update_linuxgsm.sh
More file actions
222 lines (203 loc) · 9.7 KB
/
command_update_linuxgsm.sh
File metadata and controls
222 lines (203 loc) · 9.7 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
# LinuxGSM command_update_linuxgsm.sh module
# Author: Daniel Gibbs
# Contributors: http://linuxgsm.com/contrib
# Website: https://linuxgsm.com
# Description: Deletes the modules dir to allow re-downloading of modules from GitHub.
commandname="UPDATE-LGSM"
commandaction="Updating LinuxGSM"
moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_firstcommand_set
check.sh
info_distro.sh
fn_print_dots ""
fn_script_log_info "Updating LinuxGSM"
fn_repo_selector
fn_print_dots "Selecting repo"
fn_print_ok_nl "Selecting repo: ${remotereponame}"
fn_script_log_pass "Selecting repo: ${remotereponame}"
# Check linuxsm.sh
echo -en "checking ${remotereponame} linuxgsm.sh...\c"
if [ "${remotereponame}" == "GitHub" ]; then
curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh" 1> /dev/null
else
curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh" 1> /dev/null
fi
if [ $? != "0" ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "Checking ${remotereponame} linuxgsm.sh"
fn_script_log_fatal "Curl returned error: $?"
core_exit.sh
fi
if [ "${remotereponame}" == "GitHub" ]; then
tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/linuxgsm.sh"))
else
tmp_script_diff=$(diff "${tmpdir}/linuxgsm.sh" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/linuxgsm.sh"))
fi
if [ "${tmp_script_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_update "Checking ${remotereponame} linuxgsm.sh"
rm -f "${tmpdir:?}/linuxgsm.sh"
fn_fetch_file_github "" "linuxgsm.sh" "${tmpdir}" "nochmodx" "norun" "noforcedl" "nohash"
else
fn_print_ok_eol_nl
fn_script_log_pass "Checking ${remotereponame} linuxgsm.sh"
fi
# Check gameserver.sh
# Compare gameserver.sh against linuxgsm.sh in the tmp dir.
# Ignoring server specific vars.
echo -en "checking ${selfname}...\c"
fn_script_log_info "Checking ${selfname}"
script_diff=$(diff <(sed '\/shortname/d;\/gameservername/d;\/gamename/d;\/githubuser/d;\/githubrepo/d;\/githubbranch/d' "${tmpdir}/linuxgsm.sh") <(sed '\/shortname/d;\/gameservername/d;\/gamename/d;\/githubuser/d;\/githubrepo/d;\/githubbranch/d' "${rootdir}/${selfname}"))
if [ "${script_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_update "Checking ${selfname}"
echo -en "backup ${selfname}...\c"
fn_script_log_info "Backup ${selfname}"
if [ ! -d "${backupdir}/script" ]; then
mkdir -p "${backupdir}/script"
fi
cp "${rootdir}/${selfname}" "${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
if [ $? != 0 ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "Backup ${selfname}"
core_exit.sh
else
fn_print_ok_eol_nl
fn_script_log_pass "Backup ${selfname}"
echo -e "backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
fn_script_log_pass "Backup location ${backupdir}/script/${selfname}-$(date +"%m_%d_%Y_%M").bak"
fi
echo -en "copying ${selfname}...\c"
fn_script_log_info "copying ${selfname}"
cp "${tmpdir}/linuxgsm.sh" "${rootdir}/${selfname}"
sed -i "s+shortname=\"core\"+shortname=\"${shortname}\"+g" "${rootdir}/${selfname}"
sed -i "s+gameservername=\"core\"+gameservername=\"${gameservername}\"+g" "${rootdir}/${selfname}"
sed -i "s+gamename=\"core\"+gamename=\"${gamename}\"+g" "${rootdir}/${selfname}"
sed -i "s+githubuser=\"GameServerManagers\"+githubuser=\"${githubuser}\"+g" "${rootdir}/${selfname}"
sed -i "s+githubrepo=\"LinuxGSM\"+githubrepo=\"${githubrepo}\"+g" "${rootdir}/${selfname}"
sed -i "s+githubbranch=\"master\"+githubbranch=\"${githubbranch}\"+g;q" "${rootdir}/${selfname}"
if [ $? != "0" ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "copying ${selfname}"
core_exit.sh
else
fn_print_ok_eol_nl
fn_script_log_pass "copying ${selfname}"
fi
else
fn_print_ok_eol_nl
fn_script_log_info "Checking ${selfname}"
fi
# Check _default.cfg.
echo -en "checking ${remotereponame} config _default.cfg...\c"
fn_script_log_info "Checking ${remotereponame} config _default.cfg"
if [ "${remotereponame}" == "GitHub" ]; then
curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1> /dev/null
else
curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg" 1> /dev/null
fi
if [ $? != "0" ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "Checking ${remotereponame} config _default.cfg"
fn_script_log_fatal "Curl returned error: $?"
core_exit.sh
fi
if [ "${remotereponame}" == "GitHub" ]; then
config_file_diff=$(diff "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg"))
else
config_file_diff=$(diff "${configdirdefault}/config-lgsm/${gameservername}/_default.cfg" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/config-default/config-lgsm/${gameservername}/_default.cfg"))
fi
if [ "${config_file_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_update "Checking ${remotereponame} config _default.cfg"
rm -f "${configdirdefault:?}/config-lgsm/${gameservername:?}/_default.cfg"
fn_fetch_file_github "lgsm/config-default/config-lgsm/${gameservername}" "_default.cfg" "${configdirdefault}/config-lgsm/${gameservername}" "nochmodx" "norun" "noforce" "nohash"
alert="config"
alert.sh
else
fn_print_ok_eol_nl
fn_script_log_pass "Checking ${remotereponame} config _default.cfg"
fi
# Check distro csv. ${datadir}/${distroid}-${distroversioncsv}.csv
if [ -f "${datadir}/${distroid}-${distroversioncsv}.csv" ]; then
echo -en "checking ${remotereponame} config ${distroid}-${distroversioncsv}.csv...\c"
fn_script_log_info "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
if [ "${remotereponame}" == "GitHub" ]; then
curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv" 1> /dev/null
else
curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv" 1> /dev/null
fi
if [ $? != "0" ]; then
fn_print_fail_eol_nl
fn_script_log_fatal "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
fn_script_log_fatal "Curl returned error: $?"
core_exit.sh
fi
if [ "${remotereponame}" == "GitHub" ]; then
config_file_diff=$(diff "${datadir}/${distroid}-${distroversioncsv}.csv" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv"))
else
config_file_diff=$(diff "${datadir}/${distroid}-${distroversioncsv}.csv" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/lgsm/data/${distroid}-${distroversioncsv}.csv"))
fi
if [ "${config_file_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_update "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
rm -f "${datadir:?}/${distroid}-${distroversioncsv}.csv"
fn_fetch_file_github "lgsm/data" "${distroid}-${distroversioncsv}.csv" "${datadir}" "nochmodx" "norun" "noforce" "nohash"
else
fn_print_ok_eol_nl
fn_script_log_pass "Checking ${remotereponame} ${distroid}-${distroversioncsv}.csv"
fi
fi
# Check and update modules.
if [ -n "${modulesdir}" ]; then
if [ -d "${modulesdir}" ]; then
(
cd "${modulesdir}" || exit
for modulefile in *; do
# check if module exists in the repo and remove if missing.
# commonly used if module names change.
echo -en "checking ${remotereponame} module ${modulefile}...\c"
github_file_url_dir="lgsm/modules"
if [ "${remotereponame}" == "GitHub" ]; then
curl --connect-timeout 10 -IsfL "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${modulefile}" 1> /dev/null
else
curl --connect-timeout 10 -IsfL "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${modulefile}" 1> /dev/null
fi
if [ $? != 0 ]; then
fn_print_error_eol_nl
fn_script_log_error "Checking ${remotereponame} module ${modulefile}"
echo -en "removing module ${modulefile}...\c"
if ! rm -f "${modulefile:?}"; then
fn_print_fail_eol_nl
fn_script_log_fatal "Removing module ${modulefile}"
core_exit.sh
else
fn_print_ok_eol_nl
fn_script_log_pass "Removing module ${modulefile}"
fi
else
# compare file
if [ "${remotereponame}" == "GitHub" ]; then
module_file_diff=$(diff "${modulesdir}/${modulefile}" <(curl --connect-timeout 10 -s "https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${modulefile}"))
else
module_file_diff=$(diff "${modulesdir}/${modulefile}" <(curl --connect-timeout 10 -s "https://bitbucket.org/${githubuser}/${githubrepo}/raw/${githubbranch}/${github_file_url_dir}/${modulefile}"))
fi
# results
if [ "${module_file_diff}" != "" ]; then
fn_print_update_eol_nl
fn_script_log_update "Checking ${remotereponame} module ${modulefile}"
rm -rf "${modulesdir:?}/${modulefile}"
fn_update_module
else
fn_print_ok_eol_nl
fn_script_log_pass "Checking ${remotereponame} module ${modulefile}"
fi
fi
done
)
fi
fi
fn_print_ok_nl "Updating modules"
fn_script_log_pass "Updating modules"
core_exit.sh