diff --git a/offload-wolfpack b/offload-wolfpack index b10fdfe..196b6cb 100755 --- a/offload-wolfpack +++ b/offload-wolfpack @@ -1,42 +1,31 @@ #!/bin/bash +set -x logfile=/var/log/wolfpack.log target="$1" -dir=`sudo -u deluge deluge-console config download_location 2>/dev/null | head -n 1 | sed 's/ download_location: //'` +dir=`sudo -u deluge deluge-console config download_location 2>/dev/null | head -n 1 | sed 's/download_location: //'` -if [ -z "$target" ] || [ "$(ping -c 2 "$target" &>/dev/null; echo $?)" -ne 0 ]; then +if [ -z "$target" ]; then # || [ "$(ping -c 2 "$target" &>/dev/null; echo $?)" -ne 0 ]; then echo Usage: $0 '[target]'; exit 1 fi ssh $target mkdir -p /srv/yggdrasil/new_acquisition -sudo -u deluge deluge-console info 2>/dev/null | ( -unset name; -unset id; -unset state; -while read line; do - case "$line" in - "Name:"*) name="$(echo $line | sed 's/Name: //')"; ;; - "State:"*) state="$(echo $line | cut -f 2 -d ' ')"; ;; - "ID:"*) id="$(echo $line | sed 's/ID: //')"; ;; - *) - if [ ! -z "$name" ] && [ ! -z "$id" ] && [ ! -z "$state" ]; then - echo Found "$name" "($id)" with state "$state" - if [ -e "$dir"'/'"$name" ]; then - echo "$name" exists on disk. - fi - if [ "$state" == "Seeding" ]; then - sudo -u deluge deluge-console 2>/dev/null rm "$id"; - rsync -avz "$dir"'/'"$name" $target:/srv/yggdrasil/new_acquisition - ret="$?" - if [ "$ret" -eq 0 ]; then - rm -Rf "$dir"'/'"$name" - else - echo "ERROR: Return was $ret" >> "$dir"/"$name"/error.log - fi - fi; - unset name; unset id; unset state; - fi ;; - esac -done) +sudo -u deluge deluge-console info 2>/dev/null | egrep '^\[S\]' | ( + while read line; do + id="$(echo "$line" | awk '{ print $4; }')" + name="$(echo "$line" | awk '{ print $3 }')" + sudo -u deluge deluge-console 2>/dev/null rm "$id"; + # Clean up downloads before sending. + rm -Rf "$dir"/"$name"/*.nfo "$dir"/"$name"/*.txt "$dir"/"$name"/*.png "$dir"/"$name"/*.jpg + rsync -avzz "$dir"'/'"$name" $target:/srv/yggdrasil/new_acquisition + ret="$?" + if [ "$ret" -eq 0 ]; then + rm -Rf "$dir"'/'"$name" + else + echo "ERROR: Return was $ret" >> "$dir"/"$name"/error.log + fi + unset name; unset id; + done +) cat /var/log/wolfpack.log | ssh $target /bin/bash -c 'cat >> /var/log/wolfpack.log' cat /dev/null > /var/log/wolfpack.log