blob: 068d78e799075d1422f5160e8e6308ddc66a176c (
plain) (
blame)
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
|
#!/usr/bin/env bash
version_file="versions.txt"
checksum_file="sha256checksum.txt"
deploy_dir="public"
if [[ ${CI_PROJECT_DIR} == "" ]]; then
version_url="https://jak89_1.gitlab.io/docker-testing/${version_file}" # change me!
version_url2="https://gitlab.com/jak89_1/docker-testing/-/jobs/artifacts/master/raw/public/${version_file}?job=pages" # change me
echo "[NON CI] : using local paths"
else
version_url="${CI_PAGES_URL}/${version_file}"
version_url2="https://gitlab.com/jak89_1/docker-testing/-/jobs/artifacts/master/raw/public/${version_file}?job=${CI_JOB_NAME}" # change me
fi
version_url3="https://manaplus.germantmw.de/versions/${version_file}" # fallback to my server if gitlab breaks its own pages *blames gitlab*
#add new mirrors to the end of BOTH lines
mirror_names=("gitlab.io gertmw.de")
mirror_urls=("https://themanaworld.gitlab.io/manaplus/builder/ https://manaplus.germantmw.de/versions/") # change me
last_checksum="https://gitlab.com/jak89_1/docker-testing/-/jobs/artifacts/master/raw/build/${checksum_file}?job=mxe_gcc5" # change me
#last_checksum_d="https://gitlab.com/jak89_1/docker-testing/-/jobs/artifacts/master/raw/build/debug-${checksum_file}?job=mxe_gcc5" # change me # not handled yet
# end of variable-scrabble (move this to gitlab-ci.yml laterâ„¢)
if [[ ! -d $deploy_dir ]]; then
mkdir -p $deploy_dir
fi
# buffer for .html
_b(){
BUFFER_HTML=${BUFFER_HTML}${1}
}
# buffer for .xml
_x(){
BUFFER_XML=${BUFFER_XML}${1}
}
# buffer for .json
_j(){
BUFFER_JSON=${BUFFER_JSON}${1}
}
gen_page(){
_b "<!DOCTYPE html><html>"
_b "<head><title>MirrorList</title></head>"
_b "<body><center>"
_b "<h1>ManaPlus Mirror & Version List</h1>"
_b "<sup>hover to see checksums</sup>"
_b "<table border='1px solid black'>"
_b "<tr>"
for mirror in $mirror_names; do
_b "<th>$mirror</th>"
done
_b "</tr>"
_x "<?xml version='1.0' encoding='utf-8'?>\n"
_x "<!--\n Authors: jak1\n Copyright: (C) 2021 TheManaWorld Developers\n Generated by: Gitlab deploy (manual changes will get overwritten)\n-->\n"
_j "{\n"
_j " \"#comment\": \"Authors: jak1 Copyright: (C) 2021 TheManaWorld Developers Generated by: Gitlab deploy (manual changes will get overwritten)\",\n"
_j " \"versions\": {\n"
_x "<versions>\n";
while IFS= read -r line; do
# ${line#* } = checksum
# ${line% *} = filename
_b "<tr>"
_x " <version file='${line#* }' checksum='${line% *}'>\n";
_j " \"version\": {\n \"-file\": \"${line#* }\",\n \"-checksum\": \"${line% *}\",\n \"mirror\": [\n"
c=0
for mirror_url in $mirror_urls; do
_b "<td><a title='sha256:${line% *}' href='${mirror_url}${line#* }'>${line#* }</a></td>";
_x " <mirror url='${mirror_url}${line#* }' />\n";
_j " {\n \"-url\": \"${mirror_url}${line#* }\"\n }"
if [[ $c == ${#mirror_urls[@]} ]]; then
_j "\n"
else
_j ",\n"
fi
((c++))
done
_j " ]\n }\n }\n"
_x " </version>\n";
_b "</tr>"
done < $version_file
_x "</versions>\n";
_j "}\n"
_b "</table>"
_b "<a href='$version_file'>versions.txt</a>"
_b "</center></body>"
_b "</html>"
#write out files (keep source formating for xml)
echo $BUFFER_HTML > $deploy_dir/mirrorlist.html
echo -e "$BUFFER_XML" > $deploy_dir/mirrorlist.xml
echo -e "$BUFFER_JSON" > $deploy_dir/mirrorlist.json
}
add_new_release(){
wget $last_checksum -O $checksum_file -q
#if #TODO: check if new tag/version exists, of if the pipeline got trigerred manualy
checksum=$(<${checksum_file})
echo $checksum >> $version_file
rm $checksum_file || exit 1
#fi
}
get_version_file(){
# -O is needed for artifacts!
# getting version file from deployed pages (this can break)
wget $version_url -O $version_file -q
if [[ ! -f $version_file ]]; then
echo "cant download '${version_file}' from '${version_url}'"
# getting version file from last artifacts (this can break)
wget $version_url2 -O $version_file -q
if [[ ! -f $version_file ]]; then
echo "cant download '${version_file}' from '${version_url2}'"
# getting version file from my server as fallback
wget $version_url3 -O $version_file -q
if [[ ! -f $version_file ]]; then
echo "cant download '${version_file}' from '${version_url3}'"
# this should only happen for the first build!
touch $version_file
fi
fi
fi
}
get_version_file
add_new_release
gen_page
xmllint --schema $deploy_dir/mirrorlist.xsd $deploy_dir/mirrorlist.xml --noout || exit 1
mv $version_file $deploy_dir || exit 1
echo "deploy passed \\o/"
|