Bob Mottram 10 年之前
父節點
當前提交
707868c2ca
共有 1 個檔案被更改,包括 131 行新增0 行删除
  1. 131
    0
      src/freedombone

+ 131
- 0
src/freedombone 查看文件

@@ -384,6 +384,16 @@ BATMAN_IPV6=
384 384
 # social key management
385 385
 ENABLE_SOCIAL_KEY_MANAGEMENT="no"
386 386
 
387
+TOX_PORT=33445
388
+TOX_REPO='git://github.com/irungentoo/toxcore.git'
389
+# These are some default nodes, but you can replace them with trusted nodes
390
+# as you prefer. See https://wiki.tox.im/Nodes
391
+TOX_NODE=
392
+#TOX_NODES=(
393
+#  '192.254.75.102,2607:5600:284::2,33445,951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F,Tox RELENG,US'
394
+#  '144.76.60.215,2a01:4f8:191:64d6::1,33445,04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F,sonOfRa,DE'
395
+#)
396
+
387 397
 function show_help {
388 398
   echo ''
389 399
   echo 'freedombone -c [configuration file]'
@@ -719,6 +729,15 @@ function read_configuration {
719 729
   fi
720 730
 
721 731
   if [ -f $CONFIGURATION_FILE ]; then
732
+      if grep -q "TOX_PORT" $CONFIGURATION_FILE; then
733
+          TOX_PORT=$(grep "TOX_PORT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
734
+      fi
735
+      if grep -q "TOX_NODES" $CONFIGURATION_FILE; then
736
+          TOX_NODES=$(grep "TOX_NODES" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
737
+      fi
738
+      if grep -q "TOX_REPO" $CONFIGURATION_FILE; then
739
+          TOX_REPO=$(grep "TOX_REPO" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
740
+      fi
722 741
       if grep -q "ENABLE_SOCIAL_KEY_MANAGEMENT" $CONFIGURATION_FILE; then
723 742
           ENABLE_SOCIAL_KEY_MANAGEMENT=$(grep "ENABLE_SOCIAL_KEY_MANAGEMENT" $CONFIGURATION_FILE | awk -F '=' '{print $2}')
724 743
       fi
@@ -5481,6 +5500,19 @@ function configure_firewall_for_web_server {
5481 5500
   echo 'configure_firewall_for_web_server' >> $COMPLETION_FILE
5482 5501
 }
5483 5502
 
5503
+function configure_firewall_for_tox {
5504
+  if grep -Fxq "configure_firewall_for_tox" $COMPLETION_FILE; then
5505
+      return
5506
+  fi
5507
+  if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
5508
+      # docker does its own firewalling
5509
+      return
5510
+  fi
5511
+  iptables -A INPUT -i eth0 -p tcp --dport $TOX_PORT -j ACCEPT
5512
+  save_firewall_settings
5513
+  echo 'configure_firewall_for_tox' >> $COMPLETION_FILE
5514
+}
5515
+
5484 5516
 function configure_firewall_for_ssh {
5485 5517
   if grep -Fxq "configure_firewall_for_ssh" $COMPLETION_FILE; then
5486 5518
       return
@@ -7478,6 +7510,93 @@ quit" > $INSTALL_DIR/batch.sql
7478 7510
   echo 'install_gogs' >> $COMPLETION_FILE
7479 7511
 }
7480 7512
 
7513
+function install_tox_node {
7514
+  if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" ]]; then
7515
+      return
7516
+  fi
7517
+  if grep -Fxq "install_tox_node" $COMPLETION_FILE; then
7518
+      return
7519
+  fi
7520
+
7521
+  # toxcore
7522
+  apt-get -y install build-essential libtool autotools-dev
7523
+  apt-get -y install automake checkinstall check git yasm
7524
+  apt-get -y install libsodium13 libsodium-dev libcap2-bin
7525
+
7526
+  cd $INSTALL_DIR
7527
+  git clone $TOX_REPO
7528
+  cd $INSTALL_DIR/toxcore
7529
+  autoreconf -i
7530
+  ./configure
7531
+  if [ ! "$?" = "0" ]; then
7532
+      exit 78467
7533
+  fi
7534
+  make
7535
+  if [ ! "$?" = "0" ]; then
7536
+      exit 84562
7537
+  fi
7538
+  make install
7539
+
7540
+  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
7541
+  chmod 700 /var/lib/tox-bootstrapd
7542
+  if [ ! -f $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf ]; then
7543
+      echo "File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf"
7544
+      exit 476835
7545
+  fi
7546
+
7547
+  # create configuration file
7548
+  echo "port = $TOX_PORT" > /etc/tox-bootstrapd.conf
7549
+  echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> /etc/tox-bootstrapd.conf
7550
+  echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> /etc/tox-bootstrapd.conf
7551
+  echo 'enable_ipv6 = true' >> /etc/tox-bootstrapd.conf
7552
+  echo 'enable_ipv4_fallback = true' >> /etc/tox-bootstrapd.conf
7553
+  echo 'enable_lan_discovery = true' >> /etc/tox-bootstrapd.conf
7554
+  echo 'enable_tcp_relay = true' >> /etc/tox-bootstrapd.conf
7555
+  echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> /etc/tox-bootstrapd.conf
7556
+  echo 'enable_motd = true' >> /etc/tox-bootstrapd.conf
7557
+  echo 'motd = "tox-bootstrapd"' >> /etc/tox-bootstrapd.conf
7558
+
7559
+  if [ $TOX_NODES ]; then
7560
+      echo 'bootstrap_nodes = (' >> /etc/tox-bootstrapd.conf
7561
+      toxcount=0
7562
+      while [ "x${TOX_NODES[toxcount]}" != "x" ]
7563
+      do
7564
+          toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}')
7565
+          toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}')
7566
+          toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}')
7567
+          toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}')
7568
+          toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}')
7569
+          echo "{ // $toxval_maintainer" >> /etc/tox-bootstrapd.conf
7570
+          if [[ $toxval_ipv6 != 'NONE' ]]; then
7571
+              echo "  address = \"$toxval_ipv6\"" >> /etc/tox-bootstrapd.conf
7572
+          else
7573
+              echo "  address = \"$toxval_ipv4\"" >> /etc/tox-bootstrapd.conf
7574
+          fi
7575
+          echo "  port = $toxval_port" >> /etc/tox-bootstrapd.conf
7576
+          echo "  public_key = \"$toxval_pubkey\"" >> /etc/tox-bootstrapd.conf
7577
+          toxcount=$(( $toxcount + 1 ))
7578
+          if [ "x${TOX_NODES[toxcount]}" != "x" ]; then
7579
+              echo "}," >> /etc/tox-bootstrapd.conf
7580
+          else
7581
+              echo "}" >> /etc/tox-bootstrapd.conf
7582
+          fi
7583
+      done
7584
+      echo ')' >> /etc/tox-bootstrapd.conf
7585
+  fi
7586
+
7587
+  cp $INSTALL_DIR/toxcore/tox-bootstrapd.service /etc/systemd/system/
7588
+  systemctl daemon-reload
7589
+  systemctl enable tox-bootstrapd.service
7590
+  systemctl start tox-bootstrapd.service
7591
+  if [ ! "$?" = "0" ]; then
7592
+      systemctl status tox-bootstrapd.service
7593
+      exit 5846
7594
+  fi
7595
+  configure_firewall_for_tox
7596
+
7597
+  echo 'install_tox_node' >> $COMPLETION_FILE
7598
+}
7599
+
7481 7600
 function install_xmpp {
7482 7601
   if [[ $SYSTEM_TYPE == "$VARIANT_WRITER" || $SYSTEM_TYPE == "$VARIANT_MAILBOX" || $SYSTEM_TYPE == "$VARIANT_CLOUD" || $SYSTEM_TYPE == "$VARIANT_SOCIAL" || $SYSTEM_TYPE == "$VARIANT_MEDIA" || $SYSTEM_TYPE == "$VARIANT_DEVELOPER" ]]; then
7483 7602
       return
@@ -9055,6 +9174,17 @@ function create_upgrade_script {
9055 9174
       echo 'systemctl restart gogs' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9056 9175
       echo 'systemctl daemon-reload' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9057 9176
   fi
9177
+  if [ -d $INSTALL_DIR/toxcore ]; then
9178
+      echo '' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9179
+      echo '# Tox node' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9180
+      echo "cd $INSTALL_DIR/toxcore" >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9181
+      echo 'git stash' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9182
+      echo 'git pull' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9183
+      echo 'autoreconf -i' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9184
+      echo './configure' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9185
+      echo 'make' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9186
+      echo 'make install' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9187
+  fi
9058 9188
 
9059 9189
   echo '# update email encryption script' >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
9060 9190
   echo "if [ -d $INSTALL_DIR/gpgit ]; then" >> /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
@@ -9511,6 +9641,7 @@ install_owncloud
9511 9641
 install_owncloud_music_app
9512 9642
 install_gogs
9513 9643
 install_xmpp
9644
+install_tox_node
9514 9645
 configure_firewall_for_xmpp
9515 9646
 install_irc_server
9516 9647
 configure_firewall_for_irc