freedombone-utils-tracker 3.4KB

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