Raspberry Pi as Budget BitTorrent Server

· 743 words · 4 minute read

The raspberry pi is a surprisingly powerful and cost-efficient computing device. Yesterday I put together this simple setup script to turn your new raspberry into a mean green downloading machine. The only requirement is an existing internet router and a working raspberry with SD-card.

Update July 2013: Here is another image for headless installations, only 220 MB big.

The guys on the official raspberry site have some nice images for downloading, but since we won’t be using the graphical UI, we can use a the slim image put together by darkbasic on his site linuxsystems.it. Just follow his instructions to download, extract and install the image to a compatible SD-card. A list of tested and compatible SD-cards is available from the official site.

While installing make sure to enable SSH-access by renaming the boot-enable-ssh.rc boot.rc

Once your raspberry has booted, you need to find out its IP by looking at the router’s DHCP table. Just look for a device name raspberry-pi.

Next just create a new text file by typing vi setup.sh in your terminal window while logged into the RP. Then just copy the script provided with this blog post to your clipboard. Press “i” to go into editing mode and paste the script with Ctrl/Cmd+v. Then save it with ESC, : x. Execute the script by issuing sh setup.sh. As opposed to the default Debian image, the darkbasic image gives you root access by default. When using another image, execute the script with sudo sh setup.sh.

[cc lang=“bash” width=“100%” height=“600” noborder=“1” line_numbers=“on” theme=“dawn”]

#!/usr/bin/env bash

# Installs all components needed for a nice seedbox on your new raspberry pi.
# Base image: http://www.linuxsystems.it/2012/06/debian-wheezy-raspberry-pi-minimal-image/
# Prepared by manu (at) snapdragon.cc

echo “[+] Updating packages”
apt-get update ; apt-get -y upgrade

echo “[+] Installing Samba and Transmission packages”
apt-get -y install transmission-daemon samba avahi-daemon

echo “[+] Configuring Transmission”
service transmission-daemon stop
sed -i -re ’s/(rpc-authentication-required":\ )([a-z]+)/\1false/g' /etc/transmission-daemon/settings.json
sed -i -re ’s/(rpc-whitelist-enabled":\ )([a-z]+)
/\1false/g' /etc/transmission-daemon/settings.json
sed -i -re ’s/(download-dir":\ )([a-z]+)*(.*)/\1"/srv/media",/g' /etc/transmission-daemon/settings.json
service transmission-daemon start

echo “[+] Setting up public Samba share”
mkdir /srv/media
chown debian-transmission /srv/media

echo “[public]
comment = Public Shares
browsable = yes
path = /srv/media
public = yes
writable = yes
guest ok = yes” » /etc/samba/smb.conf
service samba restart
[/cc]

Now just sit back and wait for all components to install. Depending on the speed of your SD-card, this can take up to an hour. The script will first update your package manager, then install the required applications and dependencies and settings. If you’re using a different image, you might need to adapt some package names.

If all went well, you should be able to access the transmission web interface via your Mac on the following URL: http://raspberry-pi.local:9091. On Microsoft Windows, you can try http://raspberry-pi:9091. In case neither name resolution should work, just use the IP address, you found out via your router before. The inteface should always be available on <http://:9091>.

Figure 1: Raspberry Pi running Transmission

On the transmission web interace, you can add and manage all your (legal) torrent downloads. Depending on the size of your SD-card you might need to delete old downloads from time to time.

To access your downloads, you can mount it via CIFS/SMB. On your Mac go to the Finder and connect to a new network folder by pressing CMD+k. Then type smb://raspberry-pi.local, choose to connect as guest and you should see the right folder. On Windows you can enter _\YOUR RASPBERRY IP\public _in Windows Explorer. If you are a heavy Windows user, you can also enable WINS address resolution in smb.conf

If everything went well, you should now have a basic BitTorrent server. In case something doesn’t work, just start over with a new image and do the steps found in the setup script one by one. If your downloads work OK, but you can’t access them there might be a permissions issue. This is easily correctable by logging in doing a chmod -R 777 /srv/media.

Please note that you can only use this setup in a trusted network, because all user authentication and security mechanisms are disabled. If you want to access your torrent server from the public internet, you need to proxy it via a proper webserver, enable HTTPS and password authentication.

Since the whole system is running on a standard Debian image, you could add all kinds of cool features like:

  • adding torrents automatically with Flexget
  • downloading from cyberlockers, like Rapidshare with PyLoad
  • share files via HTTP with Apache and h5ai