portsUpdate: Keeping MacPorts Up to Date

Mmmmmk, so apparently cron is going the way of the dodo on OS X/Darwin. Best practice is to move your cron jobs to launchd. Here’s the Apple kb info for timed jobs using launchd (which includes the notice of deprecation) and here’s a great tutorial on using launchd.

My goal was to automagically keep MacPorts up-to-date, ala Ubuntu’s unattended upgrades. Because I’m old, I put port selfupdate, port upgrade outdated & port uninstall inactive in root’s crontab, but then today I was reading more and decided that I really ought to do it the Mac way since it’ll be upgrade proof.

Introducing portsUpdate! You can download the portsUpdate via git.
portsUpdate is copyleft.

Note: portsUpdate works with OS X 10.11 El Capitan. I am not going to test it with older Mac versions, although if your system runs launchd, you could try it. YMMV, I’m not responsible if you break your system in any case.

portsUpdate is a launchd xml file that runs a bash script once daily to update MacPorts, an associated launchd xml to ensure that the path is correct, and an associated installer.

TL;DR

If you trust me (don’t, why would you), you can just download the installer, open Terminal.app, &…
$ cd yourDownloadsDirectory
$ chmod +x InstallMacPortsUpdater
$ sudo ./InstallMacPortsUpdater

& have a coffee. Your MacPorts will update every morning at 3:30 a.m. & your old packages will be removed every Sunday to keep your system running lean.

If you want to know how to use it and want to read the scripts (or even improve upon them!) please read on along…

In particular, note the policy on timed launchd jobs and the computer state: if your machine is asleep, it’ll run when it wakes, if it’s off, it’ll run the next time it’s scheduled.

I tend to enable Power Nap, especially on fixed workstations:

System Preferences > Engery Saver > Enable Power Nap

Screen Shot 2016-08-09 at 12.43.45 PM

So if you want to inspect it before you install, just:

$ git clone https://github.com/seannyob/portsUpdate
$ cd portsUpdate

Note that there are four files:
setenv.PATH.plist
com.seannyob.portsUpdate.plist
portsUpdate
Install

And then to install you would just set Install executable if it isn’t, then run it with sudo.

So. setenv.PATH.plist resolves an issue with launchd which is that scripts/applications/programs in /opt/local/bin are not in launchd‘s path.
com.seannyob.portsUpdate.plist tells launchd where portsUpdate is located & when to run it.
portsUpdate is a bash script that runs updates, upgrades & cleanup of your MacPorts package database, ensuring that you are always up to date on features & any security &/or bug fixes of your critical unixy apps.
Install is the same as InstallMacPortsUpdater above. It is a bash script that checks to make sure you’ve installed MacPorts, then git, then gits the package, then installs the three other aforementioned files in their appropriate places in the file system, then loads them into launchd using launchctl.

Note in particular that if you wanted to modify the time &/or frequency of updates/upgrades, you could do so in com.seannyob.portsUpdate.plist and the frequency of uninstall inactive is set for Sundays in portsUpdate.

Feel free to peruse them and use or modify them to your liking. If you have comments &/or suggestions, please let me know!

Gotta Mac? Wanna (more) current bash shell?

Mmmk. So I got this groovy new iMac and was excited to try out Terminal app, which is indeed cool, but for some bizarre reason the default system shell is a generation old. Meh.

Screen Shot 2016-08-08 at 2.40.39 PM

WTH? Ubuntu’s at 4.3.36!

Time for MacPorts! Go there, install the correct package for your version of OS X, and do a

$ xcode-select --install
$ sudo port install bash

Screen Shot 2016-08-08 at 2.50.22 PM

Ok, cool, so yeah now you have it, but you want it to be your default shell.

I suppose you could symlink /bin/bash to the Mac ports version, but that seems a little hardcore.

Let’s do it the “right” way:

$ sudo echo '/opt/local/bin/bash' >> /etc/shells
That adds the newer bash from Mac ports to the system.

To make it your default shell:

chsh -s /opt/local/bin/bash

Exit and restart terminal and you should see:

Screen Shot 2016-08-08 at 2.59.53 PM

Whooohoooo!

Make sure to keep things current by periodically running a:

$ sudo port selfupdate