public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: /
Date: Thu, 30 Apr 2020 21:27:22 +0000 (UTC)	[thread overview]
Message-ID: <1588281998.6167a39af9568ec73795d2568f30a43d86d2381a.robbat2@gentoo> (raw)

commit:     6167a39af9568ec73795d2568f30a43d86d2381a
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 30 21:26:38 2020 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Thu Apr 30 21:26:38 2020 +0000
URL:        https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=6167a39a

mirmon-wrapper.sh: support debug/verbose/quiet

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 mirmon-wrapper.sh | 70 +++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 55 insertions(+), 15 deletions(-)

diff --git a/mirmon-wrapper.sh b/mirmon-wrapper.sh
index 74a12d6..04be5ce 100755
--- a/mirmon-wrapper.sh
+++ b/mirmon-wrapper.sh
@@ -2,24 +2,35 @@
 
 NAME=$(basename "$0")
 
-OPTIONS=(
+OPTIONS_STR=(
 	"mode"
 	"xml-src"
 	"url"
 )
+OPTIONS_BOOL=(
+	"help"
+	"debug"
+	"verbose"
+	"quiet"
+)
+
+
+helpmsg() {
+	echo "$*" 1>&2
+}
 
 usage() {
-	echo "Usage: ${NAME}$(printf " --%s=..." "${OPTIONS[@]}" )" 1>&2
+	helpmsg "Usage: ${NAME}$(printf " --%s=..." "${OPTIONS_STR[@]}" )$(printf " --%s" "${OPTIONS_BOOL[@]}")"
 	exit 3
 }
 
 dohelp() {
-	echo "${NAME} TODO" 1>&2
+	helpmsg "${NAME} TODO"
 	exit 0
 }
 
 die() {
-	echo "$*" 1>&2
+	helpmsg "$*"
 	exit 2
 }
 
@@ -34,7 +45,17 @@ main() {
 	VAR_GMIRRORS=${VARDIR}/g.mirrors
 	EXTRA_MIRRORS=${CONFDIR}/g.mirrors.extra
 	# Lock outselves
-	[ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "${VARDIR}/flock" "$0" "--xml-src=${XML_SRC}" "--mode=${MODE}" "--url=${URL}" || :
+	if [ "${FLOCKER}" != "$0" ]; then
+		exec \
+		env FLOCKER="$0" flock -en "${VARDIR}/flock" \
+		"$0" \
+		${DEBUG:+--debug} \
+		${QUIET:+--quiet} \
+		${VERBOSE:+--verbose} \
+		"--xml-src=${XML_SRC}" \
+		"--mode=${MODE}" \
+		"--url=${URL}"
+	fi
 
 	# Grab mirrors from the web
 	mkdir -p "${VARDIR}" "${HTDOCS}" || die "Failed to mkdir"
@@ -52,8 +73,16 @@ main() {
 		test -w "${VARDIR}/mirmon.state" || die "Cannot write state file!"
 	fi
 
+	MIRMON_OPTS=(
+		 -c "${CONFFILE}"
+		 -get update
+	)
+	[[ $VERBOSE -eq 1 ]] && MIRMON_OPTS+=( '-v' )
+	[[ $DEBUG -eq 1 ]] && MIRMON_OPTS+=( '-d' )
+	[[ $QUIET -eq 1 ]] && MIRMON_OPTS+=( '-q' )
+
 	# run mirmon
-	/usr/bin/perl "${MIRMON}" -c "${CONFFILE}" -q -get update || die "mirmon failed: $?"
+	/usr/bin/perl "${MIRMON}" "${MIRMON_OPTS[@]}" || die "mirmon failed: $?"
 
 	# Set up a nice link to our mirror page directly:
 	sed \
@@ -74,7 +103,8 @@ main() {
 }
 
 opts=$(getopt \
-	--longoptions "$(printf "%s:," "${OPTIONS[@]}" )" \
+	--longoptions "$(printf "%s:," "${OPTIONS_STR[@]}" )" \
+	--longoptions "$(printf "%s," "${OPTIONS_BOOL[@]}" )" \
 	--name "$(basename "$0")" \
 	--options "" \
 	-- "$@"
@@ -85,8 +115,10 @@ eval set --$opts
 MODE=''
 XML_SRC=''
 URL=''
-HELP=0
-INVALID=0
+HELP=
+DEBUG=
+VERBOSE=
+INVALID=
 
 while [[ $# -gt 0 ]]; do
     case "$1" in
@@ -104,6 +136,14 @@ while [[ $# -gt 0 ]]; do
             URL=$2
             shift 2
             ;;
+		--debug)
+			DEBUG=1
+			break
+			;;
+		--verbose)
+			VERBOSE=1
+			break
+			;;
 		--help)
 			HELP=1
 			break
@@ -143,12 +183,12 @@ for m in "${XML_SRC_INPUTS[@]}"; do
 done
 [[ $XML_SRC_VALID -eq 1 ]] || XML_SRC=''
 
-[[ -z "$MODE" ]] && die "--mode must be one of: ${MODE_INPUTS[*]}"
-[[ -z "$XML_SRC" ]] && die "--xml-src must be one of: ${XML_SRC_INPUTS[*]}"
-[[ -z "$URL" ]] && die "--url unset"
+[[ "$INVALID" == 1 ]] && usage
+[[ "$HELP" == 1 ]] && dohelp
 
-[[ $INVALID -eq 1 ]] && usage
-[[ $HELP -eq 1 ]] && dohelp
+if [[ -z "$MODE" ]]; then helpmsg "--mode must be one of: ${MODE_INPUTS[*]}" ; INVALID=1 ; fi
+if [[ -z "$XML_SRC" ]]; then helpmsg "--xml-src must be one of: ${XML_SRC_INPUTS[*]}" ; INVALID=1 ; fi
+if [[ -z "$URL" ]]; then helpmsg "--url unset" ; INVALID=1 ; fi
+[[ "$INVALID" == 1 ]] && usage
 
-OPTS=( ${opts} ) # for flock
 main


             reply	other threads:[~2020-04-30 21:27 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-30 21:27 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: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-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=1588281998.6167a39af9568ec73795d2568f30a43d86d2381a.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