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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
#!/bin/bash
# parameters and default values
ARCH='i686'
DESC='i686 only'
OUTPUT_DIR="${HOME}/archisos"
DATE=$(date +%Y.%m.%d)
ISO="archlinux32-${DATE}-${ARCH}.iso"
mirror_dir='/mnt/archlinux32'
website_dir='/usr/src/archlinux32/archweb32'
# fail on first error
set -e
base_dir=$(
readlink -e "${0%/*}"
)
usage() {
>&2 echo ''
>&2 echo 'update-website: update download, torrent, magnet links on'
>&2 echo ' the Arch32 website'
>&2 echo ''
>&2 echo 'possible options:'
>&2 echo ' -h|--help: Show this help and exit.'
>&2 echo ' --magnet-i686 $link:'
>&2 echo ' Set archiso-i686 magnet link to $link.'
>&2 echo ' --magnet-dual $link:'
>&2 echo ' Set archiso-dual magnet link to $link.'
>&2 echo ' --torrent-seed-i686 $link:'
>&2 echo ' Set archiso-i686 torrent link to $link.'
>&2 echo ' --torrent-seed-dual $link:'
>&2 echo ' Set archiso-dual torrent link to $link.'
>&2 echo ' --website-dir $dir:'
>&2 echo ' Set website-dir to $dir.'
>&2 echo ' --mirror-dir $dir:'
>&2 echo ' Set mirror-dir to $dir.'
>&2 echo ' --update-mirrors:'
>&2 echo ' regenerate mirror list and country flags.'
>&2 echo ' --update-iso update information about ISO, too.'
>&2 echo " --iso name of ISO to be checked, default is '${ISO}'."
>&2 echo " --output-dir where to write the isos, default is '${OUTPUT_DIR}."
>&2 echo " --arch architecture of the ISO to update, default '$ARCH'."
>&2 echo " --desc description of the ISO to update, default '$DESC'."
[ -z "$1" ] && exit 1 || exit "$1"
}
eval set -- "$(
getopt -o h \
--long help \
--long magnet-i686: \
--long magnet-dual: \
--long torrent-seed-i686: \
--long torrent-seed-dual: \
--long mirror-dir: \
--long website-dir: \
--long update-mirrors \
--long update-iso \
--long iso: \
--long arch: \
--long desc: \
-n "$(basename "$0")" -- "$@" || \
echo usage
)"
# cleanup hook
tmp_dir="$(mktemp -d)"
cleanup() {
if mountpoint -q "${tmp_dir}"; then
sudo umount "${tmp_dir}"
fi
rm -rf --one-file-system "${tmp_dir}"
}
trap cleanup EXIT
arch="${ARCH}"
desc="${DESC}"
iso="${ISO}"
while [ $# -gt 0 ]; do
case "$1" in
'--magnet-i686')
if [ -s "${tmp_dir}/magnet.i686" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
shift
echo "$1" | \
tr -d '\n' > \
"${tmp_dir}/magnet.i686"
;;
'--magnet-dual')
if [ -s "${tmp_dir}/magnet.dual" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
shift
echo "$1" | \
tr -d '\n' > \
"${tmp_dir}/magnet.dual"
;;
'--torrent-seed-i686')
if [ -s "${tmp_dir}/torrent-seed.i686" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
shift
echo "$1" | \
tr -d '\n' > \
"${tmp_dir}/torrent-seed.i686"
;;
'--torrent-seed-dual')
if [ -s "${tmp_dir}/torrent-seed.dual" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
shift
echo "$1" | \
tr -d '\n' > \
"${tmp_dir}/torrent-seed.dual"
;;
'--mirror-dir')
if [ -s "${tmp_dir}/mirror_dir.set" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
shift
mirror_dir="$1"
echo "$mirror_dir" > "${tmp_dir}/mirror_dir.set"
;;
'--website-dir')
if [ -s "${tmp_dir}/website_dir.set" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
shift
website_dir="$1"
echo "$website_dir" > "${tmp_dir}/website_dir.set"
;;
'--update-mirrors')
if [ -s "${tmp_dir}/update_mirrors.set" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
echo "true" > "${tmp_dir}/update_mirrors.set"
;;
'--update-iso')
if [ -s "${tmp_dir}/update_iso.set" ]; then
printf 'Option %s given multiple times.\n' "$1"
usage
fi
echo "true" > "${tmp_dir}/update_iso.set"
;;
'--iso')
shift
iso="$1"
;;
'--arch')
shift
arch="$1"
;;
'--desc')
shift
desc="$1"
;;
'--help'|'-h')
usage 0
;;
'--')
shift
break
;;
*)
>&2 printf 'Whoops, option "%s" is not yet implemented!\n' "$1"
exit 42
;;
esac
shift
done
if [ $# -gt 0 ]; then
>&2 echo 'Too many arguments.'
exit 2
fi
# generate list of download mirrors
if [ -s "${tmp_dir}/update_mirrors.set" ]; then
(
printf ' <div id="download-mirrors">\n'
curl -Ss 'https://archlinux32.org/mirrorlist/?country=all&hash='"$(
head -c 24 /dev/urandom | \
base64 -w0
)" | \
sed '
0,/^$/d
/^$/d
/^## /{
s|^## |\n </ul>\n\n <h5>|
s|$|</h5>\n\n <ul>\n|
'"$(
while read -r flag country; do
printf \
's|<h5>%s</h5>|<h5><span class="fam-flag fam-flag-%s" title="%s"></span> %s</h5>|\n' \
"${country}" \
"${flag}" \
"${country}" \
"${country}"
done < \
"${0%/*}/flag-names"
)"'
}
/^#Server = /{
s|^#Server = \(.*//\)\([^/]*\)\(/.*\)\$arch/\$repo/\?$|'"$(
printf \
' %s\\n' \
'<li><a href="\1\2\3archisos/"' \
' title="Download from \1\2\3">\2</a></li>'
)"'|
}
' | \
sed '
0,/<\/ul>/d
'
printf ' </ul>\n\n'
printf ' </div>\n'
) | \
sed -i '
:emptyLines
/^\n*$/{
N
bemptyLines
}
/^\(\s*\n\)*\s*<div id="download-mirrors">$/{
:a
s|^.*</div>||
tb
$!N
ba
:b
r /dev/stdin
}
' "${website_dir}/download/index.html"
fi
latest_iso_date="$(
ls "${mirror_dir}/archisos" | \
grep '^archlinux32-[0-9.]\+-\(dual\|i.86\)\.iso$' | \
sed 's@^archlinux32-\([0-9.]\+\)-\(dual\|i.86\)\.iso$@\1@' | \
sort -k1,1 -u | \
tail -n1
)"
# update magnet links
if [ -s "${tmp_dir}/magnet.${arch}" ]; then
if ! tr '&' '\n' < \
"${tmp_dir}/magnet.${arch}" | \
grep -qxF "dn=${iso}"; then
sed -i '
/<li><a href="magnet:?.*-'"${arch}"'\.iso/ s/href="[^"]\+"/href="'"$(sed 's|&|\\&|g' "${tmp_dir}/magnet.${arch}")"'"/
/title="Magnet link">Magnet link for \S\+ ('"${desc["${arch}"]}"')/ s/>Magnet link for \S\+ />Magnet link for '"${latest_iso_date}"' /
' "${website_dir}/download/index.html"
else
>&2 printf 'Magnet link for %s is not for %s, skipping.\n' "${arch}" "${iso}"
fi
fi
# update torrent links
if [ -s "${tmp_dir}/torrent-seed.${arch}" ]; then
if grep -qF "archlinux32-${latest_iso_date}-${arch}" "${tmp_dir}/torrent-seed.${arch}"; then
sed -i '
/<li><a href="http.*-'"${arch}"'\.iso.torrent/ s/href="[^"]\+"/href="'"$(sed -e 's_/_\\/_g' "${tmp_dir}/torrent-seed.${arch}")"'"/
/title="Download torrent">Torrent for \S\+ ('"${desc["${arch}"]}"')/ s/>Torrent for \S\+ />Torrent for '"${latest_iso_date}"' /
' "${website_dir}/download/index.html"
else
>&2 printf 'Torrent seed for %s is not for %s, skipping.\n' "${arch}" "${iso}"
fi
fi
# update ISO links and information
if [ -s "${tmp_dir}/update_iso.set" ]; then
if [ ! -f "${mirror_dir}/archisos/${iso}" ]; then
>&2 echo "Can't find iso to arch '${mirror_dir}/archisos/${iso}'."
exit 1
fi
kernel="$("${base_dir}"/check-iso --output-dir "${mirror_dir}/archisos" --kernel-version)"
size="$("${base_dir}"/check-iso --output-dir "${mirror_dir}/archisos" --size)"
md5="$("${base_dir}"/check-iso --output-dir "${mirror_dir}/archisos" --md5sum)"
sha512="$("${base_dir}"/check-iso --output-dir "${mirror_dir}/archisos" --sha512sum)"
sign_key="$("${base_dir}"/check-iso --output-dir "${mirror_dir}/archisos" --sign-key)"
fi
# adapt release info on the top
values=(
'Current Release' "${latest_iso_date}"
'Included Kernel' "${kernel}"
'PGP Key' '<a href="http://www.archlinux32.org/buildmaster/gpg-keys.php?fp='"${sign_key}"'">'"${sign_key}"'</a>'
)
sed -i "$(
printf '/%s:/s|</strong>.*</li>|</strong> %s</li>|\n' "${values[@]}"
)
" \
"${website_dir}/download/index.html"
# adapt values for each ISO
values=(
"ISO Size (${desc})" "${size} MB"
"MD5 (${desc})" "${md5}"
"SHA512 (${desc})" "${sha512}"
)
sed -i "$(
printf '/%s:/s|</strong>.*</li>|</strong> %s</li>|\n' "${values[@]}"
)
" \
"${website_dir}/download/index.html"
# adapt dates in signatures
sed -i "$(
printf '/archlinux32-[0-9.]\+-%s\.iso\.sig/s@archlinux32-[0-9.]\+-%s\.iso\.sig@archlinux32-%s-%s.iso.sig@\n' \
"${arch}" "${arch}" "${latest_iso_date}" "${arch}"
)
" \
"${website_dir}/download/index.html"
exit 0
|