OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.0 KiB

# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: lib/sde-download/mirror-test.sh
# Copyright (C) 2006 - 2012 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
maxspeed=0 mirror=
[ -n "$SDEROOT" ] ||
export SDEROOT=$( cd "${0%/*}/../.."; pwd -P )
. $SDEROOT/lib/libsde.in
DC="$(type -p dc)"
div_dot2f()
{
if [ -n "$DC" ]; then
$DC -e "2k $1 $2 / p"
else
expr $(expr $1 \* 100) / $2 |
sed -e 's/\(..\)$/\.\1/'
fi
}
OLDIFS="$IFS" IFS=":"
while read name country admin url ; do
# translate $country
case "$country" in
cl) country="Chile" ;;
cr) country="Costa Rica" ;;
de) country="Germany" ;;
my) country="Malaysia" ;;
ro) country="Romania" ;;
esac
# no trailing /
url="${url%/}"
# test
echo -n "Testing <$name> ($country) ..." 1>&2
speed=$(curl -Ls -m 20 "$url/DOWNTEST" -w "%{http_code} %{speed_download}" -o /dev/null |
grep '^200 ' | cut -d' ' -f2- | sed -e 's:,:.:' -e 's:[\.,]...$::')
# compare
if [ "${speed:-0}" = "0" ]; then
echo ' failed' 1>&2
else
if [ $speed -lt 1024 ]; then
speedf="$speed B/s"
elif [ $speed -lt 1048576 ]; then
speedf="$(div_dot2f $speed 1024) KB/s"
else
speedf="$(div_dot2f $speed 1048576) MB/s"
fi
echo " $speedf" 1>&2
# and make a choice
if [ "$speed" -gt "$maxspeed" ]; then
maxspeed="$speed"; mirror="$url"
fi
fi
done < <( sed -e '/^#/d;' $1 )
IFS="$OLDIFS"
[ -n "$mirror" ] || mirror=broken
xpkgver=$("$SDEROOT/lib/version.sh" -p | tr '.' '_')
exec "$SDEROOT/bin/sde-config-ini" -F "$SDESETTINGS" \
"download-$xpkgver.mirror=$mirror" \
"download-$xpkgver.mirror_last=$(date +%s)"