freedombone/src/freedombone-utils-tracker

103 lines
3.3 KiB
Plaintext
Raw Permalink Normal View History

2016-08-24 23:45:45 +02:00
#!/bin/bash
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2016-08-24 23:45:45 +02:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2016-08-24 23:45:45 +02:00
#
# Torrent tracker functions
#
# License
# =======
#
2018-02-21 20:32:13 +01:00
# Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
2016-08-24 23:45:45 +02:00
#
# 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 {
2018-03-02 23:20:49 +01:00
# shellcheck disable=SC2154
2016-10-23 20:38:14 +02:00
chroot "$rootdir" apt-get -yq install bittornado nginx
2016-08-24 23:45:45 +02:00
TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
2018-03-02 23:20:49 +01:00
{ 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"
2016-08-24 23:45:45 +02:00
chroot "$rootdir" useradd -d /var/lib/tracker/ -s /bin/false tracker
2018-03-02 23:20:49 +01:00
if [ ! -d "$rootdir/var/lib/tracker" ]; then
mkdir "$rootdir/var/lib/tracker"
2016-08-24 23:45:45 +02:00
fi
chroot "$rootdir" chown -R tracker:tracker /var/lib/tracker
chroot "$rootdir" systemctl enable tracker.service
}
function install_tracker {
2018-03-02 23:20:49 +01:00
if [ "$INSTALLING_MESH" ]; then
2016-08-24 23:45:45 +02:00
mesh_install_tracker
return
fi
2018-02-25 13:50:46 +01:00
if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
2016-08-24 23:45:45 +02:00
return
fi
2016-10-23 20:38:14 +02:00
apt-get -yq install bittornado nginx
2016-08-24 23:45:45 +02:00
TRACKER_DAEMON=/etc/systemd/system/tracker.service
2018-03-02 23:20:49 +01:00
{ 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"
2016-08-24 23:45:45 +02:00
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
2018-02-25 13:50:46 +01:00
mark_completed "${FUNCNAME[0]}"
2016-08-24 23:45:45 +02:00
}
# NOTE: deliberately no exit 0