[PATCH] rankmirrors: add --max-time option

Johannes Löthberg johannes at kyriasis.com
Fri Jul 6 19:06:40 UTC 2018


Quoting Sami Kerola (2018-06-08 23:05:25)
> When testing all known mirrors, and knowing you have fairly ok connectivity,
> it's nice to have ability to define more aggressive timeout, such as 0.1
> This way finding a small number of best mirrors will take a little bit less
> time in total.
> 
> Signed-off-by: Sami Kerola <kerolasa at iki.fi>
> ---
>  src/rankmirrors.sh.in | 26 ++++++++++++++++++--------
>  1 file changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/src/rankmirrors.sh.in b/src/rankmirrors.sh.in
> index 7f518c0..faa4074 100644
> --- a/src/rankmirrors.sh.in
> +++ b/src/rankmirrors.sh.in
> @@ -34,13 +34,14 @@ usage() {
>         echo "Usage: ${myname} [options] MIRRORFILE | URL"
>         echo
>         echo "Options:"
> -       echo "  --version      show program's version number and exit"
> -       echo "  -h, --help     show this help message and exit"
> -       echo "  -n NUM         number of servers to output, 0 for all"
> -       echo "  -t, --times    only output mirrors and their response times"
> -       echo "  -u, --url      test a specific URL"
> -       echo "  -v, --verbose  be verbose in output"
> -       echo "  -r, --repo     specify a repository name instead of guessing"
> +       echo "  --version           show program's version number and exit"
> +       echo "  -h, --help          show this help message and exit"
> +       echo "  -n NUM              number of servers to output, 0 for all"
> +       echo "  -m, --max-time NUM  specify a ranking operation timeout, can be desimal number"
> +       echo "  -t, --times         only output mirrors and their response times"
> +       echo "  -u, --url           test a specific URL"
> +       echo "  -v, --verbose       be verbose in output"
> +       echo "  -r, --repo          specify a repository name instead of guessing"
>         exit 0
>  }
>  
> @@ -61,7 +62,7 @@ err() {
>  # gettime fetchurl (e.g gettime http://foo.com/core/os/i686/core.db.tar.gz)
>  # returns the fetching time, or timeout, or unreachable
>  gettime() {
> -       IFS=' ' output=( $(curl -s -m 10 -w "%{time_total} %{http_code}" "$1" -o/dev/null) )
> +       IFS=' ' output=( $(curl -s -m $MAX_TIME -w "%{time_total} %{http_code}" "$1" -o/dev/null) )
>         (( $? == 28 )) && echo timeout && return
>         (( ${output[1]} >= 400 || ! ${output[1]} )) && echo unreachable && return
>         echo "${output[0]}"
> @@ -128,6 +129,10 @@ while [[ $1 ]]; do
>                 case "${1:2}" in
>                         help) usage ;;
>                         version) version ;;
> +                       max-time)
> +                               [[ $2 ]] || err "Must specify number.";
> +                               MAX_TIME="$2"
> +                               shift 2;;
>                         times) TIMESONLY=1 ; shift ;;
>                         verbose) VERBOSE=1 ; shift ;;
>                         url)
> @@ -153,6 +158,10 @@ while [[ $1 ]]; do
>                         for ((i=1 ; i<${#1}; i++)); do
>                                 case ${1:$i:1} in
>                                         h) usage ;;
> +                                       m)
> +                                               [[ $2 ]] || err "Must specify number.";
> +                                               MAX_TIME="$2"
> +                                               shift 2;;
>                                         t) TIMESONLY=1 ;;
>                                         v) VERBOSE=1 ;;
>                                         u)
> @@ -185,6 +194,7 @@ done
>  
>  # Some sanity checks
>  [[ $NUM ]] || NUM=0
> +[[ $MAX_TIME ]] || MAX_TIME=10
>  [[ $FILE && $CHECKURL ]] && err "Cannot specify a URL and mirrorfile."
>  [[ $FILE || $CHECKURL || $STDIN ]] || err "Must specify URL, mirrorfile, or stdin."
>  
> -- 
> 2.17.1

Fixed the desimal typo and merged.

-- 
Sincerely,
  Johannes Löthberg
  PGP Key ID: 0x50FB9B273A9D0BB5
  PGP Key FP: 5134 EF9E AF65 F95B 6BB1  608E 50FB 9B27 3A9D 0BB5
  https://theos.kyriasis.com/~kyrias/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 1727 bytes
Desc: signature
URL: <https://lists.archlinux.org/pipermail/pacman-contrib/attachments/20180706/2f7e1789/attachment.asc>


More information about the pacman-contrib mailing list