Skip to content

Commit 97a18f2

Browse files
committed
Add FreeBSD compatibility and FreeBSD services support
1 parent 9ba9c85 commit 97a18f2

File tree

4 files changed

+104
-48
lines changed

4 files changed

+104
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ Nice=19
4343

4444
#### Choose your destiny:
4545

46-
[Docker way](https://github.com/AndrewMarchukov/tracker-add#-docker-way)
46+
[Docker way](#-docker-way)
4747

48-
[Systemd way](https://github.com/AndrewMarchukov/tracker-add#-systemd-way)
48+
[Systemd way](#-systemd-way)
4949

50-
[Simple way (for routers)](https://github.com/AndrewMarchukov/tracker-add#-simple-way-for-routers)
50+
[FreeBSD service way](#-freebsd-service-way)
51+
52+
[Simple way (for routers)](#-simple-way-for-routers)
5153

5254
## Installation and usage
5355

@@ -92,6 +94,29 @@ systemctl status transmission-tracker-add.service
9294
9395
```
9496

97+
98+
#### * FreeBSD service way
99+
100+
Edit settings.json for transmission set rpc-enabled, rpc-username and rpc-password
101+
102+
Download scripts and make it executable:
103+
```bash
104+
install -d /opt/bin
105+
fetch -o /opt/bin/add-trackers-auto.sh https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/tracker-add-auto.sh
106+
fetch -o /usr/local/etc/rc.d/transmission_tracker_add https://raw.githubusercontent.com/AndrewMarchukov/tracker-add/master/transmission_tracker_add
107+
chmod +x /opt/bin/add-trackers-auto.sh /usr/local/etc/rc.d/transmission_tracker_add
108+
```
109+
110+
Set user and password in `add-trackers-auto.sh`:
111+
```bash
112+
nano /opt/bin/add-trackers-auto.sh
113+
```
114+
115+
Start service:
116+
```bash
117+
service transmission_tracker_add start
118+
```
119+
95120
#### * Simple way (for routers)
96121

97122
Requirements: curl, transmission-remote

tracker-add-auto.sh

100644100755
Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
1-
#!/bin/bash
1+
#!/bin/sh
22
# Get transmission credentials and ip or dns address
33
auth=user:password
44
host=localhost
55

6+
trans="$(which transmission-remote) $host --auth=$auth"
67
while true ; do
7-
sleep 25
8-
add_trackers () {
9-
torrent_hash=$1
10-
id=$2
11-
trackerslist=/tmp/trackers.txt
12-
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
13-
if [ ! -f $trackerslist ]; then
14-
curl -o "$trackerslist" "${base_url}"
15-
fi
16-
Local=$(wc -c < $trackerslist)
17-
Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
18-
if [ "$Local" != "$Remote" ]; then
19-
curl -o "$trackerslist" "${base_url}"
20-
fi
21-
echo "URL for ${base_url}"
22-
echo "Adding trackers for $torrent_name..."
23-
for tracker in $(cat $trackerslist) ; do
24-
echo -n "${tracker}..."
25-
if transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
26-
echo ' done.'
27-
else
28-
echo ' already added.'
29-
fi
30-
done
31-
done
32-
sleep 3m
33-
rm -f "/tmp/TTAA.$id.lock"
34-
}
35-
# Get list of active torrents
36-
ids="$(transmission-remote "$host" --auth="$auth" --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }')"
37-
for id in $ids ; do
38-
add_date="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info| grep '^ Date added: ' |cut -c 21-)"
39-
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
40-
dater="$(date "+%Y-%m-%d %H:%M")"
41-
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"
8+
sleep 25
429

43-
if [ ! -f "/tmp/TTAA.$id.lock" ]; then
44-
if [[ "( "$add_date_t" == "$dater" || "$add_date_t" == "$dateo" )" ]]; then
45-
hash="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
46-
torrent_name="$(transmission-remote "$host" --auth="$auth" --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
47-
add_trackers "$hash" "$id" &
48-
touch "/tmp/TTAA.$id.lock"
49-
fi
50-
fi
51-
done
10+
add_trackers () {
11+
torrent_hash=$1
12+
id=$2
13+
trackerslist=/tmp/trackers.txt
14+
for base_url in https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt ; do
15+
if [ ! -f $trackerslist ]; then
16+
curl -o "$trackerslist" "${base_url}"
17+
fi
18+
Local=$(wc -c < $trackerslist)
19+
Remote=$(curl -sI "${base_url}" | awk '/Content-Length/ {sub("\r",""); print $2}')
20+
if [ "$Local" != "$Remote" ]; then
21+
curl -o "$trackerslist" "${base_url}"
22+
fi
23+
echo "URL for ${base_url}"
24+
echo "Adding trackers for $torrent_name..."
25+
for tracker in $(cat $trackerslist) ; do
26+
echo -n "${tracker}..."
27+
if ${trans} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then
28+
echo ' done.'
29+
else
30+
echo ' already added.'
31+
fi
32+
done
33+
done
34+
sleep 3m
35+
rm -f "/tmp/TTAA.$id.lock"
36+
}
37+
38+
# Get list of active torrents
39+
ids="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }' | grep -vE 'ID')"
40+
for id in $ids ; do
41+
add_date="$(${trans} --torrent "$id" --info| grep '^ Date added: ' |cut -c 21-)"
42+
if [ $(uname) = "FreeBSD" ]; then
43+
add_date_t="$(date -jf "%+" "$add_date" "+%Y-%m-%d %H:%M")"
44+
dateo="$(date -jv-1M "+%Y-%m-%d %H:%M")"
45+
else
46+
add_date_t="$(date -d "$add_date" "+%Y-%m-%d %H:%M")"
47+
dateo="$(date -d "1 minutes ago" "+%Y-%m-%d %H:%M")"
48+
fi
49+
dater="$(date "+%Y-%m-%d %H:%M")"
50+
51+
if [ ! -f "/tmp/TTAA.$id.lock" ]; then
52+
if [ "$add_date_t" = "$dater" -o "$add_date_t" = "$dateo" ]; then
53+
hash="$(${trans} --torrent "$id" --info | grep '^ Hash: ' | awk '{ print $2 }')"
54+
torrent_name="$(${trans} --torrent "$id" --info | grep '^ Name: ' |cut -c 9-)"
55+
add_trackers "$hash" "$id" &
56+
touch "/tmp/TTAA.$id.lock"
57+
fi
58+
fi
59+
done
5260
done

transmission_tracker_add

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
#
3+
# PROVIDE: transmission_tracker_add
4+
# REQUIRE: DAEMON
5+
# KEYWORD: shutdown
6+
7+
. /etc/rc.subr
8+
9+
name=transmission_tracker_add
10+
rcvar=transmission_tracker_add_enable
11+
12+
load_rc_config $name
13+
14+
: ${transmission_tracker_add_enable:=YES}
15+
16+
pidfile=/var/run/transmission/tracker-add.pid
17+
command="/usr/sbin/daemon"
18+
task="/opt/bin/add-trackers-auto.sh"
19+
procname="/bin/sh"
20+
command_args="-p ${pidfile} ${task}"
21+
22+
run_rc_command "$1"

0 commit comments

Comments
 (0)