Bladeren bron

Script to update zeronet bootstrap

Bob Mottram 9 jaren geleden
bovenliggende
commit
1d7c46db8f
3 gewijzigde bestanden met toevoegingen van 85 en 0 verwijderingen
  1. 2
    0
      Makefile
  2. 1
    0
      src/freedombone-prep
  3. 82
    0
      src/zeronetavahi

+ 2
- 0
Makefile Bestand weergeven

@@ -11,6 +11,7 @@ source:
11 11
 install:
12 12
 	mkdir -p ${DESTDIR}${PREFIX}/bin
13 13
 	install -m 755 src/${APP} ${DESTDIR}${PREFIX}/bin
14
+	install -m 755 src/zeronetavahi ${DESTDIR}${PREFIX}/bin
14 15
 	install -m 755 src/${APP}-keydrive ${DESTDIR}${PREFIX}/bin
15 16
 	install -m 755 src/${APP}-splitkey ${DESTDIR}${PREFIX}/bin
16 17
 	install -m 755 src/${APP}-recoverkey ${DESTDIR}${PREFIX}/bin
@@ -81,6 +82,7 @@ uninstall:
81 82
 	rm -f ${PREFIX}/share/man/man1/${APP}-mesh.1.gz
82 83
 	rm -rf ${PREFIX}/share/${APP}
83 84
 	rm -f ${PREFIX}/bin/${APP}
85
+	rm -f ${PREFIX}/bin/zeronetavahi
84 86
 	rm -f ${PREFIX}/bin/${APP}-keydrive
85 87
 	rm -f ${PREFIX}/bin/${APP}-splitkey
86 88
 	rm -f ${PREFIX}/bin/${APP}-recoverkey

+ 1
- 0
src/freedombone-prep Bestand weergeven

@@ -243,6 +243,7 @@ $SUDO sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $MICROSD_MOUNT
243 243
 
244 244
 # copy the commands to the card
245 245
 $SUDO cp -f $(which freedombone)* $MICROSD_MOUNT_POINT/$ROOTFS/usr/local/bin/
246
+$SUDO cp -f $(which zeronetavahi)* $MICROSD_MOUNT_POINT/$ROOTFS/usr/local/bin/
246 247
 if [ ! -f $MICROSD_MOUNT_POINT/$ROOTFS/usr/local/bin/freedombone ]; then
247 248
     echo 'There was a problem with writing freedombone commands to the SD card'
248 249
     exit 8736

+ 82
- 0
src/zeronetavahi Bestand weergeven

@@ -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