#!/bin/sh # Adds a torrent to deluge container # Assumes there is a config folder where auth and torrents/ are located DLPATH="/srv/deluge/config" mkdir -p /tmp/dladd LOG="/tmp/dladd/$(date +"%Y-%m-%d_%H-%M-%S").log" # Check for errors and input type if [ $# -eq 0 ] then echo "No file name provided. Usage: $0 " >&2 exit 1 elif [ -f "$1" ] then magnet=0 elif echo "$1 " | grep -q "magnet:?xt=urn:btih:[a-zA-Z0-9]*" then magnet=1 else echo "File '$1' not found." >&2 exit 1 fi password="$(cut -f2 -d: "$DLPATH/auth")" if [ "$magnet" -eq 0 ] then echo "Adding file." file="$(date +"%Y-%m-%d_%H-%M-%S").torrent" cp "$1" "$DLPATH/torrents/$file" docker exec -i deluge deluge-console "connect 127.0.0.1 localclient $password; add /config/torrents/$file" 2>/dev/null | tail -n 2 else echo "Adding magnet." link=$(echo -n "$1" | tr -d "'\"") docker exec -i deluge deluge-console "connect 127.0.0.1 localclient $password; add $link" 2>/dev/null | tail -n 2 fi rm -d /tmp/dladd 2>/dev/null