Adding Bittorrent Support to My PogoPlug February 12, 2014Posted by samwyse in Scripting.
Over the weekend, I visited my local Walmart and found a Pogoplug model V4-A1-01 in the electronics section. It was on the discontinued items table and marked down to $39.95, about half of what it cost new, but still a bit more that what you could find online. Still, a bird in the hand, etc. I took it home and plugged in a 1TB external drive that I’ve had for a couple of years, and it worked perfectly. Then I decided to try installing a Bittorrent client.
After a bit of a search, I found some instructions (each part is linked below) at Aaron Randall’s blog, but they are for an older version and needed some adapting to work on my Pogoplug. Here are my revisions:
Part 1, Step 1: Preparing Your Pogoplug — Unchanged.
Part 1, Step 2: Checking the Filesystem — My system has a /dev/mtdblock3 file, but I couldn’t mount anything on it. Instead I inserted an old 1GB SD card that I reformatted to use the ext3 filesystem. Instead of mounting it myself, I created a symbolic link.
mount -o remount,rw /
ln -s /opt /tmp/.cemnt/mnt_mmcblk0p1
Part 1, Step 3: Installing a Package Management System — Unchanged.
Part 2, Steps 1-3: Unchanged.
Part 2, Step 4: Running the Bittorent Client — Unchanged, except Aaron just shows you how to start the daemon manually. This means that if there’s a power outage, the daemon won’t restart automatically. I’ll fix that below.
Part 3: Adding Torrents via my.pogoplug.com — This is where everything is different. After I installed the ipkg version of cron, I couldn’t get it to work. After several hours of trying, I removed the package and used the busybox crond that is already installed on the Pogoplug. First, I set everything up so that both crond and the daemon would restart. I did this by appending the following to the /etc/init.d/rcS script:
# wait for the SD card to get mounted, then remount it with 'exec'
while ! mount -o remount,exec /tmp/.cemnt/mmcblk0p1
do sleep 1
# now we can start the daemon
/opt/bin/transmission-daemon --config-dir /opt/config/transmission-daemon/
# recreate our crontab
mkdir -p /var/spool/cron/crontabs
cp /etc/crontab /var/spool/cron/crontabs/root
# start crond
There’s another process that mounts all external storage at boot time, but it does so using the ‘noexec’ option. So I remount it using the ‘exec’ flag. But that won’t work if the other process isn’t done, so I do the remount in a loop with a one second delay. Also, /var is a symbolic link to /tmp/var, so everything there gets erased at every reboot. I had an earlier /etc/crontab left over from my experimentation, so I just copy it over; if I were doing everything from scratch, I’d probably put the source file somewhere in /opt. /etc/crontab just has one line: */15 * * * * /opt/bin/transmission-scheduler.sh This runs the scheduler every fifteen minutes, which is find for me. The scheduler script looks like this:
for f in $pathToTorrentFolder/*.torrent ;
[ -f $f ] && /opt/bin/transmission-remote -a "$f" && rm "$f";
/opt/bin/transmission-remote -l > $pathToTorrentFolder/transmission.log
Most of the time, the way that file name expansion works means that the $f variable will contain /tmp/.cemnt/mnt_sda1/Torrents/*.torrent so I first verify that the named file actually exists. If so, I add the torrent; and only if that is successful do I remove the file. Finally, I list all active torrents in a log file, so I can check on things without needing to SSH into the Pogoplug.