Commit 2af24643 authored by Zach van Rijn's avatar Zach van Rijn
Browse files

Initial commit of non-freshness mirror generator.

parents
Set up daily cron job with ./mirrors; ensure that the output is written
to a public HTML file, e.g. /var/www/html/status.html.
T1 us Texas USA us1-distfiles 1\ Gbps Adélie\ Linux http://distfiles.adelielinux.org/ https://distfiles.adelielinux.org/ rsync://distfiles.adelielinux.org/distfiles/ _
T2 de Bavaria Germany eu1-distfiles 1\ Gbps Leuhta\ Labs http://eu1-distfiles.adelielinux.org/ https://eu1-distfiles.adelielinux.org/ rsync://eu1-distfiles.adelielinux.org/distfiles/ _
T2 us Pennsylvania USA us2-distfiles 100\ Mbps ionFish\ Group http://us2-distfiles.adelielinux.org/ _ _ _
T3 us Indiana USA purdue 10\ Gbps Purdue\ Linux<br\ />Users\ Group http://plug-mirror.rcac.purdue.edu/adelie/ https://plug-mirror.rcac.purdue.edu/adelie/ rsync://plug-mirror.rcac.purdue.edu/adelie/ ftp://plug-mirror.rcac.purdue.edu/adelie/
T3 us Illinois USA servercentral 10\ Gbps ServerCentral<br\ />Turing\ Group http://mirrors.servercentral.com/adelie/ https://mirrors.servercentral.com/adelie/ _ _
#!/bin/sh -e
#---------------------------------------------------------------
##
# Generates table data for https://www.adelielinux.org/mirrors/.
# The output is HTML and it is run on a 5-minute cron job, then
# the result is made available to clients accessing that page.
#
##
# Table header.
#
T0_NEED=1;
T0_BODY=$(cat <<'EOF'
<thead>
<tr>
<th scope="col"><!-- country flag --></th>
<th scope="col">Location</th>
<th scope="col">Name</th>
<th scope="col" class="text-right">Speed</th>
<th scope="col" class="text-right">Freshness</th>
<th scope="col" class="text-right">Uptime</th>
<th scope="col">Sponsor</th>
<th scope="col">Protocol</th>
</tr>
</thead>
EOF
);
#---------------------------------------------------------------
##
# Tier 1.
#
T1_NEED=1;
T1_BODY=$(cat <<'EOF'
<tr>
<td colspan="8"><strong>Official</strong>&nbsp;&mdash;&nbsp;Part of Adélie's core infrastructure.</td>
</tr>
EOF
);
##
# Tier 2.
#
T2_NEED=1;
T2_BODY=$(cat <<'EOF'
<tr>
<td colspan="8"><strong>Affiliated</strong>&nbsp;&mdash;&nbsp;Operated by Adélie's developers and friends.</td>
</tr>
EOF
);
##
# Tier 3.
#
T3_NEED=1;
T3_BODY=$(cat <<'EOF'
<tr>
<td colspan="8"><strong>Third-Party</strong>&nbsp;&mdash;&nbsp;Community-managed mirrors over which we have no control.</td>
</tr>
EOF
);
#---------------------------------------------------------------
##
# Row template.
#
# It is assumed that all mirrors have at least 'http' meaning if
# one does not, then there is an extra preceding '<br />' which
# may cause display problems.
#
ROW_DATA=$(cat <<'EOF'
<tr>
<td class="text-right"><img src="../assets/images/flags/w40-webp/__FLAG__.webp" alt=""></td>
<td>__STATE__,<br />__COUNTRY__</td>
<td>__NAME__</td>
<td class="text-right">__SPEED__</td>
<td class="text-right">__FRESH__</td>
<td class="text-right">__UPTIME__</td>
<td>__SPONSOR__</td>
<td>
<strong>
<a href="__HTTP__">http</a>
<br /><a href="__HTTPS__">https</a>
<br /><a href="__RSYNC__">rsync</a>
<br /><a href="__FTP__">ftp</a>
</strong>
</td>
</tr>
EOF
);
#---------------------------------------------------------------
##
# Get time of last mirrormaster update.
#
wget -q http://distfiles.adelielinux.org/heartbeat -O heartbeat;
##
# Populate templates. The logic here is as follows:
#
# * Read space-delimited CSV file with a set number of columns
#
# * Each column corresponds to a variable accessible by 'read'
#
# * Append a row template to the output file
#
# * Values are replaced directly, or computed, or deleted if a
# value is '_', the sentinel for NULL because we cannot have
# meaningful extra spaces when reading by column.
#
# * Output is written to a temporary file
#
# Note that input data must be space-escaped.
#
TEMPFILE=$(mktemp);
printf >> ${TEMPFILE} "${T0_BODY}\n";
printf >> ${TEMPFILE} "<tbody>\n";
while read type flag state country name speed sponsor http https rsync ftp; do
case $type in
T1) test ${T1_NEED} = 1 && T1_NEED=0 && printf >> ${TEMPFILE} "${T1_BODY}\n"; ;;
T2) test ${T2_NEED} = 1 && T2_NEED=0 && printf >> ${TEMPFILE} "${T2_BODY}\n"; ;;
T3) test ${T3_NEED} = 1 && T3_NEED=0 && printf >> ${TEMPFILE} "${T3_BODY}\n"; ;;
*) printf "E: bad type\n"; exit 1; ;;
esac
printf "%s\n" "${ROW_DATA}" >> ${TEMPFILE};
sed -i ${TEMPFILE} \
-e 's@__FLAG__@'"${flag}"'@g' \
-e 's@__STATE__@'"${state}"'@g' \
-e 's@__COUNTRY__@'"${country}"'@g' \
-e 's@__NAME__@'"${name}"'@g' \
-e 's@__SPEED__@'"${speed}"'@g' \
-e 's@__SPONSOR__@'"${sponsor}"'@g' \
-e 's@__FRESH__@'"00:00:00"'@g' \
-e 's@__UPTIME__@'"00:00:00"'@g' \
;
if test ${http} != _; then
sed -i ${TEMPFILE} \
-e 's@__HTTP__@'"${http}"'@g' \
;
else
sed -i ${TEMPFILE} \
-e '/__HTTP__/d' \
;
fi
if test ${https} != _; then
sed -i ${TEMPFILE} \
-e 's@__HTTPS__@'"${https}"'@g' \
;
else
sed -i ${TEMPFILE} \
-e '/__HTTPS__/d' \
;
fi
if test ${rsync} != _; then
sed -i ${TEMPFILE} \
-e 's@__RSYNC__@'"${rsync}"'@g' \
;
else
sed -i ${TEMPFILE} \
-e '/__RSYNC__/d' \
;
fi
if test ${ftp} != _; then
sed -i ${TEMPFILE} \
-e 's@__FTP__@'"${ftp}"'@g' \
;
else
sed -i ${TEMPFILE} \
-e '/__FTP__/d' \
;
fi
done < mirrors.csv
printf >> ${TEMPFILE} "</tbody>\n";
#---------------------------------------------------------------
mv ${TEMPFILE} /var/www/html/status.html;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment