From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: /
Date: Wed, 29 Apr 2020 05:20:16 +0000 (UTC) [thread overview]
Message-ID: <1588136974.3481f1fa6e8dba159ded86d4f09ea860e307049a.robbat2@gentoo> (raw)
commit: 3481f1fa6e8dba159ded86d4f09ea860e307049a
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 29 05:09:34 2020 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Wed Apr 29 05:09:34 2020 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=3481f1fa
Convert refactored runner to wrapper
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
mirmon-snapshots.sh | 44 ------------------
mirmon-wrapper.sh | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 44 deletions(-)
diff --git a/mirmon-snapshots.sh b/mirmon-snapshots.sh
deleted file mode 100755
index 5a5c127..0000000
--- a/mirmon-snapshots.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/bash
-
-set -e
-
-MODE=snapshots
-SRC=distfiles
-SITEDIR=/var/www/mirrorstats.gentoo.org
-REPODIR=${SITEDIR}/gentoo-mirrorstats/
-MODEDIR=${REPODIR}/${MODE}_mirrors/
-VARDIR=${SITEDIR}/var/${MODE}
-HTDOCS=${SITEDIR}/htdocs/${MODE}
-MIRMON=$(readlink -f "${SITEDIR}"/mirmon/mirmon)
-CONFFILE=$(readlink -f "${MODEDIR}"/mirmon.conf)
-VAR_GMIRRORS=${VARDIR}/g.mirrors
-URL=https://www.gentoo.org/downloads/mirrors/
-
-# Grab mirrors from the web
-mkdir -p "${VARDIR}"
-"${REPODIR}"/get-mirrors-from-${SRC}-xml.rb > "${VAR_GMIRRORS}".tmp
-
-EXTRA_MIRRORS=${MODEDIR}/g.mirrors.extra
-[[ -e "${EXTRA_MIRRORS}" ]] && cat "${EXTRA_MIRRORS}" >>"${VAR_GMIRRORS}".tmp
-
-# Atomic rotate into place
-mv -f "${VAR_GMIRRORS}"{.tmp,}
-
-# fatal if the state file is NOT present.
-[[ -e ${VARDIR}/mirmon.state ]] || touch "${VARDIR}/mirmon.state"
-
-# run mirmon
-/usr/bin/perl "${MIRMON}" -c "${CONFFILE}" -q -get update
-
-# Set up a nice link to our mirror page directly:
-mkdir -p ${HTDOCS}
-sed \
- -e "s#mirrors</H2>#<a href="${URL}">mirrors</a></H2>#" \
- >"${HTDOCS}"/index.html.tmp <"${HTDOCS}"/index-wip.html \
- && mv -f "${HTDOCS}"/index.html{.tmp,}
-
-# Generate a json file containing the state of each mirror
-"${REPODIR}"/generate-json.py \
- "${VARDIR}"/mirmon.state \
- >"${HTDOCS}"/state.json.tmp \
- && mv -f "${HTDOCS}"/state.json{.tmp,}
diff --git a/mirmon-wrapper.sh b/mirmon-wrapper.sh
new file mode 100755
index 0000000..ba731c6
--- /dev/null
+++ b/mirmon-wrapper.sh
@@ -0,0 +1,125 @@
+#!/bin/bash -e
+
+NAME=$(basename "$0")
+
+OPTIONS=(
+ "mode"
+ "xml-src"
+ "url"
+)
+
+usage() {
+ echo "Usage: ${NAME}$(printf " --%s=..." "${OPTIONS[@]}" )" 1>&2
+ exit 3
+}
+
+dohelp() {
+ echo "${NAME} TODO" 1>&2
+ exit 0
+}
+
+die() {
+ echo "$*" 1>&2
+ exit 2
+}
+
+main() {
+ [[ -z "$MODE" ]] && die "--mode unset"
+ [[ -z "$XML_SRC" ]] && die "--xml-src unset"
+ [[ -z "$URL" ]] && die "--url unset"
+ SITEDIR=/var/www/mirrorstats.gentoo.org
+ REPODIR=${SITEDIR}/gentoo-mirrorstats/
+ MODEDIR=${REPODIR}/${MODE}_mirrors/
+ VARDIR=${SITEDIR}/var/${MODE}
+ HTDOCS=${SITEDIR}/htdocs/${MODE}
+ MIRMON=$(readlink -f "${SITEDIR}"/mirmon/mirmon)
+ CONFFILE=$(readlink -f "${MODEDIR}"/mirmon.conf)
+ VAR_GMIRRORS=${VARDIR}/g.mirrors
+
+ # Grab mirrors from the web
+ mkdir -p "${VARDIR}"
+ "${REPODIR}"/get-mirrors-from-${XML_SRC}-xml.rb > "${VAR_GMIRRORS}".tmp
+
+ EXTRA_MIRRORS=${MODEDIR}/g.mirrors.extra
+ [[ -e "${EXTRA_MIRRORS}" ]] && cat "${EXTRA_MIRRORS}" >>"${VAR_GMIRRORS}".tmp
+
+ # Atomic rotate into place
+ mv -f "${VAR_GMIRRORS}"{.tmp,}
+
+ # fatal if the state file is NOT present.
+ [[ -e ${VARDIR}/mirmon.state ]] || touch "${VARDIR}/mirmon.state"
+
+ # run mirmon
+ /usr/bin/perl "${MIRMON}" -c "${CONFFILE}" -q -get update
+
+ # Set up a nice link to our mirror page directly:
+ mkdir -p ${HTDOCS}
+ sed \
+ -e "s#mirrors</H2>#<a href="${URL}">mirrors</a></H2>#" \
+ >"${HTDOCS}"/index.html.tmp <"${HTDOCS}"/index-wip.html \
+ && mv -f "${HTDOCS}"/index.html{.tmp,}
+
+ # Generate a json file containing the state of each mirror
+ "${REPODIR}"/generate-json.py \
+ "${VARDIR}"/mirmon.state \
+ >"${HTDOCS}"/state.json.tmp \
+ && mv -f "${HTDOCS}"/state.json{.tmp,}
+
+ # Done
+ exit 0
+}
+
+opts=$(getopt \
+ --longoptions "$(printf "%s:," "${OPTIONS[@]}" )" \
+ --name "$(basename "$0")" \
+ --options "" \
+ -- "$@"
+)
+
+eval set --$opts
+
+MODE=''
+XML_SRC=''
+URL=''
+HELP=0
+INVALID=0
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --mode)
+ MODE=$2
+ shift 2
+ ;;
+
+ --xml-src)
+ XML_SRC=$2
+ shift 2
+ ;;
+
+ --url)
+ URL=$2
+ shift 2
+ ;;
+ --help)
+ HELP=1
+ break
+ ;;
+ --)
+ # End of options
+ break
+ ;;
+ *)
+ INVALID=1
+ break
+ ;;
+ esac
+done
+
+[[ $INVALID -eq 1 ]] && usage
+[[ $HELP -eq 1 ]] && dohelp
+
+main
+
+#MODE=snapshots
+#XML_SRC=distfiles
+#URL=https://www.gentoo.org/downloads/mirrors/
next reply other threads:[~2020-04-29 5:20 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 5:20 Robin H. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-03-22 17:44 [gentoo-commits] proj/gentoo-mirrorstats:master commit in: / Robin H. Johnson
2023-03-22 16:29 Robin H. Johnson
2023-03-22 16:29 Robin H. Johnson
2020-05-01 17:59 Robin H. Johnson
2020-04-30 22:59 Robin H. Johnson
2020-04-30 22:56 Robin H. Johnson
2020-04-30 22:56 Robin H. Johnson
2020-04-30 22:52 Robin H. Johnson
2020-04-30 22:17 Robin H. Johnson
2020-04-30 21:27 Robin H. Johnson
2020-04-30 21:27 Robin H. Johnson
2020-04-30 21:11 Robin H. Johnson
2020-04-30 20:29 Robin H. Johnson
2020-04-30 6:31 Robin H. Johnson
2020-04-30 6:02 Robin H. Johnson
2020-04-29 6:45 Robin H. Johnson
2020-04-29 6:39 Robin H. Johnson
2020-04-29 5:48 Robin H. Johnson
2020-04-29 5:41 Robin H. Johnson
2020-04-29 5:33 Robin H. Johnson
2020-04-29 5:20 Robin H. Johnson
2020-04-29 5:20 Robin H. Johnson
2020-04-28 23:21 Robin H. Johnson
2020-04-28 23:21 Robin H. Johnson
2020-04-28 17:42 Robin H. Johnson
2020-04-28 17:34 Robin H. Johnson
2020-04-28 16:46 Robin H. Johnson
2020-04-28 7:54 Robin H. Johnson
2018-12-15 18:57 Alec Warner
2016-11-05 18:02 Robin H. Johnson
2014-02-12 3:44 Jeremy Olexa
2013-08-28 2:28 Alec Warner
2013-08-27 9:08 Alec Warner
2012-12-25 17:22 Jeremy Olexa
2012-12-22 10:46 Jeremy Olexa
2012-09-18 16:17 Jeremy Olexa
2012-06-20 21:05 Jeremy Olexa
2012-02-24 18:45 Jeremy Olexa
2011-06-02 13:48 Jeremy Olexa
2011-05-19 15:09 Jeremy Olexa
2011-05-19 15:09 Jeremy Olexa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1588136974.3481f1fa6e8dba159ded86d4f09ea860e307049a.robbat2@gentoo \
--to=robbat2@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox