-
Notifications
You must be signed in to change notification settings - Fork 0
/
listerine
executable file
·98 lines (85 loc) · 2.42 KB
/
listerine
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
98
#!/bin/bash
#./listerine - a companion to the google gargle project
#relies on googlegrape, aria2c, curl, and youtube-dl
SERVER=199.48.254.90:8081
GARGLE=./googlegargle
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 $GARGLE ]; then
error "Couldn't find googlegargle. 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 an id from $SERVER, authenticated as $USERNAME with IP $EXTERN_IP"
askserver id 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
if [ $(echo $id | grep "^[-0-9]*$") != $id ]; then
error "The server did not return a valid id. It said: $id"
fi
echo ID is $id
$GARGLE -- "$id"
SEPDIB=$(echo "$id" | sed 's/-//g' | cut -c1)
SECDIB=$(echo "$id" | sed 's/-//g' | cut -c2)
THIRDIB=$(echo "$id" | sed 's/-//g' | cut -c3)
file="$SEPDIB/$SECDIB/$THIRDIB/$id/$id.flv"
if [ -f $file ]; then
hash=`sha1sum "$file"|awk '{print $1}'`
size=`du -b "$file"|awk '{print $1}'`
echo "Hash is $hash"
echo "ID is $id"
echo "USERNAME is $USERNAME"
echo "Size is $size"
tellserver finishVid $id $size $hash
else
warning "Failed to download anything for $id."
fi
if [ -f STOP ]; then
echo "$0: I see a file called STOP. Stopping."
exit 0
fi
done