forked from easy-wi/server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdates.sh
262 lines (193 loc) · 8.13 KB
/
updates.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/bin/bash
# Author: Ulrich Block <[email protected]>
#
# This file is part of Easy-WI.
#
# Easy-WI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Easy-WI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Easy-WI. If not, see <http://www.gnu.org/licenses/>.
#
# Diese Datei ist Teil von Easy-WI.
#
# Easy-WI ist Freie Software: Sie koennen es unter den Bedingungen
# der GNU General Public License, wie von der Free Software Foundation,
# Version 3 der Lizenz oder (nach Ihrer Wahl) jeder spaeteren
# veroeffentlichten Version, weiterverbreiten und/oder modifizieren.
#
# Easy-WI wird in der Hoffnung, dass es nuetzlich sein wird, aber
# OHNE JEDE GEWAEHELEISTUNG, bereitgestellt; sogar ohne die implizite
# Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK.
# Siehe die GNU General Public License fuer weitere Details.
#
# Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
# Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
#
############################################
# Moegliche Cronjob Konfiguration
# 25 1 * * * cd ~/ && ./updates.sh mta
# 25 1 * * * cd ~/ && ./updates.sh mms
# 25 1 * * * cd ~/ && ./updates.sh sm
# 15 */1 * * * cd ~/ && ./updates.sh mms_snapshot
# 15 */1 * * * cd ~/ && ./updates.sh mms_dev
# 15 */1 * * * cd ~/ && ./updates.sh sm_snapshot
# 15 */1 * * * cd ~/ && ./updates.sh sm_dev
function greenMessage {
echo -e "\\033[32;1m${@}\033[0m"
}
function cyanMessage {
echo -e "\\033[36;1m${@}\033[0m"
}
function checkCreateVersionFile {
if [ ! -f "$HOME/versions/$1" ]; then
touch "$HOME/versions/$1"
fi
}
function checkCreateFolder {
if [ ! -d "$1" -a "$1" != "" ]; then
mkdir -p "$1"
fi
}
function removeFile {
if [ -f "$1" ]; then
rm -f "$1"
fi
}
function downloadExtractFile {
checkCreateFolder "$HOME/$4/$1/"
cd "$HOME/$4/$1/"
removeFile "$2"
wget "$3"
if [ -f "$2" ]; then
if [[ `echo $2 | egrep -o 'samp[[:digit:]]{1,}svr.+'` ]]; then
tar xfv "$2" --strip-components=1
else
tar xfv "$2"
fi
rm -f "$2"
moveFilesFolders "$2" "$4" "$1"
find -type f ! -perm -750 -exec chmod 640 {} \;
find -type d -exec chmod 750 {} \;
fi
}
function moveFilesFolders {
FOLDER=`echo $1 | sed -r 's/.tar.gz//g'`
if [ "$FOLDER" != "" -a "" != "$2" -a "$3" != "" -a -d "$HOME/$2/$3/$FOLDER" ]; then
cd "$HOME/$2/$3/"
find "$FOLDER/" -mindepth 1 -type d | while read DIR; do
NEW_FODLER=${DIR/$FOLDER\//}
if [ ! -d "$HOME/$2/$3/$NEW_FODLER" ]; then
mkdir -p "$HOME/$2/$3/$NEW_FODLER"
fi
done
find "$FOLDER/" -type f | while read FILE; do
MOVE_TO=${FILE/$FOLDER\//.\/}
if [ "$MOVE_TO" != "" ]; then
mv "$FILE" "$MOVE_TO"
fi
done
rm -rf "$FOLDER"
fi
}
function update {
checkCreateVersionFile "$1"
FILE_NAME=`echo $2 | egrep -o '((sourcemod|mmsource|multitheftauto_linux|baseconfig)-[[:digit:]]|samp[[:digit:]]{1,}svr.+).*$' | tail -1`
LOCAL_VERSION=`cat $HOME/versions/$1 | tail -1`
CURRENT_VERSION=`echo $2 | egrep -o '((mmsource|sourcemod|multitheftauto_linux|baseconfig)-[0-9a-z.-]{1,}[0-9]|samp[[:digit:]]{1,}svr.+)' | tail -1`
if ([ "$CURRENT_VERSION" != "$LOCAL_VERSION" -o "$LOCAL_VERSION" == "" ] && [ "$CURRENT_VERSION" != "" ]); then
greenMessage "Updating $1 from $LOCAL_VERSION to $CURRENT_VERSION. Name of file is $FILE_NAME"
downloadExtractFile "$3" "$FILE_NAME" "$2" "$4"
echo "$CURRENT_VERSION" > "$HOME/versions/$1"
elif [ "$CURRENT_VERSION" == "" ]; then
cyanMessage "Could not detect current version for ${1}. Local version is $LOCAL_VERSION."
else
cyanMessage "${1} already up to date. Local version is $LOCAL_VERSION. Most recent version is $CURRENT_VERSION"
fi
}
function updatesAddonSnapshots {
if [ "$3" == "" ]; then
cyanMessage "Searching updates for $1 and revision $2"
else
cyanMessage "Searching snapshot updates for $1 ($3) and revision $2"
fi
if [ "$1" == "sourcemod" ]; then
DOWNLOAD_URL=`lynx -dump "http://www.sourcemod.net/smdrop/$2/" | egrep -o "http:.*sourcemod-.*-linux.*" | tail -2 | head -n 1`
else
DOWNLOAD_URL=`lynx -dump "http://www.metamodsource.net/mmsdrop/$2/" | egrep -o "http:.*mmsource-.*-git.*-linux.*" | tail -1`
fi
if [ "$3" == "" ]; then
update "${1}.txt" "$DOWNLOAD_URL" "${1}" "masteraddons"
else
update "${1}_snapshot_${3}.txt" "$DOWNLOAD_URL" "${1}-${3}" "masteraddons"
fi
}
function fileUpdate {
checkCreateVersionFile "$1"
checkCreateFolder "$HOME/$4/$2"
cd "$HOME/$4/$2"
wget "$2"
NO_HTTP=${2:6}
FILE_NAME=${NO_HTTP##/*/}
if [ "$FILE_NAME" != "" -a -f "$FILE_NAME" ]; then
LOCAL_VERSION=`cat $HOME/versions/$1 | tail -1`
CURRENT_VERSION=`stat -c "%Y" $FILE_NAME`
if ([ "$CURRENT_VERSION" != "$LOCAL_VERSION" -o "$LOCAL_VERSION" == "" ] && [ "$CURRENT_VERSION" != "" ]); then
greenMessage "Updating $3 from $LOCAL_VERSION to $CURRENT_VERSION. Name of file is $FILE_NAME"
unzip "$FILE_NAME"
echo "$CURRENT_VERSION" > "$HOME/versions/$1"
else
cyanMessage "$3 already up to date. Local version is $LOCAL_VERSION. Most recent version is $CURRENT_VERSION"
fi
rm -f "$FILE_NAME"
fi
}
function mtaFiles {
fileUpdate server_mta_configs.txt "https://linux.mtasa.com/dl/baseconfig.tar.gz" "mtasa" "masterserver"
fileUpdate server_mta_resources.txt "http://mirror.mtasa.com/mtasa/resources/mtasa-resources-latest.zip" "mtasa" "masterserver"
}
function updateMTA {
cyanMessage "Searching update for MTA San Andreas"
checkCreateVersionFile "server_mta.txt"
FILE_NAME="multitheftauto_linux_x64.tar.gz"
LOCAL_VERSION=`cat $HOME/versions/server_mta.txt | tail -1`
CURRENT_VERSION=`lynx -dump http://linux.mtasa.com/ | egrep -o "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+" | tail -1`
if ([ "$CURRENT_VERSION" != "$LOCAL_VERSION" -o "$LOCAL_VERSION" == "" ] && [ "$CURRENT_VERSION" != "" ]); then
greenMessage "Updating server_mta.txt from $LOCAL_VERSION to $CURRENT_VERSION. Name of file is $FILE_NAME"
downloadExtractFile "mtasa" "$FILE_NAME" "https://linux.mtasa.com/dl/multitheftauto_linux_x64.tar.gz" "masterserver"
echo "$CURRENT_VERSION" > "$HOME/versions/server_mta.txt"
mtaFiles
elif [ "$CURRENT_VERSION" == "" ]; then
cyanMessage "Could not detect current version for mta. Local version is $LOCAL_VERSION."
else
cyanMessage "mta already up to date. Local version is $LOCAL_VERSION. Most recent version is $CURRENT_VERSION"
fi
if [ "`date +'%H'`" == "00" ]; then
mtaFiles
fi
}
function updateSAMP {
cyanMessage "Searching update for San Andreas Multi Player"
DOWNLOAD_URL=`lynx -dump "http://files.sa-mp.com/" | egrep -o "http:.*samp.*tar\.gz" | tail -n 1`
update server_samp.txt "$DOWNLOAD_URL" "samp" "masterserver"
}
checkCreateFolder $HOME/versions
case $1 in
"mta") updateMTA;;
"samp") updateSAMP;;
"mms") updatesAddonSnapshots "metamod" "1.10" "";;
"mms_snapshot") updatesAddonSnapshots "metamod" "1.10" "dev";;
"mms_dev") updatesAddonSnapshots "metamod" "1.11" "dev";;
"sm") updatesAddonSnapshots "sourcemod" "1.8" "";;
"sm_snapshot") updatesAddonSnapshots "sourcemod" "1.8" "dev";;
"sm_dev") updatesAddonSnapshots "sourcemod" "1.9" "dev";;
*) cyanMessage "Usage: ${0} mta|mms|mms_snapshot|mms_dev|sm|sm_snapshot|sm_dev";;
esac
exit 0