-
Notifications
You must be signed in to change notification settings - Fork 0
/
feast.sh
executable file
·97 lines (84 loc) · 2.43 KB
/
feast.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# feast.sh: distributed delicious mirroring script
SERVER=
cannibal=./cannibal.sh
while getopts :u: OPT; do
case $OPT in
u)
USERNAME="$OPTARG"
;;
*)
echo "usage: `basename $0` [-u USERNAME]"
exit 1;
esac
done
warning() {
echo "$0: $*" >&2
}
error() {
echo "$0: $*" >&2
exit 2
}
if [ -z $USERNAME ]; then
error "You must supply a username with the -u option before you can begin"
fi
if [ ! -f $cannibal ]; then
error "Couldn't find cannibal.sh; are you sure you cloned everything from the git repository?"
fi
EXTERN_IP=`curl --silent ipv4.icanhazip.com` #Do not change without good reason, or underscor will eat your brains
tellserver() {
cmd="$1"
shift
rest=
for chunk in "$@"; do
rest="$rest/$chunk"
done
#if ! curl --silent --fail "http://$SERVER/$cmd/${USERNAME}$rest"; then
# error "Couldn't contact the listerine server. The listerine server could be down, or your network."
#fi
}
askserver() {
var="$1"
cmd="$2"
shift 2
rest=
for chunk in "$@"; do
rest="$rest/$chunk"
done
#export $var=`curl --silent --fail "http://$SERVER/$cmd/${USERNAME}$rest"`
#if [ $? != 0 ]; then
# error "Couldn't contact the listerine server. The listerine server could be down, or your network."
#fi
}
tellserver introduce $EXTERN_IP
while true; do
echo "Getting a userid from $SERVER, authenticated as $USERNAME with IP $EXTERN_IP"
askserver userid getID
if [ $? != 0 ]; then
error "The server didn't give us an id. This could mean the server is broken, or possibly that we're finished."
fi
userid=robbiet480
#if [ $(echo $userid | grep "^[-0-9]*$") != $userid ]; then
# error "The server did not return a valid id. It said: $userid"
#fi
modified=${userid/\./+}
path=data/users/${modified:0:1}/${modified:1:1}/${modified:2:1}
mkdir -p $path
echo ID is $userid saving to $path
file=$path/$modified.xml
$cannibal "$userid" | tee $file | grep "<id>" | sed -e 's/.*<id>\(.*\)<\/id>/\1/' | while read mark; do
#grep "<id>" test.xml | sed -e 's/.*<id>\(.*\)<\/id>/\1/' | while read mark; do
tagpath=data/tags/${mark:0:2}/${mark:2:2}/${mark:4:2}
mkdir -p $tagpath
./tagsaretasty.sh $mark > $tagpath/$mark.xml
done;
#if [ -f $file ]; then
# tellserver finishVid $userid $size $hash
#else
# warning "Failed to download anything for $userid."
#fi
if [ -f STOP ]; then
echo "$0: I see a file called STOP. Stopping."
exit 0
fi
done