|
@@ -0,0 +1,82 @@
|
|
1
|
+#!/bin/bash
|
|
2
|
+#
|
|
3
|
+# .---. . .
|
|
4
|
+# | | |
|
|
5
|
+# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
6
|
+# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
7
|
+# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
8
|
+#
|
|
9
|
+# Freedom in the Cloud
|
|
10
|
+#
|
|
11
|
+# A script for using avahi to discover peers and update zeronet trackers
|
|
12
|
+
|
|
13
|
+# License
|
|
14
|
+# =======
|
|
15
|
+#
|
|
16
|
+# Copyright (C) 2015 Bob Mottram <bob@robotics.uk.to>
|
|
17
|
+#
|
|
18
|
+# This program is free software: you can redistribute it and/or modify
|
|
19
|
+# it under the terms of the GNU General Public License as published by
|
|
20
|
+# the Free Software Foundation, either version 3 of the License, or
|
|
21
|
+# (at your option) any later version.
|
|
22
|
+#
|
|
23
|
+# This program is distributed in the hope that it will be useful,
|
|
24
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
26
|
+# GNU General Public License for more details.
|
|
27
|
+#
|
|
28
|
+# You should have received a copy of the GNU General Public License
|
|
29
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
30
|
+
|
|
31
|
+TRANSMISSION_PORT=
|
|
32
|
+BOOTSTRAP_FILE=/opt/zeronet/bootstrap
|
|
33
|
+
|
|
34
|
+if [ ! -d /opt/zeronet ]; then
|
|
35
|
+ exit 0
|
|
36
|
+fi
|
|
37
|
+
|
|
38
|
+if [ ! -d /etc/avahi ]; then
|
|
39
|
+ exit 0
|
|
40
|
+fi
|
|
41
|
+
|
|
42
|
+TEMPFILE=/tmp/tmpzeronetavahi.txt
|
|
43
|
+avahi-browse -atrl | grep "Workstation\|hostname =\|address =\|port =" > $TEMPFILE
|
|
44
|
+if [ ! -f $TEMPFILE ]; then
|
|
45
|
+ exit 1
|
|
46
|
+fi
|
|
47
|
+
|
|
48
|
+state=0
|
|
49
|
+address=""
|
|
50
|
+port=0
|
|
51
|
+peer=""
|
|
52
|
+while IFS='' read -r line || [[ -n "$line" ]]; do
|
|
53
|
+ if [ ${state} -eq "3" ]; then
|
|
54
|
+ if [[ $line == *"port ="* ]]; then
|
|
55
|
+ port=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
56
|
+ echo "udp $address $port" >> $BOOTSTRAP_FILE.new
|
|
57
|
+ state=0
|
|
58
|
+ fi
|
|
59
|
+ fi
|
|
60
|
+ if [ ${state} -eq "2" ]; then
|
|
61
|
+ if [[ $line == *"address ="* ]]; then
|
|
62
|
+ address=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
63
|
+ state=3
|
|
64
|
+ fi
|
|
65
|
+ fi
|
|
66
|
+ if [ ${state} -eq "1" ]; then
|
|
67
|
+ if [[ $line == *"hostname ="* ]]; then
|
|
68
|
+ peer=$(echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}')
|
|
69
|
+ state=2
|
|
70
|
+ fi
|
|
71
|
+ fi
|
|
72
|
+ if [[ $line == *"Workstation"* && $line == "= "* ]]; then
|
|
73
|
+ state=1
|
|
74
|
+ fi
|
|
75
|
+done < "$TEMPFILE"
|
|
76
|
+
|
|
77
|
+rm -f $TEMPFILE
|
|
78
|
+cp -f $BOOTSTRAP_FILE.new $BOOTSTRAP_FILE
|
|
79
|
+rm -f $BOOTSTRAP_FILE.new
|
|
80
|
+sudo chown zeronet:zeronet /opt/zeronet/bootstrap
|
|
81
|
+
|
|
82
|
+exit 0
|