Automated Download of the Latest Version of Raspbian - BitTorrent Edition

Published on Mon, 12 April, 2021 | 500 words
Tags: raspberry pi raspbian raspberry pi os bash shortcut configuration bittorrent

I often set up Raspberry Pis. I always like to make sure a new Pi on my network runs the latest version of the OS. I had a regular problem in that I wanted to set up a Pi quickly, but ended up having to go to the website, check for latest version, and download that before I could start writing the card image.

Last year, I wrote a blog post on how to automate the process of regularly checking for the latest Raspberry Pi OS and downloading it from the web ahead of time, so I always have the latest version handy on a local disk ready to install when I need it. But since then I’ve switched to the BitTorrent download.

My Deluge client, seeding various versions of Raspberry Pi OS

BitTorrent is a peer-to-peer method of sharing large files on the internet. It allows several people downloading a large file to download it from each other, in chunks, rather than in all one go from a centralised server. This distributes a lot of the bandwidth around the network and usually increases download speed. BitTorrent has been around since 2001, before most people had always-on internet, and quickly got itself a bad name in the media for being the favourite method for illegal file sharing. But, despite this, it has many legitimate uses and a lot of Linux distributions, Raspberry Pi OS included, still have a BitTorrent option for download. So, as I have quite a decent internet connection, I thought I’d rewrite my script to download the latest Pi OS via BitTorrent, and leave it seeding indefinitely. I feel that this has two benefits; firstly I’m giving back to the Raspberry Pi OS in the form of bandwidth, and secondly I’m increasing (if only slightly) the amount of legal BitTorrent traffic on the internet.

A lot of BitTorrent traffic these days uses magnet links - which are beyond the scope of this post - but the traditional way to distribute a torrent, and indeed the method used on, is to have a small metafile with a .torrent file extension that contains enough information to locate a complete copy of the full file. My torrent client of choice is Deluge (running on a Pi of course), which has a nice feature: you can define a ‘watch’ directory. If a .torrent file gets copied into this directory, it immediately gets loaded into the client and downloading begins. So the script I’ve written simply looks for new .torrent files on, and downloads them into this directory.

The code is available from GitHub.