Installing Transmission the BitTorrent client

 

Introduction

First, let's Install a BitTorrent client on your MBWE.

 

We will be using Transmission as a BitTorrent client, so if you're using for example rTorrent or some other BitTorrent client out there this guide will probably be of no interest for you. The main reason I chose Transmission over rTorrent is that it seems to be the less memory consuming one of them. Also, some people have reported that rTorrent hangs on some occasions, especially when handling big files.

 

In the MBWE wiki at Wikidot, there is a subforum dedicated to BitTorrent clients in case you need support on using some specific torrent client on your MBWE.

Also check there first if you're having problems with for example a specific version of Transmission - someone else is most likely having the same problems too :)

Prerequisites

Enabled SSH access.

A text editor and the know-how to use it. I recommend installing nano, but vi will also do just fine.

The how-to

  1. Make sure you are in superuser mode.

    # su
  2. Install Transmission. You can naturally build it from the source code, but it will be a lot easier to use optware. For instructions on how to install optware on your MBWE, see the appropriate page in the MBWE wiki.

    If you have upgraded your MBWE to firmware version 2.00.15 or newer, you even don't have the option to build it from the source since you probably don't have your c compiler anymore. Anyway, instructions on building Transmission from the source can be found here.

     

    Ok, so I'll be using optware. I'm assuming you have set your paths to the /opt directory, as described in the optware guide. If you get an error like "command not found" at some point when trying to call the transmission executables, you probably haven't.

    As of writing the latest version was 1.34 and it required also some libraries to be installed in order to function. ipkg will handle the installation of the required libraries automatically.

    If you are having problems installing Transmission using optware, check the forum if the problems are solved by someone else already.

    Note: From version 1.20 to version 1.30 the RPC/IPC protocols of Transmission were completely redefined so versions between those might not work as expected. All the scripts here have been updated to work with version 1.30 and above and all the instructions assume you have version newer than 1.30. However, old versions for transmission 1.20 and older are also available for download.
    # ipkg install transmission libiconv
    # ldconfig

    Simple as that, transmission and all the libraries needed by it are installed.

  3. Set up Transmission's config directory.By default, it uses directory ~/.config/transmission-daemon for it's needs.

    In versions older than 1.20, the default config directory is ~/.config/transmission.

    Since version 1.11+r5646, using a custom config directory has been supported. I'm going to use the default, though.

    The config directory isn't created automatically, so let's create it.

    # mkdir ~/.config
    # mkdir ~/.config/transmission-daemon

    Now you can test if the daemon starts properly with

    # /opt/bin/transmission-daemon
    # ps -A | grep transmission

    This should give you a list with three transmission-daemon processes. If not, you've done something wrong.

    Stop the daemon processes with

    # killall transmission-daemon

  4. Now, we have installed transmission successfully. Wasn't too hard, was it?

     

    You can already use it as it is; just start the daemon like in the last step. You can control the daemon from shell with the command transmission-remote. You can for example add torrents with

    # transmission-remote -a path/to/.torrent-file

    This way the torrents will be downloaded in the same directory with the .torrent file. If you want them to be downloaded to a single working directory, set it up before adding the .torrent files with

    # transmission-remote -w path/to/directory

    Also see other options for transmission-remote by calling it without any options, i.e.

    # transmission-remote

    Note that these options won't be saved anywhere, so they will be lost every time you restart the daemon.

    As of transmission 1.30, settings can also be set in the file /root/.config/transmission-daemon/settings.json (note the path, if you're planning on using non-default config directory).

     

    I have put together a startup script to automate setting these options and to start and stop the daemon automatically during boot / shutdown.

    Here's the script:

    #! /bin/sh
    #
    # transmission.sh
    # startup/shutdown script for the Transmission BitTorrent client on MBWE
    # written by kyyhkynen at gmail dot com
    # note that this version of the script works only with transmission version 1.3 and newer!
    # see http://kyyhkynen.net/stuff/mybook for further info
    #
    # you may use and modify this script any way you want as long as you keep this header attached
    # last modified Sep 2nd, 2008
    ################
    # Configuration
    ################
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin/
    
    # set path to the transmission daemon
    # by default the optware version location, change this if you built transmission from source
    DAEMON=/opt/bin/transmission-daemon
    # the port to listen for connections
    # leave blank to use upnp port mapping
    DAEMON_PORT=""
    # if you want to start the daemon with any switches (other than the location of the socket file), add them here
    # you can for example set an alternative location for the config directory here with the -g switch
    # or, if you're using version newer than 1.20, you can set the port for listening commands here with the -p switch
    DAEMON_OPTS=""
    
    # set path to the transmission remote
    # by default the optware version location, change this if you built transmission from source
    REMOTE=/opt/bin/transmission-remote
    # if you want to give the remote any additional options, add them here
    # you can for example set an alternative location for the config directory here with the -g switch
    REMOTE_OPTS=""
    
    # set the working directory for transmission
    TRANSMISSION_WORKDIR=/shares/internal/PUBLIC/Torrent/workdir
    
    ##############################################
    # end of configuration
    # you shouldn't need to edit anything below this
    
    NAME=Transmission
    
    test -x $DAEMON || exit 0
    
    start() {
            echo -e "Starting $NAME\r"
            $DAEMON $DAEMON_OPTS
            if [ -d $TRANSMISSION_WORKDIR ]; then
    		sleep 2
                    $REMOTE -w $TRANSMISSION_WORKDIR
    	else
    		if [ ! -z "$TRANSMISSION_WORKDIR" ]; then
    			echo -e "note: $TRANSMISSION_WORKDIR doesn't exist, using the default work dir\r"
    		fi
            fi
    	if [ ! -z "$REMOTE_OPTS" ]; then
    		$REMOTE $REMOTE_OPTS
    	fi
            if [ "$DAEMON_PORT" != "" ]; then
                    $REMOTE --port $DAEMON_PORT
            fi
            sleep 2
    	$REMOTE -t all --start
    }
    
    stop() {
            echo -e "Stopping $NAME\r"
    	TRANSMISSION_IS_RUNNING=`ps -A | grep transmission-d | wc -l` ;
    	if [ "$TRANSMISSION_IS_RUNNING" -gt "0" ]; then
    	        $REMOTE -t all --stop
            	sleep 2
    		killall transmission-daemon
    	fi
    }
    
    case "$1" in
    	start)
    		start
    		;;
    	stop)
    		stop
    		;;
    	restart)
    		stop
    		echo -e "Sleeping 30 seconds before starting again...\r"
    		sleep 30
    		start
    		;;
    esac
    
    exit 0
    

    The script supports only transmission versions newer than 1.30. For the old version of the script, download
    http://kyyhkynen.net/stuff/mybook/transmission.sh.old and rename it into transmission.sh.

    You can either copy-and-paste the script from above and put it in /etc/init.d/transmission.sh, or download it directly in your MBWE:

    # wget http://kyyhkynen.net/stuff/mybook/transmission.sh
    # mv transmission.sh /etc/init.d
    # chmod a+x /etc/init.d/transmission.sh

    Check the configuration section of the script and check that all the paths are correct and that the directories exist. If you built transmission from source, you'll need to change the paths.

    Make sure that the drive the WORKDIR is set on has enough free space to hold your files while they are downloading.

     

    Now you can start the daemon with

    # /etc/init.d/transmission.sh start

    And stop it (and currently donwloading torrents) accordingly with

    # /etc/init.d/transmission.sh stop

    In order to make Transmission start and stop during startup and shutdown, add the appropiate commands to /etc/init.d/post_network_start.sh, like this:

    start() {
            if [ ! -e "$POST_NETWORK_STARTED_FILE" ]
            then
                    $SCRIPTS_PATH/crond.sh start
                    # $SCRIPTS_PATH/mionet.sh start
                    $SCRIPTS_PATH/transmission.sh start
                    touch $POST_NETWORK_STARTED_FILE
            fi
    }
    
    stop() {
            if [ -e "$POST_NETWORK_STARTED_FILE" ]
            then
                    # $SCRIPTS_PATH/mionet.sh stop
                    $SCRIPTS_PATH/transmission.sh stop
                    $SCRIPTS_PATH/crond.sh stop
                    rm $POST_NETWORK_STARTED_FILE
            fi
    }

     

  5. In the long run, using transmission only from the shell gets a bit complicated, so let's make it a bit more convenient.

     

    In the next step, we'll be making it to have a rtorrent-like watch folder, move completed downloads automatically to some directory, have scheduled bandwidth limits and download tv shows automatically from RSS feeds.

    Continue to Adding extra functionality on Transmission