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.

52 lines
1.4 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 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. SDEROOT=$PWD
  16. . $SDEROOT/lib/libsde.in
  17. . $SDEROOT/lib/libsde-ini.in # to write
  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. esac
  26. # no trailing /
  27. url="${url%/}"
  28. # test
  29. echo -n "Testing <$name> ($country) ..." 1>&2
  30. speed="$(curl -s -m 20 "$url/DOWNTEST" -w "%{speed_download}" -o /dev/null |
  31. sed -e 's:,:.:' -e 's:[\.,]...$::' )"
  32. # compare
  33. if [ "${speed:-0}" == "0" ]; then
  34. echo ' failed' 1>&2
  35. else
  36. echo " $speed B/s" 1>&2
  37. # and make a choice
  38. if [ "$speed" -gt "$maxspeed" ]; then
  39. maxspeed="$speed"; mirror="$url"
  40. fi
  41. fi
  42. done < <( sed -e '/^#/d;' $1 )
  43. IFS="$OLDIFS"
  44. [ -n "$mirror" ] || mirror=broken
  45. ini_write "$SDESETTINGS" "download-$sdever" mirror