-
Notifications
You must be signed in to change notification settings - Fork 54
Add FreeBSD compatibility and FreeBSD services support #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
97a18f2
2b972a5
6cb56fe
e7f2b8e
df9f472
bbb1261
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .idea |
| 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}..." | ||
| 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 | ||
|
||
| 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 | ||
|
||
| 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 | ||
| 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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo -ndoesn't work on bin/sh, maybeprintf '%s\n'can fix itUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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:
Test 2: