Gentoo Archives: gentoo-commits

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/gentoo-mirrorstats:master commit in: /
Date: Thu, 30 Apr 2020 21:27:27
Message-Id: 1588281998.6167a39af9568ec73795d2568f30a43d86d2381a.robbat2@gentoo
1 commit: 6167a39af9568ec73795d2568f30a43d86d2381a
2 Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
3 AuthorDate: Thu Apr 30 21:26:38 2020 +0000
4 Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
5 CommitDate: Thu Apr 30 21:26:38 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/gentoo-mirrorstats.git/commit/?id=6167a39a
7
8 mirmon-wrapper.sh: support debug/verbose/quiet
9
10 Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
11
12 mirmon-wrapper.sh | 70 +++++++++++++++++++++++++++++++++++++++++++------------
13 1 file changed, 55 insertions(+), 15 deletions(-)
14
15 diff --git a/mirmon-wrapper.sh b/mirmon-wrapper.sh
16 index 74a12d6..04be5ce 100755
17 --- a/mirmon-wrapper.sh
18 +++ b/mirmon-wrapper.sh
19 @@ -2,24 +2,35 @@
20
21 NAME=$(basename "$0")
22
23 -OPTIONS=(
24 +OPTIONS_STR=(
25 "mode"
26 "xml-src"
27 "url"
28 )
29 +OPTIONS_BOOL=(
30 + "help"
31 + "debug"
32 + "verbose"
33 + "quiet"
34 +)
35 +
36 +
37 +helpmsg() {
38 + echo "$*" 1>&2
39 +}
40
41 usage() {
42 - echo "Usage: ${NAME}$(printf " --%s=..." "${OPTIONS[@]}" )" 1>&2
43 + helpmsg "Usage: ${NAME}$(printf " --%s=..." "${OPTIONS_STR[@]}" )$(printf " --%s" "${OPTIONS_BOOL[@]}")"
44 exit 3
45 }
46
47 dohelp() {
48 - echo "${NAME} TODO" 1>&2
49 + helpmsg "${NAME} TODO"
50 exit 0
51 }
52
53 die() {
54 - echo "$*" 1>&2
55 + helpmsg "$*"
56 exit 2
57 }
58
59 @@ -34,7 +45,17 @@ main() {
60 VAR_GMIRRORS=${VARDIR}/g.mirrors
61 EXTRA_MIRRORS=${CONFDIR}/g.mirrors.extra
62 # Lock outselves
63 - [ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "${VARDIR}/flock" "$0" "--xml-src=${XML_SRC}" "--mode=${MODE}" "--url=${URL}" || :
64 + if [ "${FLOCKER}" != "$0" ]; then
65 + exec \
66 + env FLOCKER="$0" flock -en "${VARDIR}/flock" \
67 + "$0" \
68 + ${DEBUG:+--debug} \
69 + ${QUIET:+--quiet} \
70 + ${VERBOSE:+--verbose} \
71 + "--xml-src=${XML_SRC}" \
72 + "--mode=${MODE}" \
73 + "--url=${URL}"
74 + fi
75
76 # Grab mirrors from the web
77 mkdir -p "${VARDIR}" "${HTDOCS}" || die "Failed to mkdir"
78 @@ -52,8 +73,16 @@ main() {
79 test -w "${VARDIR}/mirmon.state" || die "Cannot write state file!"
80 fi
81
82 + MIRMON_OPTS=(
83 + -c "${CONFFILE}"
84 + -get update
85 + )
86 + [[ $VERBOSE -eq 1 ]] && MIRMON_OPTS+=( '-v' )
87 + [[ $DEBUG -eq 1 ]] && MIRMON_OPTS+=( '-d' )
88 + [[ $QUIET -eq 1 ]] && MIRMON_OPTS+=( '-q' )
89 +
90 # run mirmon
91 - /usr/bin/perl "${MIRMON}" -c "${CONFFILE}" -q -get update || die "mirmon failed: $?"
92 + /usr/bin/perl "${MIRMON}" "${MIRMON_OPTS[@]}" || die "mirmon failed: $?"
93
94 # Set up a nice link to our mirror page directly:
95 sed \
96 @@ -74,7 +103,8 @@ main() {
97 }
98
99 opts=$(getopt \
100 - --longoptions "$(printf "%s:," "${OPTIONS[@]}" )" \
101 + --longoptions "$(printf "%s:," "${OPTIONS_STR[@]}" )" \
102 + --longoptions "$(printf "%s," "${OPTIONS_BOOL[@]}" )" \
103 --name "$(basename "$0")" \
104 --options "" \
105 -- "$@"
106 @@ -85,8 +115,10 @@ eval set --$opts
107 MODE=''
108 XML_SRC=''
109 URL=''
110 -HELP=0
111 -INVALID=0
112 +HELP=
113 +DEBUG=
114 +VERBOSE=
115 +INVALID=
116
117 while [[ $# -gt 0 ]]; do
118 case "$1" in
119 @@ -104,6 +136,14 @@ while [[ $# -gt 0 ]]; do
120 URL=$2
121 shift 2
122 ;;
123 + --debug)
124 + DEBUG=1
125 + break
126 + ;;
127 + --verbose)
128 + VERBOSE=1
129 + break
130 + ;;
131 --help)
132 HELP=1
133 break
134 @@ -143,12 +183,12 @@ for m in "${XML_SRC_INPUTS[@]}"; do
135 done
136 [[ $XML_SRC_VALID -eq 1 ]] || XML_SRC=''
137
138 -[[ -z "$MODE" ]] && die "--mode must be one of: ${MODE_INPUTS[*]}"
139 -[[ -z "$XML_SRC" ]] && die "--xml-src must be one of: ${XML_SRC_INPUTS[*]}"
140 -[[ -z "$URL" ]] && die "--url unset"
141 +[[ "$INVALID" == 1 ]] && usage
142 +[[ "$HELP" == 1 ]] && dohelp
143
144 -[[ $INVALID -eq 1 ]] && usage
145 -[[ $HELP -eq 1 ]] && dohelp
146 +if [[ -z "$MODE" ]]; then helpmsg "--mode must be one of: ${MODE_INPUTS[*]}" ; INVALID=1 ; fi
147 +if [[ -z "$XML_SRC" ]]; then helpmsg "--xml-src must be one of: ${XML_SRC_INPUTS[*]}" ; INVALID=1 ; fi
148 +if [[ -z "$URL" ]]; then helpmsg "--url unset" ; INVALID=1 ; fi
149 +[[ "$INVALID" == 1 ]] && usage
150
151 -OPTS=( ${opts} ) # for flock
152 main