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.

55 lines
1.5 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-download/mirror-test.sh
  5. # Copyright (C) 2006 - 2007 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License. A copy of the
  12. # GNU General Public License can be found in the file COPYING.
  13. # --- SDE-COPYRIGHT-NOTE-END ---
  14. maxspeed=0 mirror=
  15. [ -n "$SDEROOT" ] ||
  16. export SDEROOT=$( cd "${0%/*}/../.."; pwd -P )
  17. . $SDEROOT/lib/libsde.in
  18. OLDIFS="$IFS" IFS=":"
  19. while read name country admin url ; do
  20. # translate $country
  21. case "$country" in
  22. cl) country="Chile" ;;
  23. cr) country="Costa Rica" ;;
  24. de) country="Germany" ;;
  25. my) country="Malaysia" ;;
  26. esac
  27. # no trailing /
  28. url="${url%/}"
  29. # test
  30. echo -n "Testing <$name> ($country) ..." 1>&2
  31. speed="$(curl -s -m 20 "$url/DOWNTEST" -w "%{speed_download}" -o /dev/null |
  32. sed -e 's:,:.:' -e 's:[\.,]...$::' )"
  33. # compare
  34. if [ "${speed:-0}" == "0" ]; then
  35. echo ' failed' 1>&2
  36. else
  37. echo " $speed B/s" 1>&2
  38. # and make a choice
  39. if [ "$speed" -gt "$maxspeed" ]; then
  40. maxspeed="$speed"; mirror="$url"
  41. fi
  42. fi
  43. done < <( sed -e '/^#/d;' $1 )
  44. IFS="$OLDIFS"
  45. [ -n "$mirror" ] || mirror=broken
  46. $SDEROOT/bin/sde-config-ini -F "$SDESETTINGS" "download-$sdever.mirror=$mirror"