-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·194 lines (165 loc) · 4.18 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
#!/bin/bash
SCRIPT_PATH="$( cd -- "$(dirname "$0")" || exit 1 >/dev/null 2>&1 ; pwd -P )"
if [ "$SCRIPT_PATH" == "" ]
then
echo "[-] Error: could not get script path"
exit 1
fi
NEW_MAPS_SCRIPTS=0
NEW_MAPS_THEMES=0
NEW_MAPS_HTTP=0
python3 -c "import twmap" || exit 1
if [ ! -d maps-scripts/BlmapChill ]
then
echo "[!] Warning: no BlmapChill/ found in maps-scripts"
echo "[!] trying to load submodule"
git submodule update --init --recursive
fi
if [ ! -d maps-themes/BlmapChill ]
then
echo "[!] Warning: no BlmapChill/ found in maps-themes"
echo "[!] trying to load submodule"
git submodule update --init --recursive
fi
if [ ! -f http-maps/README.md ]
then
echo "[!] Warning: no README.md found in http-maps"
echo "[!] trying to load submodule"
git submodule update --init --recursive
fi
update_repo() {
# if update_repo maps-scripts
# then
# echo "got new commits"
# fi
local folder="$1"
local branch="${2:-master}"
local commit_pre_pull=''
local commit_post_pull=''
pushd "$SCRIPT_PATH" || exit 1
if [ ! -d "$folder/.git" ]
then
pushd "$folder" || exit 1
echo "[*] updating $folder ..."
git checkout "$branch"
commit_pre_pull="$(git rev-parse HEAD)"
git pull
commit_post_pull="$(git rev-parse HEAD)"
popd || exit 1
git add "$folder" && git commit -m "Auto update submodule $folder" && git push
fi
popd || exit 1 # SCRIPT_PATH
if [ "$commit_pre_pull" != "$commit_post_pull" ]
then
return 0
fi
return 1
}
update_all_git() {
pushd "$SCRIPT_PATH" || exit 1
git pull
update_repo maps-scripts && NEW_MAPS_SCRIPTS=1
update_repo maps-themes && NEW_MAPS_THEMES=1
update_repo http-maps && NEW_MAPS_HTTP=1
popd || exit 1
}
update_maps_scripts() {
local mapname="$1"
# skip generate if there are no new commits
[[ "$NEW_MAPS_SCRIPTS" == "1" ]] || return
local theme
local theme_outfile
for theme in "$SCRIPT_PATH/maps-scripts/$mapname"/themes/*.py
do
[ -f "$theme" ] || continue
theme="$(basename "$theme" .py)"
echo "[*] generating python $theme theme ..."
"$SCRIPT_PATH/maps-scripts/$mapname/themes/$theme.py" "$mapname.map" "${mapname}_${theme}.map"
checksum="$(sha256sum "${mapname}_${theme}.map" | cut -d' ' -f1)"
theme_outfile="${mapname}_${theme}_$checksum.map"
echo "[*] $theme_outfile"
mv "${mapname}_${theme}.map" "$theme_outfile"
done
}
update_maps_themes() {
local mapname="$1"
# skip generate if there are no new commits
[[ "$NEW_MAPS_THEMES" == "1" ]] || return
echo "[*] generate themes based on .map themes ..."
pushd "$SCRIPT_PATH/maps-themes" || exit 1
git pull
./generate.sh || exit 1
git add .
git commit -m "generate themes"
git push
popd || exit 1
echo "[*] generate .map file themes sha sums ..."
local theme
local theme_outfile
for theme in "$SCRIPT_PATH/maps-themes/$mapname"/*.map
do
[ -f "$theme" ] || continue
local theme_fullpath="$theme"
theme="$(basename "$theme" .map)"
echo "[*] generating $theme.map theme sha256sums ..."
checksum="$(sha256sum "$theme_fullpath" | cut -d' ' -f1)"
theme_outfile="${mapname}_${theme}_$checksum.map"
echo "[*] $theme_outfile"
cp "$theme_fullpath" "$theme_outfile"
done
}
update_http_maps() {
[[ "$NEW_MAPS_HTTP" == "1" ]] || return
local map
for map in "$SCRIPT_PATH"/http-maps/*.map
do
[ -f "$map" ] || continue
hash_map "$map"
done
}
function hash_map() {
local map="$1"
local mapname
local checksum
local outfile
if [ ! -f "$map" ]
then
echo "Error: map not found '$map'"
exit 1
fi
mapname="$(basename "$map" .map)"
checksum="$(sha256sum "$map" | cut -d' ' -f1)"
outfile="${mapname}_$checksum.map"
echo "[*] adding '$map'"
if [ -f "$outfile" ]
then
echo "[*] already got '$outfile'"
else
echo "[*] adding new '$outfile'"
fi
cp "$map" "$outfile"
}
all_maps=(
BlmapChill
blmapV3multistarbox
)
if [ ! -d public ]
then
# force refresh all on first run
NEW_MAPS_SCRIPTS=1
NEW_MAPS_THEMES=1
NEW_MAPS_HTTP=1
fi
mkdir -p public
cd public || exit 1
update_all_git
update_http_maps
for map in "${all_maps[@]}"
do
[[ -f "$map".map ]] && rm "$map".map
wget -q "https://github.com/DDNetPP/maps/raw/master/$map.map"
hash_map "$map".map
update_maps_scripts "$map"
update_maps_themes "$map"
rm "$map".map
done