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.

78 lines
1.9 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 - 2008 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. DC="$(type -p dc)"
  19. div_dot2f()
  20. {
  21. if [ -n "$DC" ]; then
  22. $DC -e "2k $1 $2 / p"
  23. else
  24. expr $(expr $1 \* 100) / $2 |
  25. sed -e 's/\(..\)$/\.\1/'
  26. fi
  27. }
  28. OLDIFS="$IFS" IFS=":"
  29. while read name country admin url ; do
  30. # translate $country
  31. case "$country" in
  32. cl) country="Chile" ;;
  33. cr) country="Costa Rica" ;;
  34. de) country="Germany" ;;
  35. my) country="Malaysia" ;;
  36. ro) country="Romania" ;;
  37. esac
  38. # no trailing /
  39. url="${url%/}"
  40. # test
  41. echo -n "Testing <$name> ($country) ..." 1>&2
  42. speed="$(curl -s -m 20 "$url/DOWNTEST" -w "%{speed_download}" -o /dev/null |
  43. sed -e 's:,:.:' -e 's:[\.,]...$::' )"
  44. # compare
  45. if [ "${speed:-0}" = "0" ]; then
  46. echo ' failed' 1>&2
  47. else
  48. if [ $speed -lt 1024 ]; then
  49. speedf="$speed B/s"
  50. elif [ $speed -lt 1048576 ]; then
  51. speedf="$(div_dot2f $speed 1024) KB/s"
  52. else
  53. speedf="$(div_dot2f $speed 1048576) MB/s"
  54. fi
  55. echo " $speedf" 1>&2
  56. # and make a choice
  57. if [ "$speed" -gt "$maxspeed" ]; then
  58. maxspeed="$speed"; mirror="$url"
  59. fi
  60. fi
  61. done < <( sed -e '/^#/d;' $1 )
  62. IFS="$OLDIFS"
  63. [ -n "$mirror" ] || mirror=broken
  64. exec "$SDEROOT/bin/sde-config-ini" -F "$SDESETTINGS" \
  65. "download-$sdever.mirror=$mirror" \
  66. "download-$sdever.mirror_last=$(date +%s)"