Separate tracker utils

This commit is contained in:
Bob Mottram 2016-08-24 22:45:45 +01:00
parent e0a800f608
commit a6d36eb13e
No known key found for this signature in database
GPG Key ID: 0452CC7CEA982E38
3 changed files with 171 additions and 14 deletions

View File

@ -67,36 +67,77 @@ function remove_librevault {
if ! grep -Fxq "install_librevault" $COMPLETION_FILE; then if ! grep -Fxq "install_librevault" $COMPLETION_FILE; then
return return
fi fi
iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT if [ $LIBREVAULT_PORT ]; then
iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT iptables -D INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
function_check save_firewall_settings iptables -D INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
save_firewall_settings function_check save_firewall_settings
save_firewall_settings
fi
systemctl stop librevault systemctl stop librevault
systemctl disable librevault systemctl disable librevault
rm /etc/systemd/system/librevault.service rm /etc/systemd/system/librevault.service
sed -i '/install_librevault/d' $COMPLETION_FILE sed -i '/install_librevault/d' $COMPLETION_FILE
sed -i '/configure_firewall_for_librevault/d' $COMPLETION_FILE sed -i '/configure_firewall_for_librevault/d' $COMPLETION_FILE
systemctl restart cron
} }
function configure_firewall_for_librevault { function configure_firewall_for_librevault {
if grep -Fxq "configure_firewall_for_librevault" $COMPLETION_FILE; then if grep -Fxq "configure_firewall_for_librevault" $COMPLETION_FILE; then
return return
fi fi
iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT if [ $LIBREVAULT_PORT ]; then
iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT iptables -A INPUT -p udp --dport $LIBREVAULT_PORT -j ACCEPT
function_check save_firewall_settings iptables -A INPUT -p tcp --dport $LIBREVAULT_PORT -j ACCEPT
save_firewall_settings function_check save_firewall_settings
save_firewall_settings
OPEN_PORTS+=("Librevault $LIBREVAULT_PORT") OPEN_PORTS+=("Librevault $LIBREVAULT_PORT")
fi
echo 'configure_firewall_for_librevault' >> $COMPLETION_FILE echo 'configure_firewall_for_librevault' >> $COMPLETION_FILE
} }
function mesh_install_syncthing { function mesh_install_librevault {
install_tracker
chroot "$rootdir" apt-get -y -t jessie-backports install cmake
chroot "$rootdir" apt-get -y install bittornado nginx
chroot "$rootdir" apt-get -y install build-essential libboost-all-dev libssl-dev
chroot "$rootdir" apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
chroot "$rootdir" apt-get -y install autoconf automake libtool curl make g++ unzip
if [ ! -d $rootdir$INSTALL_DIR ]; then
chroot "$rootdir" mkdir -p $INSTALL_DIR
fi
chroot "$rootdir" git clone $PROTOBUF_REPO $rootdir$INSTALL_DIR/protobuf
cd $rootdir$INSTALL_DIR/protobuf
git checkout $PROTOBUF_COMMIT -b $PROTOBUF_COMMIT
cat <<EOF > $rootdir/root/install_protobuf
cd $INSTALL_DIR/protobuf
./autogen.sh
./configure
make
make install
ldconfig
EOF
chroot "$rootdir" chmod +x /root/install_protobuf
chroot "$rootdir" /root/install_protobuf
git_clone $LIBREVAULT_REPO $rootdir$INSTALL_DIR/librevault
cd $rootdir$INSTALL_DIR/librevault
git checkout $LIBREVAULT_COMMIT -b $LIBREVAULT_COMMIT
mkdir $rootdir$INSTALL_DIR/librevault/build
cat <<EOF > $rootdir/root/install_librevault
cd $INSTALL_DIR/librevault/build
cmake ..
cmake --build .
make install
EOF
chroot "$rootdir" chmod +x /root/install_librevault
chroot "$rootdir" /root/install_librevault
} }
function install_syncthing { function install_librevault {
if [ $INSTALLING_MESH ]; then if [ $INSTALLING_MESH ]; then
mesh_install_librevault mesh_install_librevault
return return
@ -106,7 +147,10 @@ function install_syncthing {
return return
fi fi
apt-get -y install build-essential cmake libboost-all-dev libssl-dev install_tracker
apt-get -y -t jessie-backports install cmake
apt-get -y install build-essential libboost-all-dev libssl-dev
apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev apt-get -y install qtbase5-dev libqt5svg5-dev libqt5websockets5-dev
apt-get -y install autoconf automake libtool curl make g++ unzip apt-get -y install autoconf automake libtool curl make g++ unzip
@ -130,6 +174,7 @@ function install_syncthing {
cd $INSTALL_DIR/librevault/build cd $INSTALL_DIR/librevault/build
cmake .. cmake ..
cmake --build . cmake --build .
make install
echo 'install_librevault' >> $COMPLETION_FILE echo 'install_librevault' >> $COMPLETION_FILE
} }

View File

@ -62,6 +62,7 @@ fi
ZERONET_PORT=15441 ZERONET_PORT=15441
IPFS_PORT=4001 IPFS_PORT=4001
TOX_PORT=33445 TOX_PORT=33445
TRACKER_PORT=6969
# Ethernet bridge definition (bridged to bat0) # Ethernet bridge definition (bridged to bat0)
BRIDGE=br-mesh BRIDGE=br-mesh
@ -124,6 +125,10 @@ function stop {
ifconfig $IFACE down ifconfig $IFACE down
iwconfig $IFACE mode managed iwconfig $IFACE mode managed
iptables -D INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT
iptables -D INPUT -p udp --dport $TRACKER_PORT -j ACCEPT
iptables -D INPUT -p tcp --dport 80 -j ACCEPT
iptables -D INPUT -p udp --dport 80 -j ACCEPT
iptables -D INPUT -p tcp --dport 548 -j ACCEPT iptables -D INPUT -p tcp --dport 548 -j ACCEPT
iptables -D INPUT -p udp --dport 548 -j ACCEPT iptables -D INPUT -p udp --dport 548 -j ACCEPT
iptables -D INPUT -p tcp --dport 5353 -j ACCEPT iptables -D INPUT -p tcp --dport 5353 -j ACCEPT
@ -226,6 +231,10 @@ function start {
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
iptables -A INPUT -p tcp --dport $TRACKER_PORT -j ACCEPT
iptables -A INPUT -p udp --dport $TRACKER_PORT -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p udp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 548 -j ACCEPT iptables -A INPUT -p tcp --dport 548 -j ACCEPT
iptables -A INPUT -p udp --dport 548 -j ACCEPT iptables -A INPUT -p udp --dport 548 -j ACCEPT
iptables -A INPUT -p tcp --dport 5353 -j ACCEPT iptables -A INPUT -p tcp --dport 5353 -j ACCEPT

103
src/freedombone-utils-tracker Executable file
View File

@ -0,0 +1,103 @@
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Torrent tracker functions
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
TRACKER_PORT=6969
function mesh_install_tracker {
chroot "$rootdir" apt-get -y install bittornado nginx
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=/var/lib/tracker" >> $TRACKER_DAEMON
echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /var/lib/tracker/dstate --logfile /var/lib/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 "$rootdir" useradd -d /var/lib/tracker/ -s /bin/false tracker
if [ ! -d $rootdir/var/lib/tracker ]; then
mkdir $rootdir/var/lib/tracker
fi
chroot "$rootdir" chown -R tracker:tracker /var/lib/tracker
chroot "$rootdir" systemctl enable tracker.service
}
function install_tracker {
if [ $INSTALLING_MESH ]; then
mesh_install_tracker
return
fi
if grep -Fxq "install_tracker" $COMPLETION_FILE; then
return
fi
apt-get -y install bittornado nginx
TRACKER_DAEMON=/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=/var/lib/tracker" >> $TRACKER_DAEMON
echo "ExecStart=/usr/bin/bttrack --port $TRACKER_PORT --dfile /var/lib/tracker/dstate --logfile /var/lib/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
useradd -d /var/lib/tracker/ -s /bin/false tracker
if [ ! -d /var/lib/tracker ]; then
mkdir /var/lib/tracker
fi
chown -R tracker:tracker /var/lib/tracker
systemctl enable tracker.service
systemctl start tracker.service
echo 'install_tracker' >> $COMPLETION_FILE
}
# NOTE: deliberately no exit 0