commit: 97ea3377d7030d39b2f7340ebf060eb072ec2343 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> AuthorDate: Tue Apr 28 23:21:21 2020 +0000 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> CommitDate: Tue Apr 28 23:21:21 2020 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=97ea3377
mirmon-snapshots.sh: test refactor of runner Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> mirmon-snapshots.sh | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/mirmon-snapshots.sh b/mirmon-snapshots.sh old mode 100644 new mode 100755 index 692a1ef..894e94b --- a/mirmon-snapshots.sh +++ b/mirmon-snapshots.sh @@ -1,18 +1,36 @@ #!/bin/bash -cd /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/snapshots_mirrors +set -e + +MODE=snapshots +SRC=distfiles +SITEDIR=/var/www/mirrorstats.gentoo.org +REPODIR=${SITEDIR}/gentoo-mirrorstats/ +MODEDIR=${SITEDIR}/${MODE}_mirrors/ +VARDIR=${SITEDIR}/var/${MODE} +HTDOCS=${SITEDIR}/htdocs/${MODE} +MIRMON=$(readlink -f "${SITEDIR}"/mirmon/mirmon) +CONFFILE=$(readlink -f "${MODEDIR}"/mirmon.conf) + # Grab mirrors from the web -[[ -d ./var ]] || mkdir ./var -../get-mirrors-from-distfiles-xml.rb > ./var/g.mirrors +mkdir -p "${VARDIR}" +"${REPODIR}"/get-mirrors-from-${SRC}-xml.rb > "${VARDIR}"/g.mirrors.tmp && mv -f "${VARDIR}"/g.mirrors{.tmp,} + # fatal if the state file is NOT present. -[[ -e ./var/mirmon.state ]] || touch ./var/mirmon.state +[[ -e ${VARDIR}/mirmon.state ]] || touch "${VARDIR}/mirmon.state" + # run mirmon -/usr/bin/perl ../../mirmon/mirmon -c ./mirmon.conf -q -get update +/usr/bin/perl "${MIRMON}" -c "${CONFFILE}" -q -get update + # Set up a nice link to our mirror page directly: -[[ -d ../../htdocs/snapshots ]] || mkdir ../../htdocs/snapshots +mkdir -p ${HTDOCS} sed \ -e 's#mirrors</H2>#<a href="http://www.gentoo.org/main/en/mirrors2.xml">mirrors</a></H2>#' \ - >../../htdocs/snapshots/index.html <../../htdocs/snapshots/index-wip.html + >"${HTDOCS}"/index.html.tmp <"${HTDOCS}"/index-wip.html \ + && mv -f "${HTDOCS}"/index.html{.tmp,} + # Generate a json file containing the state of each mirror -../json/generate-json.py /var/www/mirrorstats.gentoo.org/gentoo-mirrorstats/snapshots_mirrors/var/mirmon.state \ - > ../../htdocs/snapshots/state.json +../json/generate-json.py \ + "${VARDIR}"/mirmon.state \ + >"${HTDOCS}"/state.json.tmp \ + && mv -f "${HTDOCS}"/state.json{.tmp,}