Sp4ce.net rss

MacPorts outdated ports notifications

Each time I wanted to install a new ports at home, I got a notification that some of my ports are outdated. I then run the update, but it could take lots of time (more than one hour) if I didn't run it for a long time. This post explains how to get a notification about recent outdated ports and update them more often.

The MacPorts Project is an open-source initiative for compiling, installing, and upgrading open-source software on Max OS X operating system. I’ve been using it for some years now and it is very stable and easy to use.

Yesterday afternoon, I wanted to finish the tag cloud plugin of my website when I run into a error in Jekyll. I fixed it, but I needed to upgrade MacPorts. I didn’t touch to it for months and I had a lot of outdated ports. It took me more than one hour to update everything and so delayed my work. I thought that I really needed to have notifications, or automatic update of ports.

I read at the MacPorts Project documentation and I found exactly what I needed in the FAQ: “How do I know when an update is available? Do I have to constantly perform manual checks?”.

Based on this, I created a small shell script:

update.sh

#!/bin/sh

# This script updates MacPorts and send you and email when there are ports to manually update.

MSMTP_DEST=bapt at sp4ce.net
MSMTP_CONFIG=/Users/baptiste/.msmtprc

# This command "teaches" MacPorts about new updates.
/opt/local/bin/port selfupdate

# Get the outdated ports
outdated=`/opt/local/bin/port outdated`
echo $outdated > /Users/baptiste/Scripts/MacPorts/outdated.txt

# mail the result
# echo $outdated | msmtp -C $MSMTP_CONFIG $MSMTP_DEST

I disable the mail command line because I finally didn’t want to receive email everyday, because if I can’t connect to my mac and perform the update, I will simply forget to do it. The best thing to do is to get the notification when I can really update the ports just after: when I open a terminal.

Then I put a line in my .bashrc file: echo /Users/baptiste/Scripts/MacPorts/outdated.txt and so I get a nice message in my terminal:

Finally I setup a cron job as the root user (needed to run the selfupdate):

sudo crontab -e

* * * * * sh /Users/baptiste/Scripts/MacPorts/update.sh