From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 097A8138351 for ; Wed, 29 Apr 2020 05:20:26 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 49022E094F; Wed, 29 Apr 2020 05:20:25 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 2545FE0949 for ; Wed, 29 Apr 2020 05:20:25 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id CD86034EF97 for ; Wed, 29 Apr 2020 05:20:18 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CBCD51F4 for ; Wed, 29 Apr 2020 05:20:16 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1588136974.3481f1fa6e8dba159ded86d4f09ea860e307049a.robbat2@gentoo> Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: / X-VCS-Repository: proj/gentoo-mirrorstats X-VCS-Files: mirmon-snapshots.sh mirmon-wrapper.sh X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: 3481f1fa6e8dba159ded86d4f09ea860e307049a X-VCS-Branch: master Date: Wed, 29 Apr 2020 05:20:16 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: abbdcbc3-beee-4ad0-b72b-2c105be47317 X-Archives-Hash: 7cb740b864bde723f18614aab21a1fe6 commit: 3481f1fa6e8dba159ded86d4f09ea860e307049a Author: Robin H. Johnson gentoo org> AuthorDate: Wed Apr 29 05:09:34 2020 +0000 Commit: Robin H. Johnson gentoo 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 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#mirrors#" \ - >"${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#mirrors#" \ + >"${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/