WolfPack/offload-wolfpack

32 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -x
target="$1"
dir=`sudo -u deluge deluge-console config download_location 2>/dev/null | head -n 1 | sed 's/download_location: //'`
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
timeout 60 sudo -u deluge /bin/bash -l -c 'deluge-console info' 2>/dev/null | egrep '^\[S\]' | (
while read line; do
id="$(echo "$line" | awk '{ print $4; }')"
name="$(echo "$line" | awk '{ print $3 }')"
# 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
# Hack because `deluged rm -c $id` isn't working
sudo systemctl stop deluged
sudo rm -Rf /srv/deluge/.config/deluge/state"$id";
sudo systemctl start deluged
rm -Rf "$dir"'/'"$name"
else
echo "ERROR: Return was $ret" >> "$dir"/"$name"/error.log
fi
unset name; unset id;
done
) | systemd-cat -t "offload-wolfpack"