From 350ab2682f1a3fa833a5699feb8678f0ef60021e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 17 Jul 2016 17:20:16 +0100 Subject: [PATCH] Remove duplicate functions --- src/freedombone-app-zeronet | 28 --- src/freedombone-mesh-install | 328 ----------------------------------- 2 files changed, 356 deletions(-) diff --git a/src/freedombone-app-zeronet b/src/freedombone-app-zeronet index 03b776c3..bb4620e6 100755 --- a/src/freedombone-app-zeronet +++ b/src/freedombone-app-zeronet @@ -461,34 +461,6 @@ function install_zeronet_main { } function mesh_zeronet { - # obtain commits from the main file - ZERONET_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}') - if [ ${#ZERONET_COMMIT_MAIN} -gt 10 ]; then - ZERONET_COMMIT=$ZERONET_COMMIT_MAIN - fi - if [ ! $ZERONET_COMMIT ]; then - echo $'No Tox commit was specified' - exit 37046 - fi - - ZERONET_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}') - if [ ${#ZERONET_REPO_MAIN} -gt 5 ]; then - ZERONET_REPO=$ZERONET_REPO_MAIN - fi - if [ ! $ZERONET_REPO ]; then - echo $'No Tox commit was specified' - exit 37046 - fi - - ZERONET_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}') - if [ ${#ZERONET_PORT_MAIN} -gt 1 ]; then - ZERONET_PORT=$ZERONET_PORT_MAIN - fi - if [ ! $ZERONET_PORT ]; then - echo $'No zeronet port was specified' - exit 67433 - fi - chroot "$rootdir" apt-get -y install python python-msgpack python-gevent chroot "$rootdir" apt-get -y install python-pip bittornado chroot "$rootdir" pip install msgpack-python --upgrade diff --git a/src/freedombone-mesh-install b/src/freedombone-mesh-install index 6c1483fd..f63c7bec 100755 --- a/src/freedombone-mesh-install +++ b/src/freedombone-mesh-install @@ -425,194 +425,6 @@ function mesh_firewall { $CHROOT_PREFIX systemctl enable meshfirewall } -function mesh_tox_node_remove { - systemctl stop tox-bootstrapd - systemctl disable tox-bootstrapd - if [ -f /etc/systemd/system/tox-bootstrapd.service ]; then - rm /etc/systemd/system/tox-bootstrapd.service - fi - if [ -d $INSTALL_DIR/toxcore ]; then - cd $INSTALL_DIR/toxcore - make uninstall - rm -rf $INSTALL_DIR/toxcore - fi - if [ -f /etc/tox-bootstrapd.conf ]; then - rm /etc/tox-bootstrapd.conf - fi -} - -function mesh_tox_node { - # obtain commits from the main file - TOXCORE_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_COMMIT=" | head -n 1 | awk -F "'" '{print $2}') - if [ ${#TOXCORE_COMMIT_MAIN} -gt 10 ]; then - TOXCORE_COMMIT=$TOXCORE_COMMIT_MAIN - fi - if [ ! $TOXCORE_COMMIT ]; then - echo $'No Tox commit was specified' - exit 76325 - fi - - TOXID_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXID_REPO=" | head -n 1 | awk -F '"' '{print $2}') - if [ ${#TOXID_REPO_MAIN} -gt 5 ]; then - TOXID_REPO=$TOXID_REPO_MAIN - fi - if [ ! $TOXID_REPO ]; then - echo $'No ToxID repo was specified' - exit 78252 - fi - - TOX_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOX_PORT=" | head -n 1 | awk -F '=' '{print $2}') - if [ ${#TOX_PORT_MAIN} -gt 2 ]; then - TOX_PORT=$TOX_PORT_MAIN - fi - if [ ! $TOX_PORT ]; then - echo $'No Tox port was specified' - exit 32856 - fi - - TOXCORE_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXCORE_REPO=" | head -n 1 | awk -F '"' '{print $2}') - if [ ${#TOXCORE_REPO_MAIN} -gt 10 ]; then - TOXCORE_REPO=$TOXCORE_REPO_MAIN - fi - if [ ! $TOXCORE_REPO ]; then - echo $'No Tox repo was specified' - exit 16865 - fi - - $CHROOT_PREFIX apt-get -y install build-essential libtool autotools-dev - $CHROOT_PREFIX apt-get -y install automake checkinstall check git yasm - $CHROOT_PREFIX apt-get -y install libsodium13 libsodium-dev libcap2-bin - $CHROOT_PREFIX apt-get -y install libconfig9 libconfig-dev - - $CHROOT_PREFIX mkdir -p $INSTALL_DIR - $CHROOT_PREFIX git_clone $TOXCORE_REPO $INSTALL_DIR/toxcore - $CHROOT_PREFIX cd $INSTALL_DIR/toxcore - $CHROOT_PREFIX git checkout $TOXCORE_COMMIT -b $TOXCORE_COMMIT - - $CHROOT_PREFIX autoreconf -i - $CHROOT_PREFIX ./configure --enable-daemon --disable-av - $CHROOT_PREFIX make clean - $CHROOT_PREFIX make -k - if [ ! "$?" = "0" ]; then - return - fi - $CHROOT_PREFIX make install - $CHROOT_PREFIX cp /usr/local/lib/libtoxcore* /usr/lib/ - - if [ ! -f $rootdir/usr/local/bin/tox-bootstrapd ]; then - echo $"File not found /usr/local/bin/tox-bootstrapd" - return - fi - - $CHROOT_PREFIX 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 - $CHROOT_PREFIX chmod 700 /var/lib/tox-bootstrapd - if [ ! -f $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf ]; then - echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.conf" - fi - # remove Maildir - if [ -d $rootdir/var/lib/tox-bootstrapd/Maildir ]; then - rm -rf $rootdir/var/lib/tox-bootstrapd/Maildir - fi - - # create configuration file - TOX_BOOTSTRAP_CONFIG=${rootdir}/etc/tox-bootstrapd.conf - echo "port = $TOX_PORT" > $TOX_BOOTSTRAP_CONFIG - echo 'keys_file_path = "/var/lib/tox-bootstrapd/keys"' >> $TOX_BOOTSTRAP_CONFIG - echo 'pid_file_path = "/var/run/tox-bootstrapd/tox-bootstrapd.pid"' >> $TOX_BOOTSTRAP_CONFIG - echo 'enable_ipv6 = true' >> $TOX_BOOTSTRAP_CONFIG - echo 'enable_ipv4_fallback = true' >> $TOX_BOOTSTRAP_CONFIG - echo 'enable_lan_discovery = true' >> $TOX_BOOTSTRAP_CONFIG - echo 'enable_tcp_relay = true' >> $TOX_BOOTSTRAP_CONFIG - echo "tcp_relay_ports = [443, 3389, $TOX_PORT]" >> $TOX_BOOTSTRAP_CONFIG - echo 'enable_motd = true' >> $TOX_BOOTSTRAP_CONFIG - echo 'motd = "tox-bootstrapd"' >> $TOX_BOOTSTRAP_CONFIG - - if [ $TOX_NODES ]; then - echo 'bootstrap_nodes = (' >> $TOX_BOOTSTRAP_CONFIG - toxcount=0 - while [ "x${TOX_NODES[toxcount]}" != "x" ] - do - toxval_ipv4=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $1}') - toxval_ipv6=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $2}') - toxval_port=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $3}') - toxval_pubkey=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $4}') - toxval_maintainer=$(echo $TOX_NODES[toxcount] | awk -F ',' '{print $5}') - echo "{ // $toxval_maintainer" >> $TOX_BOOTSTRAP_CONFIG - if [[ $toxval_ipv6 != 'NONE' ]]; then - echo " address = \"$toxval_ipv6\"" >> $TOX_BOOTSTRAP_CONFIG - else - echo " address = \"$toxval_ipv4\"" >> $TOX_BOOTSTRAP_CONFIG - fi - echo " port = $toxval_port" >> $TOX_BOOTSTRAP_CONFIG - echo " public_key = \"$toxval_pubkey\"" >> $TOX_BOOTSTRAP_CONFIG - toxcount=$(( $toxcount + 1 )) - if [ "x${TOX_NODES[toxcount]}" != "x" ]; then - echo "}," >> $TOX_BOOTSTRAP_CONFIG - else - echo "}" >> $TOX_BOOTSTRAP_CONFIG - fi - done - echo ')' >> $TOX_BOOTSTRAP_CONFIG - fi - - if [ ! -f $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service ]; then - echo $"File not found $INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service" - return - fi - cp $rootdir/$INSTALL_DIR/toxcore/other/bootstrap_daemon/tox-bootstrapd.service $rootdir/etc/systemd/system/ - sed -i 's|ExecStart=.*|ExecStart=/usr/local/bin/tox-bootstrapd --config /etc/tox-bootstrapd.conf|g' $rootdir/etc/systemd/system/tox-bootstrapd.service - - $CHROOT_PREFIX systemctl daemon-reload - $CHROOT_PREFIX systemctl enable tox-bootstrapd.service -} - -function mesh_tox_client_remove { - if [ ! -d $INSTALL_DIR/toxic ]; then - return - fi - cd $INSTALL_DIR/toxic - make uninstall - rm -rf $INSTALL_DIR/toxic -} - -function mesh_tox_client { - TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}') - - # obtain commits from the main file - TOXIC_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_COMMIT=" | head -n 1 | awk -F "'" '{print $2}') - if [ ${#TOXIC_COMMIT_MAIN} -gt 10 ]; then - TOXIC_COMMIT=$TOXIC_COMMIT_MAIN - fi - - TOXIC_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_REPO=" | head -n 1 | awk -F '"' '{print $2}') - if [ ${#TOXIC_REPO_MAIN} -gt 5 ]; then - TOXIC_REPO=$TOXIC_REPO_MAIN - fi - - $CHROOT_PREFIX apt-get -y install libncursesw5-dev libconfig-dev libqrencode-dev - $CHROOT_PREFIX apt-get -y install libcurl4-openssl-dev libvpx-dev libopenal-dev - - $CHROOT_PREFIX git_clone $TOXIC_REPO $INSTALL_DIR/toxic - $CHROOT_PREFIX cd $INSTALL_DIR/toxic - $CHROOT_PREFIX git checkout $TOXIC_COMMIT -b $TOXIC_COMMIT - if ! grep -q "Toxic commit" $rootdir$COMPLETION_FILE; then - echo "Toxic commit:$TOXIC_COMMIT" >> $rootdir$COMPLETION_FILE - else - sed -i "s|Toxic commit.*|Toxic commit:$TOXIC_COMMIT|g" $rootdir$COMPLETION_FILE - fi - - $CHROOT_PREFIX make clean - $CHROOT_PREFIX make -k - if [ ! -f $INSTALL_DIR/toxic/build/toxic ]; then - exit 74872 - fi - $CHROOT_PREFIX make install - if [ ! -f $TOXIC_FILE ]; then - echo $'Tox client was not installed' - exit 63278 - fi -} - function enable_tox_repo { sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/antonbatenev:/tox/Debian_8.0/ /' > /etc/apt/sources.list.d/tox.list" wget http://download.opensuse.org/repositories/home:antonbatenev:tox/Debian_8.0/Release.key @@ -633,125 +445,6 @@ function mesh_tox_client_toxic_from_repo { echo "Toxic Installed." } -function mesh_zeronet_remove { - systemctl stop zeronet - systemctl disable zeronet - systemctl stop tracker - systemctl disable tracker - $CHROOT_PREFIX apt-get -y remove --purge bittornado - if [ -f $rootdir/etc/systemd/system/zeronet.service ]; then - rm $rootdir/etc/systemd/system/zeronet.service - fi - if [ -f $rootdir/etc/systemd/system/tracker.service ]; then - rm $rootdir/etc/systemd/system/tracker.service - fi - if [ -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then - rm -rf $rootdir$MESH_INSTALL_DIR/zeronet - fi - userdel -r zeronet -} - -function mesh_zeronet { - # obtain commits from the main file - ZERONET_COMMIT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_COMMIT=" | head -n 1 | awk -F "'" '{print $2}') - if [ ${#ZERONET_COMMIT_MAIN} -gt 10 ]; then - ZERONET_COMMIT=$ZERONET_COMMIT_MAIN - fi - if [ ! $ZERONET_COMMIT ]; then - echo $'No Tox commit was specified' - exit 37046 - fi - - ZERONET_REPO_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_REPO=" | head -n 1 | awk -F '"' '{print $2}') - if [ ${#ZERONET_REPO_MAIN} -gt 5 ]; then - ZERONET_REPO=$ZERONET_REPO_MAIN - fi - if [ ! $ZERONET_REPO ]; then - echo $'No Tox commit was specified' - exit 37046 - fi - - ZERONET_PORT_MAIN=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-zeronet | grep "ZERONET_PORT=" | head -n 1 | awk -F '=' '{print $2}') - if [ ${#ZERONET_PORT_MAIN} -gt 1 ]; then - ZERONET_PORT=$ZERONET_PORT_MAIN - fi - if [ ! $ZERONET_PORT ]; then - echo $'No zeronet port was specified' - exit 67433 - fi - - $CHROOT_PREFIX apt-get -y install python python-msgpack python-gevent - $CHROOT_PREFIX apt-get -y install python-pip bittornado - $CHROOT_PREFIX pip install msgpack-python --upgrade - $CHROOT_PREFIX pip install gevent --upgrade - - $CHROOT_PREFIX useradd -d $MESH_INSTALL_DIR/zeronet/ -s /bin/false zeronet - git_clone $ZERONET_REPO $rootdir$MESH_INSTALL_DIR/zeronet - if [ ! -d $rootdir$MESH_INSTALL_DIR/zeronet ]; then - echo 'WARNING: Unable to clone zeronet' - return - fi - cd $rootdir$MESH_INSTALL_DIR/zeronet - git checkout $ZERONET_COMMIT -b $ZERONET_COMMIT - if ! grep -q "ZeroNet commit" $COMPLETION_FILE; then - echo "ZeroNet commit:$ZERONET_COMMIT" >> $rootdir$COMPLETION_FILE - else - sed -i "s/ZeroNet commit.*/ZeroNet commit:$ZERONET_COMMIT/g" $COMPLETION_FILE - fi - chown -R zeronet:zeronet $rootdir$MESH_INSTALL_DIR/zeronet - - # Hack to ensure that the file access port is opened - # This is because zeronet normally relies on an internet site - # to do this, but on a purely local mesh the internet isn't available - sed -i 's|fileserver_port = 0|fileserver_port = config.fileserver_port\n sys.modules["main"].file_server.port_opened = True|g' $rootdir$MESH_INSTALL_DIR/zeronet/src/Site/Site.py - - ZERPNET_DAEMON=$rootdir/etc/systemd/system/zeronet.service - echo '[Unit]' > $ZERONET_DAEMON - echo 'Description=Zeronet Server' >> $ZERONET_DAEMON - echo 'After=syslog.target' >> $ZERONET_DAEMON - echo 'After=network.target' >> $ZERONET_DAEMON - echo '[Service]' >> $ZERONET_DAEMON - echo 'Type=simple' >> $ZERONET_DAEMON - echo 'User=zeronet' >> $ZERONET_DAEMON - echo 'Group=zeronet' >> $ZERONET_DAEMON - echo "WorkingDirectory=$MESH_INSTALL_DIR/zeronet" >> $ZERONET_DAEMON - echo "ExecStart=/usr/bin/python zeronet.py --ip_external replace.local --trackers_file $MESH_INSTALL_DIR/zeronet/bootstrap" >> $ZERONET_DAEMON - echo '' >> $ZERONET_DAEMON - echo 'TimeoutSec=300' >> $ZERONET_DAEMON - echo '' >> $ZERONET_DAEMON - echo '[Install]' >> $ZERONET_DAEMON - echo 'WantedBy=multi-user.target' >> $ZERONET_DAEMON - - TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service - echo '[Unit]' > $TRACKER_DAEMON - echo 'Description=Torrent Tracker' >> $TRACKER_DAEMON - echo 'After=syslog.target' >> $TRACKER_DAEMON - echo 'After=network.target' >> $TRACKER_DAEMON - echo '[Service]' >> $TRACKER_DAEMON - echo 'Type=simple' >> $TRACKER_DAEMON - echo 'User=tracker' >> $TRACKER_DAEMON - echo 'Group=tracker' >> $TRACKER_DAEMON - echo "WorkingDirectory=$MESH_INSTALL_DIR/tracker" >> $TRACKER_DAEMON - echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile $MESH_INSTALL_DIR/tracker/dstate --logfile $MESH_INSTALL_DIR/tracker/tracker.log --nat_check 0 --scrape_allowed full --ipv6_enabled 0" >> $TRACKER_DAEMON - echo '' >> $TRACKER_DAEMON - echo 'TimeoutSec=300' >> $TRACKER_DAEMON - echo '' >> $TRACKER_DAEMON - echo '[Install]' >> $TRACKER_DAEMON - echo 'WantedBy=multi-user.target' >> $TRACKER_DAEMON - - $CHROOT_PREFIX useradd -d $MESH_INSTALL_DIR/tracker/ -s /bin/false tracker - if [ ! -d $rootdir$MESH_INSTALL_DIR/tracker ]; then - mkdir $rootdir$MESH_INSTALL_DIR/tracker - fi - chown -R tracker:tracker $rootdir$MESH_INSTALL_DIR/tracker - - # publish regularly - echo "* * * * * root zeronetavahi > /dev/null" >> $rootdir/etc/crontab - - $CHROOT_PREFIX systemctl enable tracker.service - $CHROOT_PREFIX systemctl enable zeronet.service -} - function install_batman_client { TOXIC_FILE=$(cat /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-tox | grep "TOXIC_FILE=" | head -n 1 | awk -F '=' '{print $2}') @@ -1074,27 +767,6 @@ fi if [[ $FN == 'batman_client' ]]; then install_batman_client fi -if [[ $FN == 'tox_node' ]]; then - if [[ $REMOVE != 'yes' ]]; then - mesh_tox_node - else - mesh_tox_node_remove - fi -fi -if [[ $FN == 'tox_client' ]]; then - if [[ $REMOVE != 'yes' ]]; then - mesh_tox_client - else - mesh_tox_client_remove - fi -fi -if [[ $FN == 'zeronet' ]]; then - if [[ $REMOVE != 'yes' ]]; then - mesh_zeronet - else - mesh_zeronet_remove - fi -fi if [[ $FN == 'qtox' ]]; then mesh_tox_client_qtox fi