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