]> git.xonotic.org Git - xonotic/xonotic.git/commitdiff
new command: ./all update -l best - switches to the best available mirror
authorRudolf Polzer <divverent@alientrap.org>
Sun, 7 Nov 2010 18:20:42 +0000 (19:20 +0100)
committerRudolf Polzer <divverent@alientrap.org>
Sun, 7 Nov 2010 18:20:42 +0000 (19:20 +0100)
all

diff --git a/all b/all
index 396002126ea551194d4cad2ef718fcc7f3aa5681..287dfdced62b10fc1da61d7d20b3c0e7573251d0 100755 (executable)
--- a/all
+++ b/all
@@ -339,6 +339,39 @@ mkzip0()
        zip -0y "$@"
 }
 
+mirrorspeed()
+{
+       # first result is to be ignored, but we use it to check status
+       git ls-remote "$1" refs/heads/master >/dev/null 2>&1 || return 1
+       time -p git ls-remote "$1" refs/heads/master 2>&1 >/dev/null | head -n 1 | cut -d ' ' -f 2 | tr -d . | sed 's,^0*,,'
+               # unit: clock ticks (depends on what "time" returns
+}
+
+bestmirror()
+{
+       pre=$1; shift
+       suf=$1; shift
+
+       bestin=
+       bestt=
+       for in in "$@"; do
+               m=$pre$in$suf
+               if t=`mirrorspeed "$m"`; then
+                       msg "$m -> $t ticks"
+                       if [ -n "$t" ]; then
+                               if [ -z "$bestt" ] || [ "$t" -lt "$bestt" ]; then
+                                       bestin=$in
+                                       bestt=$t
+                               fi
+                       fi
+               else
+                       msg "$m -> FAIL"
+               fi
+       done
+       msg "Best mirror seems to be $pre$bestin$suf"
+       echo "$bestin"
+}
+
 case "$cmd" in
        fix_upstream_rebase)
                for d in $repos; do
@@ -438,12 +471,14 @@ case "$cmd" in
                                case "$2" in
                                        nl) ;;
                                        de) ;;
+                                       best) ;;
                                        default) ;;
                                        *)
                                                msg "Invalid location!"
                                                msg "Possible locations for the -l option:"
                                                msg "  nl (Netherlands, run by merlijn)"
                                                msg "  de (Germany, run by divVerent)"
+                                               msg "  best (find automatically)"
                                                msg "  default (currently nl)"
                                                exit 1
                                                ;;
@@ -471,6 +506,17 @@ case "$cmd" in
                                                ;;
                                esac
                                ;;
+                       best)
+                               base=`echo "$base" | sed "s,://\(.*\.\)\?git.xonotic.org/,:// .git.xonotic.org/,"`
+                               case "$base" in
+                                       *\ *)
+                                               location=`bestmirror $base"xonotic.git" de nl`
+                                               ;;
+                                       *)
+                                               location=
+                                               ;;
+                               esac
+                               ;;
                esac
                if [ -n "$location" ]; then
                        base=`echo "$base" | sed "s,://\(.*\.\)\?git.xonotic.org/,://$location.git.xonotic.org/,"`