freedombone-utils-tracker 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Torrent tracker functions
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. TRACKER_PORT=6969
  29. function mesh_install_tracker {
  30. # shellcheck disable=SC2154
  31. chroot "$rootdir" apt-get -yq install bittornado nginx
  32. TRACKER_DAEMON=$rootdir/etc/systemd/system/tracker.service
  33. { echo '[Unit]'
  34. echo 'Description=Torrent Tracker';
  35. echo 'After=syslog.target';
  36. echo 'After=network.target';
  37. echo '[Service]';
  38. echo 'Type=simple';
  39. echo 'User=tracker';
  40. echo 'Group=tracker';
  41. echo "WorkingDirectory=/var/lib/tracker";
  42. 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";
  43. echo '';
  44. echo 'TimeoutSec=300';
  45. echo '';
  46. echo '[Install]';
  47. echo 'WantedBy=multi-user.target'; } > "$TRACKER_DAEMON"
  48. chroot "$rootdir" useradd -d /var/lib/tracker/ -s /bin/false tracker
  49. if [ ! -d "$rootdir/var/lib/tracker" ]; then
  50. mkdir "$rootdir/var/lib/tracker"
  51. fi
  52. chroot "$rootdir" chown -R tracker:tracker /var/lib/tracker
  53. chroot "$rootdir" systemctl enable tracker.service
  54. }
  55. function install_tracker {
  56. if [ "$INSTALLING_MESH" ]; then
  57. mesh_install_tracker
  58. return
  59. fi
  60. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  61. return
  62. fi
  63. apt-get -yq install bittornado nginx
  64. TRACKER_DAEMON=/etc/systemd/system/tracker.service
  65. { echo '[Unit]';
  66. echo 'Description=Torrent Tracker';
  67. echo 'After=syslog.target';
  68. echo 'After=network.target';
  69. echo '[Service]';
  70. echo 'Type=simple';
  71. echo 'User=tracker';
  72. echo 'Group=tracker';
  73. echo "WorkingDirectory=/var/lib/tracker";
  74. 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";
  75. echo '';
  76. echo 'TimeoutSec=300';
  77. echo '';
  78. echo '[Install]';
  79. echo 'WantedBy=multi-user.target'; } > "$TRACKER_DAEMON"
  80. useradd -d /var/lib/tracker/ -s /bin/false tracker
  81. if [ ! -d /var/lib/tracker ]; then
  82. mkdir /var/lib/tracker
  83. fi
  84. chown -R tracker:tracker /var/lib/tracker
  85. systemctl enable tracker.service
  86. systemctl start tracker.service
  87. mark_completed "${FUNCNAME[0]}"
  88. }
  89. # NOTE: deliberately no exit 0