diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/README.md b/README.md index e144ad2..b148721 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,13 @@ Nice=19 #### Choose your destiny: -[Docker way](https://github.com/AndrewMarchukov/tracker-add#-docker-way) +[Docker way](#-docker-way) -[Systemd way](https://github.com/AndrewMarchukov/tracker-add#-systemd-way) +[Systemd way](#-systemd-way) -[Simple way (for routers)](https://github.com/AndrewMarchukov/tracker-add#-simple-way-for-routers) +[FreeBSD service way](#-freebsd-service-way) + +[Simple way (for routers)](#-simple-way-for-routers) ## Installation and usage @@ -95,6 +97,29 @@ systemctl status transmission-tracker-add.service ``` + +#### * FreeBSD service way + +Edit settings.json for transmission set rpc-enabled, rpc-username and rpc-password + +Download scripts and make it executable: +```bash +install -d /opt/bin +fetch -o /opt/bin/add-trackers-auto.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker-add-auto.sh +fetch -o /usr/local/etc/rc.d/transmission_tracker_add https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/transmission_tracker_add +chmod +x /opt/bin/add-trackers-auto.sh /usr/local/etc/rc.d/transmission_tracker_add +``` + +Set user and password in `add-trackers-auto.sh`: +```bash +nano /opt/bin/add-trackers-auto.sh +``` + +Start service: +```bash +service transmission_tracker_add start +``` + #### * Simple way (for routers) Requirements: curl, transmission-remote diff --git a/tracker-add-auto-router.sh b/tracker-add-auto-router.sh old mode 100644 new mode 100755 diff --git a/tracker-add-auto.sh b/tracker-add-auto.sh old mode 100644 new mode 100755 index 2acd3d2..31409fe --- a/tracker-add-auto.sh +++ b/tracker-add-auto.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Get transmission credentials and ip or dns address auth=user:password host=localhost @@ -6,6 +6,8 @@ host=localhost trackers=https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt pt_trackers=() +trans="/usr/local/bin/transmission-remote $host --auth=$auth" + while true; do sleep 25 add_trackers() { @@ -25,7 +27,7 @@ while true; do echo "Adding trackers for $torrent_name..." for tracker in $(cat $trackerslist); do echo -n "${tracker}..." - if transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then + if ${trans} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then echo ' done.' else echo ' already added.' @@ -36,13 +38,13 @@ while true; do rm -f "/tmp/TTAA.$id.lock" } # Get list of active torrents - ids="$(transmission-remote "$host" --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }')" + ids="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }')" for id in $ids; do - add_date="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Date added: ' | cut -c 21-)" + add_date="$(${trans} --torrent "$id" --info | grep '^ Date added: ' | cut -c 21-)" add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")" dater="$(date "+%Y-%m-%d %H:%M")" dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")" - tracker0="$(transmission-remote "$host" --auth="$auth" -t "$id" -it | sed -n '2,2p' | awk '{print $3}' | awk -F : '{print $2}' | sed -e 's/\/\///')" + tracker0="$(${trans} -t "$id" -it | sed -n '2,2p' | awk '{print $3}' | awk -F : '{print $2}' | sed -e 's/\/\///')" if [[ " ${pt_trackers[@]} " =~ " $tracker0 " ]]; then echo "skip id=" "$id" "$tracker0" continue @@ -50,8 +52,8 @@ while true; do if [ ! -f "/tmp/TTAA.$id.lock" ]; then if [[ "( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" )" ]]; then - hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')" - torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' | cut -c 9-)" + hash="$(${trans} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')" + torrent_name="$(${trans} --torrent "$id" --info | grep '^ Name: ' | cut -c 9-)" add_trackers "$hash" "$id" & touch "/tmp/TTAA.$id.lock" fi diff --git a/transmission_tracker_add b/transmission_tracker_add new file mode 100755 index 0000000..616332e --- /dev/null +++ b/transmission_tracker_add @@ -0,0 +1,22 @@ +#!/bin/sh +# +# PROVIDE: transmission_tracker_add +# REQUIRE: DAEMON +# KEYWORD: shutdown + +. /etc/rc.subr + +name=transmission_tracker_add +rcvar=transmission_tracker_add_enable + +load_rc_config $name + +: ${transmission_tracker_add_enable:=YES} + +pidfile=/var/run/transmission/tracker-add.pid +command="/usr/sbin/daemon" +task="/opt/bin/add-trackers-auto.sh" +procname="/bin/sh" +command_args="-p ${pidfile} ${task}" + +run_rc_command "$1"