summaryrefslogtreecommitdiff
path: root/extra/tpull.sh
blob: eaa2909fb4c977a4c7a30ca01df5ca22ecd54a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

# This is a really simple script intended to be run as an action
# from transmission-remote-gtk. It uses rsync to fetch
# a torrent/torrents to a local directory (or put it somewhere
# remote and run it using ssh to there).

# It also shows how we can call transmission-remote with
# connection details to find information about a torrent or
# manipulate it.

# Example
# gnome-terminal -e "tpull.sh %{hostname} %{port} %{username}:%{password} %{id}[,] /srv/incoming/"

if [ -z "$5" ]; then
  echo "usage: <host> <port> <user:pass> <id> <dest>"
  exit 1
fi

HOST=$1
TPORT=$2
TAUTH=$3
IDS=$4
DEST=$5

echo $IDS | sed "s/,/\n/g" | while read id; do
  DETAILS=$(transmission-remote $HOST:$TPORT -n $TAUTH -t $id -i)

  if [ $? -ne 0 ]; then
    read
    exit 1
  fi

  LOCATION=$(echo "$DETAILS" | egrep '^\s+Location:' | cut -c 13-)
  NAME=$(echo "$DETAILS" | egrep '^\s+Name:' | cut -c 9-)

  if [ -z "$LOCATION" -o -z "$NAME" ]; then
    continue
  fi

  FULLPATH="$LOCATION/$NAME"

  echo "Syncing $FULLPATH ..."
  rsync -avPs "$HOST:$FULLPATH" "$DEST"
done