Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,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

Expand Down Expand Up @@ -92,6 +94,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
Expand Down
Empty file modified tracker-add-auto-router.sh
100644 → 100755
Empty file.
88 changes: 48 additions & 40 deletions tracker-add-auto.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
#!/bin/bash
#!/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 -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
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 -n "${tracker}..."
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo -n doesn't work on bin/sh, maybe printf '%s\n' can fix it

Copy link
Author

@Limych Limych Feb 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very strange. Are you sure this code doesn't work?

Test 1:

user:~$ sh
$ uname -sv
Linux #49-Ubuntu SMP Fri Feb 5 03:01:28 UTC 2021
$ echo -n "test..."
test...$ 

Test 2:

root@server:~ # sh
# uname -sv
FreeBSD FreeBSD 12.2-RELEASE-p3 7851f4a452d(HEAD) TRUENAS
# echo -n "test..."
test...# 

if ${trans} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
echo ' done.'
else
echo ' failed.'
fi
done
done
sleep 180
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")"

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
trans="/usr/local/bin/transmission-remote $host --auth=$auth"
while true ; do
sleep 25

# Get list of active torrents
ids="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }' | grep -vE 'ID')"
for id in $ids ; do
add_date="$(${trans} --torrent "$id" --info| grep '^ Date added: ' |cut -c 21-)"
if [ $(uname) = "FreeBSD" ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"$(uname)" just in case, prevent word splitting

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

add_date_t="$(date -jf "%+" "$add_date" "+%Y-%m-%d %H:%M")"
dateo="$(date -jv-1M "+%Y-%m-%d %H:%M")"
else
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"
fi
dater="$(date "+%Y-%m-%d %H:%M")"

if [ ! -f "/tmp/TTAA.$id.lock" ]; then
if [ "$add_date_t" = "$dater" -o "$add_date_t" = "$dateo" ]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regress changes
should be if [[ "( "$(add_date_t)" == "$(dater)" || "$(add_date_t)" == "$(dateo)" )" ]]; then or something like that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no built-in command [[ in sh. There is a command [, which has a slightly different syntax. I just translated the logic of the command [[ into the syntax of the command [.

What you wrote is exactly the condition that is specified.

hash="$(${trans} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
torrent_name="$(${trans} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
touch "/tmp/TTAA.$id.lock"
add_trackers "$hash" "$id" &
fi
fi
done
done
22 changes: 22 additions & 0 deletions transmission_tracker_add
Original file line number Diff line number Diff line change
@@ -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"