Posts Tagged ‘script’

Parallel package downloads for Debian-based distros

April 7th, 2010

When trying to install some packages in my Karmic box and noticing that it would take a long time, I wondered why the downloads couldn’t be made in parallel – the one-of-a-time download method used by apt-get is far from optimal. A quick search resulted in these very useful blog posts – it seems that I wasn’t the only one with that question in my mind. So, starting from the solution from the second hyperlink and putting all inside a single bash script, we have:

#!/bin/bash
# Must be run with sudo or as (gasp!) root

apt-get -y --print-uris install "$@" |
egrep -o -e "http://[^\']+" |
aria2c -c -d /var/cache/apt/archives -i - && apt-get install "$@"

You’ll need aria2 for this, download it in the classic way :P . In a nutshell, the script obtains the list of packages do be downloaded, pass them to aria2 for downloading and runs the proper install command in the end. Now you just have to chmod u+x and it you’re set. For example, if you wanted to use xfce4 in your Ubuntu box instead of Gnome, you could just do

$ sudo ./parallelInstall.sh xubuntu-desktop

and go grab a coffee. Other apt-get commands work: if you want to do an apt-get upgrade just change install to upgrade (or dist-upgrade) in the script. The script is not fully automated, you see – the last command may need mandatory interaction because installing things may nicely break your system without your ever noticing until the damage is done. If all the packages are from official repos and signed and whatnot, though, all will happen in a very automatic way :)

Although this script is tailored for Debian-flavored distros, you could just adapt the first and last commands to match your favourite distro.