From 9c3bd25cd440f235377bd7a9d2866d5cd191cceb Mon Sep 17 00:00:00 2001 From: Dan Lenski Date: Wed, 15 Apr 2020 09:23:01 -0700 Subject: [PATCH] don't send --auth option if TRANSMISSION_USER/PASS are unset Handle the common case of localhost-only transmission running without authentication --- manual-tracker-add.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/manual-tracker-add.sh b/manual-tracker-add.sh index e5d7828..1afe076 100755 --- a/manual-tracker-add.sh +++ b/manual-tracker-add.sh @@ -1,6 +1,10 @@ #!/bin/bash -# Get transmission credentials -auth=${TRANSMISSION_USER:-user}:${TRANSMISSION_PASS:-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} @@ -15,7 +19,7 @@ add_trackers () { for tracker in $(curl --location -# "${base_url}") ; do echo -en "\e[0m" echo -ne "\e[93m*\e[0m ${tracker}..." -if transmission-remote "$host" --auth="$auth" --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then +if transmission-remote "$host" ${auth:+--auth="$auth"} --torrent "${torrent_hash}" -td "${tracker}" | grep -q 'success'; then echo -e '\e[91m failed.' echo -en "\e[0m" else @@ -27,10 +31,10 @@ done } # Get list of active torrents -ids=${1:-"$(transmission-remote "$host" --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 "$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-)" + 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