|
@@ -1,375 +0,0 @@
|
1
|
|
-#!/bin/bash
|
2
|
|
-#
|
3
|
|
-# .---. . .
|
4
|
|
-# | | |
|
5
|
|
-# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
6
|
|
-# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
7
|
|
-# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
8
|
|
-#
|
9
|
|
-# Freedom in the Cloud
|
10
|
|
-#
|
11
|
|
-# A script to easily locate mesh peers and start communicating
|
12
|
|
-
|
13
|
|
-# License
|
14
|
|
-# =======
|
15
|
|
-#
|
16
|
|
-# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
|
17
|
|
-#
|
18
|
|
-# This program is free software: you can redistribute it and/or modify
|
19
|
|
-# it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
27
|
|
-#
|
28
|
|
-# You should have received a copy of the GNU Affero General Public License
|
29
|
|
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
30
|
|
-
|
31
|
|
-PROJECT_NAME='freedombone'
|
32
|
|
-
|
33
|
|
-export TEXTDOMAIN=${PROJECT_NAME}-mesh
|
34
|
|
-export TEXTDOMAINDIR="/usr/share/locale"
|
35
|
|
-
|
36
|
|
-CONFIG_FILE=$HOME/${PROJECT_NAME}.cfg
|
37
|
|
-
|
38
|
|
-MUMBLE_PATH=/usr/bin/mumble
|
39
|
|
-TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}')
|
40
|
|
-DHTNODES=/usr/share/toxic/DHTnodes
|
41
|
|
-
|
42
|
|
-PEERS_FILE=/tmp/meshpeers.txt
|
43
|
|
-
|
44
|
|
-TOX_PORT=33445
|
45
|
|
-TOXCORE_REPO='https://github.com/irungentoo/toxcore'
|
46
|
|
-TOXCORE_COMMIT=
|
47
|
|
-# obtain tox values from main install
|
48
|
|
-if grep -q "TOX_PORT=" $CONFIG_FILE; then
|
49
|
|
- TOX_PORT=$(cat $CONFIG_FILE | grep "TOX_PORT=" | nead -n 1 | awk -F '=' '{print $2}')
|
50
|
|
-fi
|
51
|
|
-if grep -q "TOXCORE_REPO=" $CONFIG_FILE; then
|
52
|
|
- TOXCORE_REPO=$(cat $CONFIG_FILE | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}')
|
53
|
|
-fi
|
54
|
|
-if grep -q "TOXCORE_COMMIT=" $CONFIG_FILE; then
|
55
|
|
- TOXCORE_COMMIT=$(cat $CONFIG_FILE | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}')
|
56
|
|
-fi
|
57
|
|
-TOXID_REPO='https://github.com/bashrc/toxid'
|
58
|
|
-TOX_BOOTSTRAP_ID_FILE=/var/lib/tox-bootstrapd/pubkey.txt
|
59
|
|
-QTOX_INI="/home/$USER/.config/tox/qtox.ini"
|
60
|
|
-
|
61
|
|
-# client or server installations sounds odd for a mesh, but this
|
62
|
|
-# indicates whether this is a dedicated mesh peer ("yes") or
|
63
|
|
-# a 'client' such as a laptop or desktop machine with
|
64
|
|
-# the freedombone-client script installed
|
65
|
|
-SERVER_INSTALLATION="no"
|
66
|
|
-
|
67
|
|
-function install_toxcore {
|
68
|
|
- if [ -f /etc/tox-bootstrapd.conf ]; then
|
69
|
|
- return
|
70
|
|
- fi
|
71
|
|
-
|
72
|
|
- sudo apt-get -yq install build-essential libtool autotools-dev
|
73
|
|
- sudo apt-get -yq install automake checkinstall check git yasm
|
74
|
|
- sudo apt-get -yq install libsodium18 libsodium-dev libcap2-bin
|
75
|
|
- sudo apt-get -yq install libconfig9 libconfig-dev
|
76
|
|
-
|
77
|
|
- if [ ! -d ~/develop ]; then
|
78
|
|
- mkdir ~/develop
|
79
|
|
- fi
|
80
|
|
- cd ~/develop
|
81
|
|
- git clone $TOXCORE_REPO ~/develop/toxcore
|
82
|
|
- cd ~/develop/toxcore
|
83
|
|
- if [ $TOXCORE_COMMIT ]; then
|
84
|
|
- git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT
|
85
|
|
- fi
|
86
|
|
- autoreconf -i
|
87
|
|
- ./configure --enable-daemon
|
88
|
|
- if [ ! "$?" = "0" ]; then
|
89
|
|
- exit 78467
|
90
|
|
- fi
|
91
|
|
- make
|
92
|
|
- if [ ! "$?" = "0" ]; then
|
93
|
|
- exit 84562
|
94
|
|
- fi
|
95
|
|
- sudo make install
|
96
|
|
- sudo cp /usr/local/lib/libtoxcore* /usr/lib/
|
97
|
|
-
|
98
|
|
- if [ ! -f /usr/local/bin/tox-bootstrapd ]; then
|
99
|
|
- echo $"File not found /usr/local/bin/tox-bootstrapd"
|
100
|
|
- exit 73862
|
101
|
|
- fi
|
102
|
|
-
|
103
|
|
- sudo useradd --home-dir /var/lib/tox-bootstrapd --create-home --system --shell /sbin/nologin --comment "Account to run Tox's DHT bootstrap daemon" --user-group tox-bootstrapd
|
104
|
|
- sudo chmod 700 /var/lib/tox-bootstrapd
|
105
|
|
- if [ ! -f ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf ]; then
|
106
|
|
- echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf"
|
107
|
|
- exit 476835
|
108
|
|
- fi
|
109
|
|
-
|
110
|
|
- # create configuration file
|
111
|
|
- echo "port = $TOX_PORT" > /tmp/tox-bootstrapd.conf
|
112
|
|
- echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> /tmp/tox-bootstrapd.conf
|
113
|
|
- echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> /tmp/tox-bootstrapd.conf
|
114
|
|
- echo 'enable_ipv6 = true' >> /tmp/tox-bootstrapd.conf
|
115
|
|
- echo 'enable_ipv4_fallback = true' >> /tmp/tox-bootstrapd.conf
|
116
|
|
- echo 'enable_lan_discovery = true' >> /tmp/tox-bootstrapd.conf
|
117
|
|
- echo 'enable_tcp_relay = true' >> /tmp/tox-bootstrapd.conf
|
118
|
|
- echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> /tmp/tox-bootstrapd.conf
|
119
|
|
- echo 'enable_motd = true' >> /tmp/tox-bootstrapd.conf
|
120
|
|
- echo 'motd = "tox-bootstrapd"' >> /tmp/tox-bootstrapd.conf
|
121
|
|
- sudo cp /tmp/tox-bootstrapd.conf /etc/tox-bootstrapd.conf
|
122
|
|
- rm /tmp/tox-bootstrapd.conf
|
123
|
|
-
|
124
|
|
- if [ ! -f ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.service ]; then
|
125
|
|
- echo $"File not found ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.service"
|
126
|
|
- exit 7359
|
127
|
|
- fi
|
128
|
|
- sudo cp ~/develop/toxcore/other/bootstrap_daemon/tox-bootstrapd.service /etc/systemd/system/
|
129
|
|
-
|
130
|
|
- sudo systemctl daemon-reload
|
131
|
|
- sudo systemctl enable tox-bootstrapd.service
|
132
|
|
- sudo systemctl start tox-bootstrapd.service
|
133
|
|
- if [ ! "$?" = "0" ]; then
|
134
|
|
- sudo systemctl status tox-bootstrapd.service
|
135
|
|
- exit 5846
|
136
|
|
- fi
|
137
|
|
-
|
138
|
|
- sudo systemctl restart tox-bootstrapd.service
|
139
|
|
-
|
140
|
|
- TOX_PUBLIC_KEY=$(cat /var/log/syslog | grep tox | grep "Public Key" | awk -F ' ' '{print $8}' | tail -1)
|
141
|
|
- if [ ${#TOX_PUBLIC_KEY} -lt 30 ]; then
|
142
|
|
- echo $'Could not obtain the tox node public key'
|
143
|
|
- exit 6529
|
144
|
|
- fi
|
145
|
|
-
|
146
|
|
- # save the public key for later reference
|
147
|
|
- echo "$TOX_PUBLIC_KEY" > /tmp/boostrapid
|
148
|
|
- sudo mv /tmp/boostrapid $TOX_BOOTSTRAP_ID_FILE
|
149
|
|
-}
|
150
|
|
-
|
151
|
|
-function install_toxid {
|
152
|
|
- if [ -f /usr/local/bin/toxid ]; then
|
153
|
|
- return
|
154
|
|
- fi
|
155
|
|
- cd ~/develop
|
156
|
|
- git clone $TOXID_REPO ~/develop/toxid
|
157
|
|
- cd ~/develop/toxid
|
158
|
|
- make
|
159
|
|
- sudo make install
|
160
|
|
-
|
161
|
|
- if [ ! -f /usr/local/bin/toxid ]; then
|
162
|
|
- echo $"Couldn't install toxid"
|
163
|
|
- exit 6389
|
164
|
|
- fi
|
165
|
|
-}
|
166
|
|
-
|
167
|
|
-function run_tox {
|
168
|
|
- echo $QTOX_INI
|
169
|
|
- if [[ -f $TOXIC_FILE || -f $QTOX_INI ]]; then
|
170
|
|
- if [[ $SERVER_INSTALLATION == "no" ]]; then
|
171
|
|
- # update bootstrap nodes
|
172
|
|
- if [ -f $DHTNODES ]; then
|
173
|
|
- if [ ! -f $DHTNODES.internet ]; then
|
174
|
|
- sudo cp $DHTNODES $DHTNODES.internet
|
175
|
|
- fi
|
176
|
|
- fi
|
177
|
|
- lstox -f dht > /tmp/dht
|
178
|
|
- sudo cp /tmp/dht $DHTNODES
|
179
|
|
- fi
|
180
|
|
-
|
181
|
|
- # get a list of peers
|
182
|
|
- PEER_TOX_ID_LIST=$(lstox | grep $AVAHI_DOMAIN | sort -u)
|
183
|
|
- if [ ! "$PEER_TOX_ID_LIST" ]; then
|
184
|
|
- echo $'No peers found'
|
185
|
|
- exit 0
|
186
|
|
- fi
|
187
|
|
- PEER_TOX_ID_LIST_COUNT=$(echo "$PEER_TOX_ID_LIST" | wc -l)
|
188
|
|
- PEER_TOX_ID=''
|
189
|
|
- if [ $PEER_TOX_ID_LIST_COUNT -lt "2" ]; then
|
190
|
|
- # single peer
|
191
|
|
- PEER_TOX_ID=$(echo "$PEER_TOX_ID_LIST" | awk -F ' ' '{print $3}')
|
192
|
|
- else
|
193
|
|
- # choose a user from a list
|
194
|
|
- echo ''
|
195
|
|
- echo $"Select a user on $AVAHI_DOMAIN:"
|
196
|
|
- ctr=0
|
197
|
|
- while IFS='' read -r line || [[ -n "$line" ]]; do
|
198
|
|
- toxusername=$(echo $line | awk -F ' ' '{print $2}')
|
199
|
|
- echo " $ctr. $toxusername"
|
200
|
|
- ctr=$((ctr + 1))
|
201
|
|
- done < "$PEER_TOX_ID_LIST"
|
202
|
|
- read user_index
|
203
|
|
- PEER_TOX_ID=$(echo "$PEER_TOX_ID_LIST" | tail -n+${user_index} | head -n1 | awk -F ' ' '{print $3}')
|
204
|
|
- fi
|
205
|
|
-
|
206
|
|
- # if this is a valid ID
|
207
|
|
- if [ ${#PEER_TOX_ID} -gt 30 ]; then
|
208
|
|
- # start client and make a friend request
|
209
|
|
- if [ -f $QTOX_INI ]; then
|
210
|
|
- echo $'Launch qTox'
|
211
|
|
- qtox &
|
212
|
|
- else
|
213
|
|
-
|
214
|
|
- echo "n
|
215
|
|
-/nick $USER
|
216
|
|
-/add $PEER_TOX_ID
|
217
|
|
-/exit
|
218
|
|
-" | $TOXIC_FILE -d
|
219
|
|
- # Running twice is a hack to get around buggyness in the client
|
220
|
|
- $TOXIC_FILE -d
|
221
|
|
- fi
|
222
|
|
- exit 0
|
223
|
|
- else
|
224
|
|
- # ID was invalid
|
225
|
|
- echo $PEER_TOX_ID
|
226
|
|
- echo $"Tox ID for $AVAHI_DOMAIN was not found"
|
227
|
|
- exit 6
|
228
|
|
- fi
|
229
|
|
- fi
|
230
|
|
-}
|
231
|
|
-
|
232
|
|
-if [ -f /var/lib/batman ]; then
|
233
|
|
- SERVER_INSTALLATION="yes"
|
234
|
|
-fi
|
235
|
|
-
|
236
|
|
-if [[ $SERVER_INSTALLATION == "no" ]]; then
|
237
|
|
- if [ ! -f /usr/bin/batman ]; then
|
238
|
|
- ${PROJECT_NAME}-client
|
239
|
|
- fi
|
240
|
|
-fi
|
241
|
|
-
|
242
|
|
-# alternative toxic paths
|
243
|
|
-if [ -f /usr/local/bin/toxic ]; then
|
244
|
|
- TOXIC_FILE=/usr/local/bin/toxic
|
245
|
|
-fi
|
246
|
|
-if [ -f /usr/local/share/toxic/DHTnodes ]; then
|
247
|
|
- DHTNODES=/usr/local/share/toxic/DHTnodes
|
248
|
|
-fi
|
249
|
|
-
|
250
|
|
-if [[ $SERVER_INSTALLATION == "no" ]]; then
|
251
|
|
- if [ ! -f /tmp/meshtype ]; then
|
252
|
|
- install_toxcore
|
253
|
|
- install_toxid
|
254
|
|
- sudo batman start
|
255
|
|
- if [ ! "$?" = "0" ]; then
|
256
|
|
- exit 2
|
257
|
|
- fi
|
258
|
|
- fi
|
259
|
|
-fi
|
260
|
|
-
|
261
|
|
-avahi-browse -atl | awk -F ' ' '{print $4}' | sort -u > $PEERS_FILE
|
262
|
|
-
|
263
|
|
-if [ ! -f $PEERS_FILE ]; then
|
264
|
|
- echo $'No peers were found'
|
265
|
|
- exit 0
|
266
|
|
-fi
|
267
|
|
-
|
268
|
|
-ctr=0
|
269
|
|
-while IFS='' read -r line || [[ -n "$line" ]]; do
|
270
|
|
- ctr=$((ctr + 1))
|
271
|
|
-done < "$PEERS_FILE"
|
272
|
|
-
|
273
|
|
-if [ ${ctr} -lt "1" ]; then
|
274
|
|
- echo $'No peers were found'
|
275
|
|
- exit 0
|
276
|
|
-fi
|
277
|
|
-
|
278
|
|
-clear
|
279
|
|
-echo ''
|
280
|
|
-echo ".---. . . "
|
281
|
|
-echo "| | | "
|
282
|
|
-echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. "
|
283
|
|
-echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' "
|
284
|
|
-echo "' ' --' --' -' - -' ' ' -' -' -' ' - --'"
|
285
|
|
-echo $' Freedom in the Mesh'
|
286
|
|
-echo ''
|
287
|
|
-echo $'Please choose a peer to connect to:'
|
288
|
|
-idx=1
|
289
|
|
-while IFS='' read -r line || [[ -n "$line" ]]; do
|
290
|
|
- echo " $idx. $line"
|
291
|
|
- idx=$((idx + 1))
|
292
|
|
-done < "$PEERS_FILE"
|
293
|
|
-
|
294
|
|
-peer_index=0
|
295
|
|
-read peer_index
|
296
|
|
-
|
297
|
|
-# if no selection made
|
298
|
|
-if [ ! $peer_index ]; then
|
299
|
|
- echo $'Nothing was selected'
|
300
|
|
- echo ''
|
301
|
|
- exit 0
|
302
|
|
-fi
|
303
|
|
-
|
304
|
|
-# get the avahi domain name
|
305
|
|
-AVAHI_DOMAIN=
|
306
|
|
-idx=1
|
307
|
|
-while IFS='' read -r line || [[ -n "$line" ]]; do
|
308
|
|
- if [ ${idx} -eq "$peer_index" ]; then
|
309
|
|
- AVAHI_DOMAIN=${line}.local
|
310
|
|
- fi
|
311
|
|
- idx=$((idx + 1))
|
312
|
|
-done < "$PEERS_FILE"
|
313
|
|
-
|
314
|
|
-if [ ! $AVAHI_DOMAIN ]; then
|
315
|
|
- echo $'No domain name'
|
316
|
|
- exit 3
|
317
|
|
-fi
|
318
|
|
-
|
319
|
|
-# if only mumble is installed
|
320
|
|
-if [ ! -f $TOXIC_FILE ]; then
|
321
|
|
- if [ -f $MUMBLE_PATH ]; then
|
322
|
|
- $MUMBLE_PATH &
|
323
|
|
- exit 0
|
324
|
|
- fi
|
325
|
|
- echo $'You need mumble/toxic/qTox installed on your system'
|
326
|
|
- if [[ $SERVER_INSTALLATION == "no" ]]; then
|
327
|
|
- sudo batman stop
|
328
|
|
- fi
|
329
|
|
- exit 4
|
330
|
|
-fi
|
331
|
|
-
|
332
|
|
-# if only tox is installed
|
333
|
|
-if [ ! -f $MUMBLE_PATH ]; then
|
334
|
|
- run_tox
|
335
|
|
-fi
|
336
|
|
-
|
337
|
|
-echo ''
|
338
|
|
-echo $'Choose communication service:'
|
339
|
|
-echo $' 1. Voice'
|
340
|
|
-echo $' 2. Tox Chat'
|
341
|
|
-echo ''
|
342
|
|
-
|
343
|
|
-read peer_index
|
344
|
|
-
|
345
|
|
-# if no selection made
|
346
|
|
-if [ ! $peer_index ]; then
|
347
|
|
- echo $'Nothing was selected'
|
348
|
|
- echo ''
|
349
|
|
- exit 0
|
350
|
|
-fi
|
351
|
|
-
|
352
|
|
-if [[ $peer_index == 1 ]]; then
|
353
|
|
- if [ -f $MUMBLE_PATH ]; then
|
354
|
|
- echo ''
|
355
|
|
- echo $'To setup for the first time click "Add New", then set:'
|
356
|
|
- echo $" Label: $AVAHI_DOMAIN"
|
357
|
|
- echo $" Address: $AVAHI_DOMAIN"
|
358
|
|
- echo $' Port: 64738'
|
359
|
|
- echo $" Username: $USER"
|
360
|
|
- echo ''
|
361
|
|
- echo $'Press Enter to continue.'
|
362
|
|
- echo ''
|
363
|
|
- read peer_index
|
364
|
|
- $MUMBLE_PATH &
|
365
|
|
- else
|
366
|
|
- echo $'Mumble may not be installed on this system'
|
367
|
|
- exit 5
|
368
|
|
- fi
|
369
|
|
-fi
|
370
|
|
-
|
371
|
|
-if [[ $peer_index == 2 ]]; then
|
372
|
|
- run_tox
|
373
|
|
-fi
|
374
|
|
-
|
375
|
|
-exit 0
|