I have a main desktop on my home LAN, and a few notebooks, all running Ubuntu. I have a pretty slow Internet connection, so when a kernel update comes out it means running a 50Mb update on all of the machines. It struck me that this isn’t the most efficient way of doing things. I experimented with the apt-cacher package, but that had two problems: first it didn’t seem to work that well and often crashed on the main desktop; second, whenever I went outside my home LAN it didn’t work.
So I did the Linux thing, and made a quick and dirty script that works for me …
First of all I tried to figure out how to mount a remote directory over the network and then add a line to apt’s sources-list file to include that directory. I didn’t get too far with that. Then I figured I could use rsync over ssh to update the local cache directory and then run apt-get after that.
OK, so my main machine is called “desktop”. That’s where I’ll run all the normal ‘apt-get update’s and Update Manager. So I need to sync all those changes to “laptop1”, “laptop2” etc.
The first step isn’t essential but it makes things easier: setting up password-less login to the main machine.
On the main machine install openssh-server if you don’t already have it.
sudo apt-get install openssh-server
On each of the laptop clients, set up a certificate and copy it to the main machine.
ssh-keygen ssh-copy-id desktop
More detailed instructions can be found by searching for ssh-keygen on the Internet.
So assuming you can now login to the main machine with no password, you can use the following script to sync the /var/cache/apt/archive directory (which is where all the downloaded packages are stored).
#!/bin/bash # Script to log into main desktop, sync the deb package archive and run an update. # Sync sudo rsync -avz -e "ssh -i /home/laptopusername/.ssh/id_rsa" desktopusername@desktop:/var/cache/apt/archives/ /var/cache/apt/archives/ # Upgrade sudo apt-get update sudo apt-get -y dist-upgrade
So when I’m on my home LAN, I can use this script, and when I’m elsewhere, I can just use the normal apt-get / Update Manager method. If you have other ssh options, eg non-standard port numbers etc, be sure to add them to the ssh command between the two double-quotes.