freedomboneeee/src/freedombone-utils-tracker

105 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Torrent tracker functions
#
# License
# =======
#
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
#
# 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 {
# shellcheck disable=SC2154
chroot "$rootdir" apt-get -yq install bittornado nginx
TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
{ echo '[Unit]'
echo 'Description=Torrent Tracker';
echo 'After=syslog.target';
echo 'After=network.target';
echo '[Service]';
echo 'Type=simple';
echo 'User=tracker';
echo 'Group=tracker';
echo "WorkingDirectory=/var/lib/tracker";
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";
echo '';
echo 'TimeoutSec=300';
echo '';
echo '[Install]';
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 [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
return
fi
apt-get -yq install bittornado nginx
TRACKER_DAEMON=/etc/systemd/system/tracker.service
{ echo '[Unit]';
echo 'Description=Torrent Tracker';
echo 'After=syslog.target';
echo 'After=network.target';
echo '[Service]';
echo 'Type=simple';
echo 'User=tracker';
echo 'Group=tracker';
echo "WorkingDirectory=/var/lib/tracker";
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";
echo '';
echo 'TimeoutSec=300';
echo '';
echo '[Install]';
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
mark_completed "${FUNCNAME[0]}"
}
# NOTE: deliberately no exit 0