Skip to content
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

Add FreeBSD compatibility and FreeBSD services support #18

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Script optimization by @otapi (partially)
Limych committed Feb 14, 2021

Verified

This commit was signed with the committer’s verified signature.
Limych Andrey "Limych" Khrolenok
commit 2b972a5a77313c8f5f38ae339650707ea3db31ad
Empty file modified tracker-add-auto-router.sh
100644 → 100755
Empty file.
58 changes: 29 additions & 29 deletions tracker-add-auto.sh
Original file line number Diff line number Diff line change
@@ -3,38 +3,38 @@
auth=user:password
host=localhost

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}..."
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 ' failed.'
else
echo ' done.'
fi
done
done
sleep 3m
rm -f "/tmp/TTAA.$id.lock"
}

trans="$(which transmission-remote) $host --auth=$auth"
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 ${trans} --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="$(${trans} --list | grep -vE 'Seeding|Stopped|Finished|[[:space:]]100%[[:space:]]' | grep '^ ' | awk '{ print $1 }' | grep -vE 'ID')"
for id in $ids ; do
@@ -52,8 +52,8 @@ while true ; do
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-)"
add_trackers "$hash" "$id" &
touch "/tmp/TTAA.$id.lock"
add_trackers "$hash" "$id" &
fi
fi
done