From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1166602-garchives=archives.gentoo.org@lists.gentoo.org>
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 4BC59138350
	for <garchives@archives.gentoo.org>; Thu, 30 Apr 2020 21:27:27 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 8F486E09D6;
	Thu, 30 Apr 2020 21:27:26 +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 6B6A6E09D6
	for <gentoo-commits@lists.gentoo.org>; Thu, 30 Apr 2020 21:27:26 +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 4A2BB34F08C
	for <gentoo-commits@lists.gentoo.org>; Thu, 30 Apr 2020 21:27:25 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id A6A0E1DD
	for <gentoo-commits@lists.gentoo.org>; Thu, 30 Apr 2020 21:27:22 +0000 (UTC)
From: "Robin H. Johnson" <robbat2@gentoo.org>
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" <robbat2@gentoo.org>
Message-ID: <1588281998.6167a39af9568ec73795d2568f30a43d86d2381a.robbat2@gentoo>
Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: /
X-VCS-Repository: proj/gentoo-mirrorstats
X-VCS-Files: mirmon-wrapper.sh
X-VCS-Directories: /
X-VCS-Committer: robbat2
X-VCS-Committer-Name: Robin H. Johnson
X-VCS-Revision: 6167a39af9568ec73795d2568f30a43d86d2381a
X-VCS-Branch: master
Date: Thu, 30 Apr 2020 21:27:22 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 3d5ba3be-1771-4112-a714-92bf4288dada
X-Archives-Hash: 285820dff540f2e516c2d8e6c8d19580

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