-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·250 lines (233 loc) · 5.73 KB
/
update.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
#!/bin/bash
if [ ! -f lib/lib.sh ]
then
echo "Error: lib/lib.sh not found!"
echo "make sure you are in the root of the server repo"
exit
fi
source lib/lib.sh
source lib/include/update/vartype.sh
source lib/include/update/cmake.sh
source lib/include/update/custom.sh
source lib/include/update/bam.sh
print_default() {
if [ "$CFG_SERVER_TYPE" == "$1" ]
then
tput bold
printf "(default)"
tput sgr0
fi
}
tem_update() {
(
cd "$CFG_TEM_PATH" || exit 1
git_save_pull
)
}
arg_type=''
arg_refresh=0
for arg in "$@"
do
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]
then
echo "usage: ./update.sh [TYPE] [OPTIONS..]"
echo "type:"
echo " teeworlds compile a teeworlds server $(print_default teeworlds)"
echo " tem update a TeeworldsEconMod repo $(print_default tem)"
echo " bot update side runner bot"
echo "options:"
echo " -f|--force force build dirty git tree"
echo " --refresh only update binary no rebuild (for now teeworlds only)"
exit 0
elif [ "${arg::1}" != "-" ] && [ "$arg_type" == "" ]
then
arg_type="$arg"
if [[ ! "$arg_type" =~ (teeworlds|tem|bot) ]]
then
err "ERROR: invalid update type '$arg_type'"
err " valid types: teeworlds, tem, bot"
exit 1
fi
shift
elif [ "$arg" == "--force" ] || [ "$arg" == "-f" ]
then
# gets passed on
test
elif [ "$arg" == "--refresh" ]
then
arg_refresh=1
else
err "Error: unknown argument '$arg' try --help"
exit 1
fi
done
map_themes_pre() {
if [ ! -d "$CFG_GIT_ROOT"/maps-scripts ]
then
return
fi
OldMapHashes=()
local map_name
for map_name in "$CFG_GIT_ROOT"/maps-scripts/*/themes
do
map_name="${map_name%/*}" # cut off /themes at the end
map_name="$(basename "$map_name")" # get folder name for examle BlmapChill
if [ -f ./maps/"$map_name".map ]
then
OldMapHashes["$map_name"]="$(sha1sum ./maps/"$map_name".map | cut -d' ' -f1)"
fi
done
}
map_themes_post() {
if [ ! -d "$CFG_GIT_ROOT"/maps-scripts ]
then
return
fi
# expects the following folder structure fro $CFG_GIT_ROOT/maps-scripts
# https://github.com/DDNetPP/maps-scripts
#
# and also supports ./designs being a maps repo like this
# https://github.com/fddrace/maps-themes
# where the generated themes will auto uploaded
# and the plain mapfiles will be auto pulled
if [ -d ./designs/.git ]
then
pushd ./designs/ > /dev/null || exit 1
git_save_pull
popd > /dev/null || exit 1
fi
local map_name
local t
local updated_themes=0
for map_name in "$CFG_GIT_ROOT"/maps-scripts/*/themes
do
map_name="${map_name%/*}" # cut off /themes at the end
map_name="$(basename "$map_name")" # get folder name for examle BlmapChill
log "themes for $map_name"
if [ -f ./maps/"$map_name".map ]
then
if [ "${OldMapHashes["$map_name"]}" != "$(sha1sum ./maps/"$map_name".map | cut -d' ' -f1)" ]
then
local version_script
map_version=null
version_script="$CFG_GIT_ROOT"/maps-scripts/"$map_name"/print_version.py
log "map '$map_name' updated generating new themes ..."
log " old: ${OldMapHashes["$map_name"]}"
log " new: $(sha1sum ./maps/"$map_name".map | cut -d' ' -f1)"
if [[ -f "$version_script" ]]
then
map_version="$($version_script ./maps/"$map_name".map)"
log " version: $map_version"
fi
for t in "$CFG_GIT_ROOT"/maps-scripts/"$map_name"/themes/*.py
do
local theme_name
theme_name="$(basename "$t" .py)"
log "generating '$theme_name' theme for '$map_name' ..."
mkdir -p ./designs/"$map_name"
"$t" ./maps/"$map_name".map ./designs/"$map_name"/"$theme_name".map
updated_themes=1
if [ -d ./designs/.git ]
then
pushd ./designs/ > /dev/null || exit 1
git add ./"$map_name"/"$theme_name".map
git commit -m "Updated map $map_name theme $theme_name to version $map_version"
popd > /dev/null || exit 1
fi
done
fi
fi
done
if [ "$updated_themes" == "1" ] && [ -d ./designs/.git ]
then
pushd ./designs/ > /dev/null || exit 1
git push
popd > /dev/null || exit 1
fi
}
update_non_git_module_sub_repos() {
if ! is_cfg CFG_PULL_GIT_SUB_REPOS
then
return
fi
cd "$CFG_GIT_PATH_MOD" || exit 1
local sub_repo
while read -r sub_repo
do
[ -d "$sub_repo" ] || continue
log "found sub repo $sub_repo"
(
cd "$sub_repo" || exit 1
git_save_pull
)
done < <(find src -maxdepth 3 -name ".git" | rev | cut -c 5- | rev)
}
update_lua() {
[[ -d lua ]] || return
[[ -d lua/.git ]] || return
log "checking for lua/ updates"
pushd lua || return
git_save_pull
popd || return
}
if [ "$arg_type" == "bot" ]
then
if [ "$arg_refresh" == "1" ]
then
err "Error: --refresh is not supported for bot yet"
exit 1
fi
cmake_update_bot "$@"
update_configs
git_save_pull
update_lua
elif [ "$CFG_SERVER_TYPE" == "teeworlds" ] || [ "$arg_type" == "teeworlds" ]
then
if [ "$arg_refresh" == "1" ]
then
cmake_refresh_teeworlds_binary
exit 0
fi
while ! lock_build
do
wrn "WARNING: the build is locked by another process"
wrn " waiting for the lock to release ..."
sleep 20
done
map_themes_pre
update_non_git_module_sub_repos
if [ "$CFG_BUILD_SYSTEM" == "cmake" ]
then
cmake_update_teeworlds "$@"
elif [ "$CFG_BUILD_SYSTEM" == "bam" ]
then
bam_update_teeworlds 5 "$@"
elif [ "$CFG_BUILD_SYSTEM" == "bam4" ]
then
bam_update_teeworlds 4 "$@"
elif [ "$CFG_BUILD_SYSTEM" == "custom" ]
then
custom_update_teeworlds "$@"
else
unlock_build
err "Unsupported build system: $CFG_BUILD_SYSTEM"
exit 1
fi
map_themes_post
git_save_pull
update_lua
unlock_build
elif [ "$CFG_SERVER_TYPE" == "tem" ] || [ "$arg_type" == "tem" ]
then
if [ "$arg_refresh" == "1" ]
then
err "Error: --refresh is not supported for tem"
exit 1
fi
tem_update
update_configs
git_save_pull
else
err "something went wrong :/"
exit 1
fi