added ssh-smart package - curently not working
[mirrors/ArchLinux-Packages.git] / rtorrent-screen / rtorrent-screen.bash
CommitLineData
209feeb0
H
1#!/bin/bash
2# rtorrent-screen 1.0 (Harvie 2oo9)
3# - Simple rtorrent manager (keeps your torrents in screen transparently + allows you to monitor it using hardcopies)
4#
5# - Dependencies: bash, screen, rtorrent
6# - Optionaly webserver with PHP (you will be allowed to monitor your torrents using web interface)
7# - TODO: adding torrents using web interface...
8
9TARGET_DIRECTORY=~/downloads #warning: each user MUST have his own directory for downloading (on "single user" system u can use eg. /srv/http/downloads)
10SCREEN_PID_FILE='rtorrent-screen.pid'
11SCREEN_DUMP_INTERVAL=30;
12SESSION_NAME='rtorrent'
13CREATE_PHP_UI=true
14PHP_UI='download.php'
15
16CONFIG_OVERRIDE=~/.config/rtorrent-screen.rc.sh
17#source "$CONFIG_OVERRIDE" 2>/dev/null
18
19cd "$TARGET_DIRECTORY";
20if [ $? != 0 ]; then
21 echo Directory "$TARGET_DIRECTORY" does not exists create it or change path in "$CONFIG_OVERRIDE" or in "$0"
22 echo Note that each user MUST have his own separate directory for rtorrent-screen to avoid collisions.
23 exit 2;
24fi;
25
26#PHP UI
27if "$CREATE_PHP_UI"; then
28echo "
29<head>
30 <title>Harvie's Downloads</title>
31</head>
32<style>
33 * { font-size: small; color: green; background-color: black; }
34 b,i,u { color: lime; }
35</style>
36<pre><?php
37 if(is_file('$SCREEN_PID_FILE')) {
38 echo(
39 'rTorrent is running. To attach to it login as <b>$USER</b> and type: <b>$0</b> or <b>screen -x '.
40 htmlspecialchars(file_get_contents('$SCREEN_PID_FILE')).
41 '</b>If you want to detach from it (leave it running on background) press <b>CTRL+a followed by d</b> and if you want to stop rTorrent definitely then press <b>CTRL+q</b> few times.<hr />'.
42 htmlspecialchars(file_get_contents('./hardcopy.0'))
43 );
44 } else {
45 echo('rTorrent is not running at this time... To execute it use command: <b>$0</b>');
46 }
47?></pre>
48" > "$PHP_UI"
49fi;
50
51#SCREEN SESSION
52if [[ -r "$SCREEN_PID_FILE" ]]; then
53 screen -x $(cat "$SCREEN_PID_FILE");
54else
55 screen -U -S "$SESSION_NAME" -t "$SESSION_NAME" bash -c "
56 while true; do
57 sleep 1;
58 screen -S \$PPID -X hardcopy;
59 sleep $SCREEN_DUMP_INTERVAL;
60 done &
61
62 echo \$PPID > $SCREEN_PID_FILE;
63 rtorrent;
64 rm -f $SCREEN_PID_FILE;
65 rm -f hardcopy.0;
66 "
67fi;
68
69echo 'Thank you for using rtorrent-screen by Harvie'
This page took 0.145602 seconds and 4 git commands to generate.