diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..91ccc92 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +- package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 10 +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + open-pull-requests-limit: 10 diff --git a/README.md b/README.md index 4df5f70..31969dd 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,88 @@ -# Get more trackers +# Get more trackers, get more seeders, get more peers transmission +[![Docker Image CI](https://github.com/AndrewMarchukov/tracker-add/actions/workflows/docker-image.yml/badge.svg?branch=docker)](https://github.com/AndrewMarchukov/tracker-add/actions/workflows/docker-image.yml) [![](https://images.microbadger.com/badges/version/andrewmhub/transmission-tracker-add.svg)](https://microbadger.com/images/andrewmhub/transmission-tracker-add) ![Docker Pulls](https://img.shields.io/docker/pulls/andrewmhub/transmission-tracker-add.svg) ![GitHub top language](https://img.shields.io/github/languages/top/AndrewMarchukov/tracker-add.svg) ![Docker Image Size (tag)](https://img.shields.io/docker/image-size/andrewmhub/transmission-tracker-add/latest) -See no peers for some torrent(s)? Add more tracker(s) from Transmission +See no peers,seeds for some torrent(s)? Add more tracker(s) for Transmission + +This script automatically checks new torrents and adds trackers + +
+ FAQ: + +``` +Q: Requirements? +A: curl, transmission-remote or\and transmission-cli + +Q: How often does this check for updates for new trackers? +A: Only when adding new torrent in transmission and only active torrents and gap 25 seconds + +Q: Can I add tracker to a remote server? +A: Yes, host=host:port or host=http(s?)://host:port/transmission/ +``` +
+ +
+ Changelog + +``` +Mar 10, 2020 +avoid add trackers for private torrents + +Mar 27, 2019 +add tracker-add-auto-router.sh script for routers +now tracker file saved in tmp directory until update web source +new exception in "Get list of active torrents", helps to avoid fully loaded torrents +cosmetic fixes + +Feb 22, 2019 +add feature connection to host + +May 27, 2018 +wait new torrents 25 sec + +May 26, 2018 +Change systemd policy +CPUSchedulingPolicy=idle +Nice=19 +``` +
+ +#### Choose your destiny: + +[Docker way](https://github.com/AndrewMarchukov/tracker-add#-docker-way) + +[Systemd way](https://github.com/AndrewMarchukov/tracker-add#-systemd-way) + +[Simple way (for routers)](https://github.com/AndrewMarchukov/tracker-add#-simple-way-for-routers) + +## Installation and usage + +#### * Docker way + +Take image `docker pull andrewmhub/transmission-tracker-add` + +```docker run --net=host -d -e HOSTPORT=localhost:9091 -e TR_AUTH=user:password --name=transmission-tracker-add andrewmhub/transmission-tracker-add:latest``` + +if you need another torrent tracker list then use docker run env + +`-e TORRENTLIST=https://raw.githubusercontent.com/user/trackerslist/master/mylist.txt` + +you have transmission daemon in docker then read [Docker Documentation Network](https://docs.docker.com/network/) + + +#### * Systemd way + +Download script and make it executable: + +Edit settings.json for transmission set rpc-enabled, rpc-username and rpc-password -## Installation -* Download script and make it executable: -Edit settings for transmission set rpc-enabled, rpc-username and rpc-password ``` -wget --no-check-certificate -O /opt/bin/add-trackers-auto.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker_add_auto.sh +wget --no-check-certificate -O /opt/bin/add-trackers-auto.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker-add-auto.sh wget --no-check-certificate -O /etc/systemd/system/transmission-tracker-add.service https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/transmission-tracker-add.service -chmod +x /opt/bin/add_trackers_auto.sh -Set user and password in add_trackers_auto.sh -systemctl daemon-reload +chmod +x /opt/bin/add-trackers-auto.sh ``` -## Usage -Automatically checks new torrents and adds trackers: +Set user and password in add-trackers-auto.sh ``` +systemctl daemon-reload systemctl enable transmission-tracker-add.service systemctl start transmission-tracker-add.service @@ -26,13 +94,38 @@ systemctl status transmission-tracker-add.service CGroup: /system.slice/transmission-tracker-add.service ├─19102 /bin/bash /opt/bin/add-trackers-auto.sh └─31204 sleep 5 - + ``` +#### * Simple way (for routers) + +Requirements: curl, transmission-remote + +Download script and make it executable: + +Edit settings for transmission set rpc-enabled, rpc-username, rpc-password and your pt trackers + +``` +wget --no-check-certificate -O tracker-add-auto-router.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker-add-auto-router.sh +chmod +x tracker-add-auto-router.sh +``` +Set user and password in tracker-add-auto-router.sh + +``` +./tracker-add-auto-router.sh & +``` +or +``` +nohup ./tracker-add-auto-router.sh /var/log/tracker-add-auto.log 2>&1 & +``` +or +``` +screen -d -m -S tracker-add-auto path/to/tracker-add-auto-router.sh +``` -## Extra manual script if you need +### Extra manual script if you need Set user and password in manual-tracker-add.sh Run manual script to add some more trackers for active torrents: diff --git a/manual-tracker-add.sh b/manual-tracker-add.sh index b8c886a..922a663 100755 --- a/manual-tracker-add.sh +++ b/manual-tracker-add.sh @@ -1,23 +1,29 @@ #!/bin/bash -# Get transmission credentials -auth=user:password +# Get transmission credentials, if set +if [[ -n "$TRANSMISSION_USER" && -n "$TRANSMISSION_PASS" ]]; then + auth="${TRANSMISSION_USER:-user}:${TRANSMISSION_PASS:-password}" +else + auth= +fi +host=${TRANSMISSION_HOST:-localhost} +list_url=${TRACKER_URL:-https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt} add_trackers () { torrent_hash=$1 - for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do + for base_url in "${list_url}" ; do echo -e "\e[1m\e[5m" echo "URL for ${base_url}" echo -e "Adding trackers for \e[91m$torrent_name..." echo -en "\e[0m" echo -e "\e[2m\e[92m" -for tracker in $(curl -# "${base_url}") ; do +for tracker in $(curl --location -# "${base_url}") ; do echo -en "\e[0m" echo -ne "\e[93m*\e[0m ${tracker}..." -if transmission-remote --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then - echo -e '\e[91m failed.' +if transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then + echo -e '\e[92m done.' echo -en "\e[0m" else - echo -e '\e[92m done.' + echo -e '\e[93m already added.' echo -en "\e[0m" fi done @@ -25,10 +31,10 @@ done } # Get list of active torrents -ids="$(transmission-remote --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')" +ids=${1:-"$(transmission-remote "$host" ${auth:+--auth="$auth"} --list | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')"} for id in $ids ; do - hash="$(transmission-remote --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')" - torrent_name="$(transmission-remote --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)" + hash="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')" + torrent_name="$(transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)" add_trackers "$hash" done diff --git a/tracker-add-auto-router.sh b/tracker-add-auto-router.sh new file mode 100644 index 0000000..2c1875d --- /dev/null +++ b/tracker-add-auto-router.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Get transmission credentials and ip or dns address +auth=user:password +host=localhost + +while true ; do +sleep 25 +add_trackers () { + torrent_hash=$1 + id=$2 + trackerslist=/tmp/trackers.txt +for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do +if [ ! -f $trackerslist ]; then +curl -o "$trackerslist" "${base_url}" +fi +Local=$(wc -c < $trackerslist) +Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}') +if [ "$Local" != "$Remote" ]; then +curl -o "$trackerslist" "${base_url}" +fi + echo "URL for ${base_url}" + echo "Adding trackers for $torrent_name..." +for tracker in $(cat $trackerslist) ; do + echo "${tracker}..." +if transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then + echo ' failed.' +else + echo ' done.' +fi +done +done + sleep 3m + 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 }')" +for id in $ids ; do + add_date="$(transmission-remote "$host" --auth="$auth" --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 '%s' -d "$(( `date +%s`+1*60 ))" "+%Y-%m-%d %H:%M")" + +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-)" + add_trackers "$hash" "$id" & + touch "/tmp/TTAA.$id.lock" +fi +fi +done +done diff --git a/tracker-add-auto.sh b/tracker-add-auto.sh index 4fdee63..2acd3d2 100644 --- a/tracker-add-auto.sh +++ b/tracker-add-auto.sh @@ -1,41 +1,60 @@ #!/bin/bash -# Get transmission credentials +# Get transmission credentials and ip or dns address auth=user:password -while true ; do -sleep 25 -add_trackers () { - torrent_hash=$1 - id=$2 -for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do - echo "URL for ${base_url}" - echo "Adding trackers for $torrent_name..." -for tracker in $(curl -# "${base_url}") ; do - echo -n "${tracker}..." -if transmission-remote --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then - echo ' failed.' -else - echo ' done.' -fi -done -done - sleep 3m - rm -f /tmp/TTAA.$id.lock -} -# Get list of active torrents - ids="$(transmission-remote --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished' | grep '^ ' | awk '{ print $1 }')" -for id in $ids ; do - add_date="$(transmission-remote --auth="$auth" --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")" +host=localhost +# set trackers list space separated +trackers=https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt +pt_trackers=() -if [ ! -f /tmp/TTAA.$id.lock ]; then -if [[ ( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" ) ]]; then - hash="$(transmission-remote --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')" - torrent_name="$(transmission-remote --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)" - add_trackers "$hash" "$id" & - touch /tmp/TTAA.$id.lock -fi -fi -done +while true; do + sleep 25 + add_trackers() { + torrent_hash=$1 + id=$2 + trackerslist=/tmp/trackers.txt + for base_url in $trackers; do + if [ ! -f $trackerslist ]; then + curl -o "$trackerslist" "${base_url}" + fi + Local=$(wc -c <$trackerslist) + Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}') + if [ "$Local" != "$Remote" ]; then + curl -o "$trackerslist" "${base_url}" + fi + echo "URL for ${base_url}" + 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 + echo ' done.' + else + echo ' already added.' + fi + done + done + sleep 3m + 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 }')" + for id in $ids; do + add_date="$(transmission-remote "$host" --auth="$auth" --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/\/\///')" + if [[ " ${pt_trackers[@]} " =~ " $tracker0 " ]]; then + echo "skip id=" "$id" "$tracker0" + continue + fi + + 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-)" + add_trackers "$hash" "$id" & + touch "/tmp/TTAA.$id.lock" + fi + fi + done done diff --git a/transmission-tracker-add.service b/transmission-tracker-add.service index a05e90e..42d74f0 100644 --- a/transmission-tracker-add.service +++ b/transmission-tracker-add.service @@ -3,8 +3,10 @@ Description=transmission tracker add Requires=network.target [Service] +### use non root user example below: +#User=debian-transmission Type=simple -ExecStart=/opt/bin/add_trackers_auto.sh +ExecStart=/opt/bin/add-trackers-auto.sh ExecStop=/bin/kill -s TERM $MAINPID ExecStopPost=/bin/rm -f /tmp/TTAA.*.lock KillMode=control-group