fetch-all 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # Download all current v2 directory status documents, then download
  3. # the descriptors and extra info documents.
  4. # Copyright (c) 2005, 2006, 2007, 2008 Peter Palfrader
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. TZ=UTC
  24. export TZ
  25. DIRSERVERS=""
  26. DIRSERVERS="$DIRSERVERS 86.59.21.38:80" # tor26
  27. DIRSERVERS="$DIRSERVERS 128.31.0.34:9031" # moria1
  28. DIRSERVERS="$DIRSERVERS 128.31.0.34:9032" # moria2
  29. DIRSERVERS="$DIRSERVERS 194.109.206.212:80" # dizum
  30. DATEDIR=$(date "+%Y/%m/%d")
  31. TIME=$(date "+%Y%m%d-%H%M%S")
  32. . fetch-all-functions
  33. statuses=""
  34. for dirserver in $DIRSERVERS; do
  35. authorities=$(wget -q -O - http://$dirserver/tor/status/all | egrep '^fingerprint ' | awk '{print $2}')
  36. if [ "$authorities" == "" ]; then
  37. echo "Did not get a list of authorities from $dirserver, going to next" 2>&1
  38. continue
  39. fi
  40. dir="status/$DATEDIR"
  41. [ -d "$dir" ] || mkdir -p "$dir"
  42. authprefix="$dir/$TIME-"
  43. for fp in $authorities; do
  44. wget -q -O "$authprefix$fp" http://$dirserver/tor/status/fp/"$fp"
  45. bzip2 "$authprefix$fp"
  46. statuses="$statuses $authprefix$fp.bz2"
  47. done
  48. if [ "$statuses" == "" ]; then
  49. echo "Did not get any statuses from $dirserver, going to next" 2>&1
  50. continue
  51. else
  52. break
  53. fi
  54. done
  55. if [ "$statuses" = "" ]; then
  56. echo "No statuses available" 2>&1
  57. exit 1
  58. fi
  59. digests=$( for i in ` bzcat $statuses | awk '$1 == "r" {printf "%s=\n", $4}' | sort -u `; do
  60. echo $i | \
  61. base64-decode | \
  62. perl -e 'undef $/; $a=<>; print unpack("H\*", $a),"\n";';
  63. done )
  64. for digest in $digests; do
  65. fetch_digest "$digest" "server-descriptor"
  66. done