Skip to content

Commit 335b394

Browse files
committed
Add optional Kiwix test ZIM download
After installing Kiwix-Tools, add an optional step to fetch the latest speedtest ZIM archive from https://download.kiwix.org/zim/wikipedia. The script probes the listing to find the newest speedtest_en_blob_YYYY-MM.zim, then downloads it to /data using a temporary file and curl_with_retry (with CURL_TIMEOUT and CURL_CONNECT_TO), handling missing entries, download failures, and empty files with warnings. On success the file is moved into /data and a success message is logged.
1 parent 0b3ff91 commit 335b394

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

install/kiwix-install.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,34 @@ mkdir -p /data
2929
echo "${RELEASE}" >/root/.kiwix
3030
msg_ok "Installed Kiwix-Tools"
3131

32+
msg_info "Downloading Kiwix Test Archive"
33+
ZIM_BASE_URL="https://download.kiwix.org/zim/wikipedia"
34+
ZIM_FILE="$(CURL_TIMEOUT=60 CURL_CONNECT_TO=15 curl_with_retry "${ZIM_BASE_URL}/" "-" |
35+
grep -oE 'href="speedtest_en_blob_[0-9]{4}-[0-9]{2}\.zim"' |
36+
sed -E 's/^href="|"$//g' |
37+
sort -V |
38+
tail -n 1)" || true
39+
40+
if [[ -z "${ZIM_FILE}" ]]; then
41+
msg_warn "No Kiwix speedtest ZIM archive found - skipping optional download"
42+
else
43+
ZIM_URL="${ZIM_BASE_URL}/${ZIM_FILE}"
44+
ZIM_TEMP="/data/.${ZIM_FILE}.tmp"
45+
ZIM_TARGET="/data/${ZIM_FILE}"
46+
if ! CURL_TIMEOUT=120 CURL_CONNECT_TO=15 curl_with_retry "${ZIM_URL}" "${ZIM_TEMP}"; then
47+
rm -f "${ZIM_TEMP}"
48+
msg_warn "Failed to download Kiwix ZIM archive - skipping optional download"
49+
ZIM_FILE=""
50+
elif [[ ! -s "${ZIM_TEMP}" ]]; then
51+
rm -f "${ZIM_TEMP}"
52+
msg_warn "Downloaded Kiwix ZIM archive is empty - skipping optional download"
53+
ZIM_FILE=""
54+
else
55+
mv "${ZIM_TEMP}" "${ZIM_TARGET}"
56+
msg_ok "Downloaded Kiwix Test Archive (${ZIM_FILE})"
57+
fi
58+
fi
59+
3260
msg_info "Creating Service"
3361
cat <<'EOF' >/etc/systemd/system/kiwix-serve.service
3462
[Unit]

0 commit comments

Comments
 (0)