[pacman-dev] Fwd: [PATCH] rankmirrors: Add a --repo option to target a specific repo
--- scripts/rankmirrors.sh.in | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/rankmirrors.sh.in b/scripts/rankmirrors.sh.in index d5cbadd..9838a2a 100644 --- a/scripts/rankmirrors.sh.in +++ b/scripts/rankmirrors.sh.in @@ -35,6 +35,7 @@ usage() { echo " -t, --times only output mirrors and their response times" echo " -u, --url test a specific url" echo " -v, --verbose be verbose in ouptut" + echo " -r, --repo specify a specific repo name instead of guessing" exit 0 } @@ -69,13 +70,18 @@ ARCH="$(uname -m)" getfetchurl() { local strippedurl="${1%/}" - local replacedurl="${strippedurl//'$repo'/core}" - replacedurl="${replacedurl//'$arch'/$ARCH}" + local replacedurl="${replacedurl//'$arch'/$ARCH}" + if [[ $TARGETREPO = auto ]]; then + replacedurl="${strippedurl//'$repo'/core}" + local tmp="${replacedurl%/*}" + tmp="${tmp%/*}" - local tmp="${replacedurl%/*}" - tmp="${tmp%/*}" + local reponame="${tmp##*/}" + else + replacedurl="${strippedurl//'$repo'/$TARGETREPO}" + local reponame="$TARGETREPO" + fi - local reponame="${tmp##*/}" if [[ -z $reponame || $reponame = $replacedurl ]]; then echo "fail" else @@ -119,6 +125,7 @@ while [[ $1 ]]; do times) TIMESONLY=1 ; shift ;; verbose) VERBOSE=1 ; shift ;; url) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; shift 2;; + repo) [[ $2 ]] || err "Must specify repo name."; TARGETREPO="$2"; shift 2;; *) err "\`$1' is an invalid argument." esac elif [[ ${1:0:1} = - ]]; then @@ -136,6 +143,7 @@ while [[ $1 ]]; do t) TIMESONLY=1 ;; v) VERBOSE=1 ;; u) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; snum=2;; + r) [[ $2 ]] || err "Must specify repo name."; TARGETREPO="$2"; snum=2;; n) [[ $2 ]] || err "Must specify number." ; NUM="$2" ; snum=2;; *) err "\`-$1' is an invald argument." ;; esac @@ -156,6 +164,7 @@ done [[ $NUM ]] || NUM=0 [[ $FILE && $CHECKURL ]] && err "Cannot specify a url and mirrorfile." [[ $FILE || $CHECKURL || $STDIN ]] || err "Must specify url, mirrorfile, or stdin." +[[ $TARGETREPO ]] || TARGETREPO=auto # Single url handling if [[ $CHECKURL ]]; then @@ -182,6 +191,7 @@ for line in "${linearray[@]}"; do # Getting values and times and such server="${line#*= }" + server=$(echo $server | awk '{print $1}') url="$(getfetchurl "$server")" [[ $url = fail ]] && err "url \`$URL' is malformed." time=$(gettime "$url") -- 1.7.0
On Thu, Mar 25, 2010 at 12:45 PM, Daenyth Blank <daenyth+arch@gmail.com> wrote:
--- scripts/rankmirrors.sh.in | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/scripts/rankmirrors.sh.in b/scripts/rankmirrors.sh.in index d5cbadd..9838a2a 100644 --- a/scripts/rankmirrors.sh.in +++ b/scripts/rankmirrors.sh.in @@ -35,6 +35,7 @@ usage() { echo " -t, --times only output mirrors and their response times" echo " -u, --url test a specific url" echo " -v, --verbose be verbose in ouptut" + echo " -r, --repo specify a specific repo name instead of guessing" exit 0 }
@@ -69,13 +70,18 @@ ARCH="$(uname -m)" getfetchurl() { local strippedurl="${1%/}"
- local replacedurl="${strippedurl//'$repo'/core}" - replacedurl="${replacedurl//'$arch'/$ARCH}" + local replacedurl="${replacedurl//'$arch'/$ARCH}" + if [[ $TARGETREPO = auto ]]; then Use quotes around vars and text strings please.
+ replacedurl="${strippedurl//'$repo'/core}" + local tmp="${replacedurl%/*}" + tmp="${tmp%/*}"
- local tmp="${replacedurl%/*}" - tmp="${tmp%/*}" + local reponame="${tmp##*/}" + else + replacedurl="${strippedurl//'$repo'/$TARGETREPO}" + local reponame="$TARGETREPO" + fi
- local reponame="${tmp##*/}" if [[ -z $reponame || $reponame = $replacedurl ]]; then echo "fail" else @@ -119,6 +125,7 @@ while [[ $1 ]]; do times) TIMESONLY=1 ; shift ;; verbose) VERBOSE=1 ; shift ;; url) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; shift 2;; + repo) [[ $2 ]] || err "Must specify repo name."; TARGETREPO="$2"; shift 2;; *) err "\`$1' is an invalid argument." esac elif [[ ${1:0:1} = - ]]; then @@ -136,6 +143,7 @@ while [[ $1 ]]; do t) TIMESONLY=1 ;; v) VERBOSE=1 ;; u) CHECKURL=1; [[ $2 ]] || err "Must specify url."; URL="$2"; snum=2;; + r) [[ $2 ]] || err "Must specify repo name."; TARGETREPO="$2"; snum=2;; n) [[ $2 ]] || err "Must specify number." ; NUM="$2" ; snum=2;; *) err "\`-$1' is an invald argument." ;; esac @@ -156,6 +164,7 @@ done [[ $NUM ]] || NUM=0 [[ $FILE && $CHECKURL ]] && err "Cannot specify a url and mirrorfile." [[ $FILE || $CHECKURL || $STDIN ]] || err "Must specify url, mirrorfile, or stdin." +[[ $TARGETREPO ]] || TARGETREPO=auto Quotes again.
# Single url handling if [[ $CHECKURL ]]; then @@ -182,6 +191,7 @@ for line in "${linearray[@]}"; do
# Getting values and times and such server="${line#*= }" + server=$(echo $server | awk '{print $1}')
What is this for? I'm suspecting it is an attempt at comment stripping or something, but Server = http://example.org/path/to/repo# you lose will still bite you. And I don't think the call to an external program is necessary here. Stay in shell with maybe something like # strip the longest substring off the end starting with '#' server="${server%%#*}"
url="$(getfetchurl "$server")" [[ $url = fail ]] && err "url \`$URL' is malformed." time=$(gettime "$url") -- 1.7.0
participants (2)
-
Daenyth Blank
-
Dan McGee