Okay, so maybe the government won’t come after you for not updating. But they should. To guard off any present or future threats (be they from governments, security vulnerabilities, or something else in the cyber realm), I wrote a short bash snippet to check my system for outdated packages.
Obligatory Existential/Meta Section
I don’t quite know what prompted me to suddenly become interested in maintaining an up to date system. Maybe it was this post of Arch Linux horror stories. Maybe it was the release of git 2.0, which introduces a lot of cool new features and deprecates a lot of others. Who knows, maybe it was influenced by Heartbleed and the host of other high-profile security vulnerabilities and hacks that have sprung up lately. It’s probably a combination of all of these. Let’s move on.
You’ll note the use of a touch file (created in line 2 of the first snippet if it doesn’t already exist). If this file is 24 hours old, each time this code is run an alert will be printed. Since this code is running inside of my
.bash_profile, that means that every time I open a terminal on a 24-hour-old system, I see the update message.
Next, you’ll note that I’ve defined a function called
update which is actually misnamed. This function merely checks for available updates instead of actually performing the updates, logging those packages, gems, and formulae it finds that are out of date. For my purposes, I only need to update brew, check for formulae updates, update rbenv, and check for gem updates. Obviously though, given that there is a way to programmatically check something for updates, plugging that code in here would check it as well. This means that this method is very easy to customize and extend for various needs.
I was planning on checking pip for updates as well, but pip is kind of not even good. To give you an idea, to check all the packages brew manages for updates, you type
brew outdated, and it will list the formula name, current version number, and newest version number. Meanwhile, back in the land of pip, no such functionality exists (at least, simple functionality, and functionality that I could find. If you’d like to correct me, be my guest!). I’m sure that this script will grow as I come to manage more and more pieces of software on my system and others.
If you have any questions about what I’ve done here, or you catch some bugs, be sure to comment below or file an issue on GitHub! I’d love to hear what you have to say.
Jake on the Web
If you cared enough to read that far, you should consider following me on GitHub or paying a visit to my homepage. If this post was about one of my open source projects, make sure to star it on GitHub! I love hearing what people think, so feel free to comment, open an issue, or send me an email.