Преглед изворни кода

Install scuttlebot on mesh

This should better enable nat traversal between the internet and the mesh
Bob Mottram пре 7 година
родитељ
комит
073ad0f888

+ 40
- 0
src/freedombone-app-scuttlebot Прегледај датотеку

@@ -197,6 +197,46 @@ function remove_scuttlebot {
197 197
     sed -i '/scuttlebot /d' $COMPLETION_FILE
198 198
 }
199 199
 
200
+function mesh_install_scuttlebot {
201
+    cat <<EOF > $rootdir/usr/bin/install_scuttlebot
202
+#!/bin/bash
203
+npm install -g scuttlebot@${SCUTTLEBOT_VERSION}
204
+EOF
205
+    chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
206
+    chroot "$rootdir" /usr/bin/install_scuttlebot
207
+    rm $rootdir/usr/bin/install_scuttlebot
208
+
209
+    if [ ! -f $rootdir/usr/local/bin/sbot ]; then
210
+        echo $'Scuttlebot was not installed'
211
+        exit 528253
212
+    fi
213
+
214
+    if [ ! -d $rootdir/etc/scuttlebot ]; then
215
+        mkdir -p $rootdir/etc/scuttlebot
216
+    fi
217
+
218
+    # an unprivileged user to run as
219
+    chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
220
+
221
+    # daemon
222
+    echo '[Unit]' > $rootdir/etc/systemd/system/scuttlebot.service
223
+    echo 'Description=Scuttlebot (messaging system)' >> $rootdir/etc/systemd/system/scuttlebot.service
224
+    echo 'After=syslog.target' >> $rootdir/etc/systemd/system/scuttlebot.service
225
+    echo 'After=network.target' >> $rootdir/etc/systemd/system/scuttlebot.service
226
+    echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
227
+    echo '[Service]' >> $rootdir/etc/systemd/system/scuttlebot.service
228
+    echo 'Type=simple' >> $rootdir/etc/systemd/system/scuttlebot.service
229
+    echo 'User=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
230
+    echo 'Group=scuttlebot' >> $rootdir/etc/systemd/system/scuttlebot.service
231
+    echo "WorkingDirectory=/etc/scuttlebot" >> $rootdir/etc/systemd/system/scuttlebot.service
232
+    echo 'ExecStart=/usr/local/bin/sbot server' >> $rootdir/etc/systemd/system/scuttlebot.service
233
+    echo 'Restart=always' >> $rootdir/etc/systemd/system/scuttlebot.service
234
+    echo 'Environment="USER=scuttlebot"' >> $rootdir/etc/systemd/system/scuttlebot.service
235
+    echo '' >> $rootdir/etc/systemd/system/scuttlebot.service
236
+    echo '[Install]' >> $rootdir/etc/systemd/system/scuttlebot.service
237
+    echo 'WantedBy=multi-user.target' >> $rootdir/etc/systemd/system/scuttlebot.service
238
+}
239
+
200 240
 function install_scuttlebot {
201 241
     function_check install_nodejs
202 242
     install_nodejs scuttlebot

+ 1
- 0
src/freedombone-image-customise Прегледај датотеку

@@ -701,6 +701,7 @@ initialise_mesh() {
701 701
     #install_tahoelafs
702 702
     #install_librevault
703 703
     install_patchwork
704
+    mesh_install_scuttlebot
704 705
     install_ferment
705 706
     install_ipfs
706 707
     install_tox

+ 36
- 0
src/freedombone-image-mesh Прегледај датотеку

@@ -756,6 +756,41 @@ function mesh_setup_vpn {
756 756
     systemctl restart openvpn
757 757
 }
758 758
 
759
+function initialise_scuttlebot_pub {
760
+    chown -R scuttlebot:scuttlebot /etc/scuttlebot
761
+
762
+    systemctl enable scuttlebot.service
763
+    systemctl daemon-reload
764
+    systemctl start scuttlebot.service
765
+
766
+    sleep 3
767
+
768
+    if [ ! -d /etc/scuttlebot/.ssb ]; then
769
+        echo $'Scuttlebot config not generated' >> /var/log/${PROJECT_NAME}.log
770
+        exit 73528
771
+    fi
772
+
773
+    echo '{' > /etc/scuttlebot/.ssb/config
774
+    echo "  \"host\": \"${HOSTNAME}\"," >> /etc/scuttlebot/.ssb/config
775
+    echo "  \"port\": 8008," >> /etc/scuttlebot/.ssb/config
776
+    echo '  "timeout": 30000,' >> /etc/scuttlebot/.ssb/config
777
+    echo '  "pub": true,' >> /etc/scuttlebot/.ssb/config
778
+    echo '  "local": true,' >> /etc/scuttlebot/.ssb/config
779
+    echo '  "friends": {' >> /etc/scuttlebot/.ssb/config
780
+    echo '    "dunbar": 150,' >> /etc/scuttlebot/.ssb/config
781
+    echo '    "hops": 3' >> /etc/scuttlebot/.ssb/config
782
+    echo '  },' >> /etc/scuttlebot/.ssb/config
783
+    echo '  "gossip": {' >> /etc/scuttlebot/.ssb/config
784
+    echo '    "connections": 2' >> /etc/scuttlebot/.ssb/config
785
+    echo '  },' >> /etc/scuttlebot/.ssb/config
786
+    echo '  "master": [],' >> /etc/scuttlebot/.ssb/config
787
+    echo '  "logging": {' >> /etc/scuttlebot/.ssb/config
788
+    echo '    "level": "error"' >> /etc/scuttlebot/.ssb/config
789
+    echo '  }' >> /etc/scuttlebot/.ssb/config
790
+    echo '}' >> /etc/scuttlebot/.ssb/config
791
+    chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
792
+    systemctl restart scuttlebot.service
793
+}
759 794
 
760 795
 # whether to reset the identity
761 796
 set_new_identity=
@@ -819,6 +854,7 @@ if [ -f $MESH_INSTALL_SETUP ]; then
819 854
     create_tox_user
820 855
     #setup_tahoelafs
821 856
     mesh_setup_vpn
857
+    initialise_scuttlebot_pub
822 858
     setup_ipfs
823 859
     mesh_amnesic
824 860
     make_root_read_only

+ 2
- 2
src/freedombone-mesh-batman Прегледај датотеку

@@ -155,7 +155,7 @@ function stop {
155 155
     iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
156 156
     iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
157 157
     iptables -D INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
158
-    # SSB/Patchwork
158
+    # SSB/Scuttlebot/Patchwork
159 159
     iptables -D INPUT -p udp --dport 8008 -j ACCEPT
160 160
     iptables -D INPUT -p tcp --dport 8008 -j ACCEPT
161 161
     # vpn over the internet
@@ -325,7 +325,7 @@ function start {
325 325
     iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
326 326
     iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
327 327
     iptables -A INPUT -p tcp --dport $TAHOELAFS_PORT -j ACCEPT
328
-    # SSB/Patchwork
328
+    # SSB/Scuttlebot/Patchwork
329 329
     iptables -A INPUT -p udp --dport 8008 -j ACCEPT
330 330
     iptables -A INPUT -p tcp --dport 8008 -j ACCEPT
331 331
     # vpn over the internet