2009/09/03

macports notification of outdated

A quick and dirty bash/shell script to get automatic notification of outdated macports:

#!/bin/bash

# 20090902 mvgfr: tweaks
# 20071110 mvgfr: check for outdated macports & notify if any - via growl & stdout (emailed when cron'd)
# 20080209 mvgfr: must run sync before, so it can learn about updates!
# also added "-H localhost" workaround for growl Leopard bug (ignores some)

debugMe="" # presume we'll only use alphanum; like "YES" or empty string for NO

# may take awhile; is this an issue?
if [ ! $debugMe ] ; then /opt/local/bin/port sync; fi

if [ $debugMe ] ; then
potentialOutput="`echo 'debugging:';ls -1|head -1`"
else
potentialOutput=`/opt/local/bin/port outdated`
fi

if [ "$potentialOutput" != "No installed ports are outdated." ] ; then
echo "$potentialOutput" # for cron to email to root
if [ -f /usr/local/bin/growlnotify ]; then
NumLinesToDisplay=$((`echo "$potentialOutput" | wc -l` -1))
if [ $NumLinesToDisplay -lt 1 ]; then
echo "underflow error; see log" | /usr/local/bin/growlnotify -H localhost -s -t 'macports outdated:'
elif [ $NumLinesToDisplay -gt 20 ]; then
echo "overflow error; see log" | /usr/local/bin/growlnotify -H localhost -s -t 'macports outdated:'
else
echo "$potentialOutput" | tail -`echo $NumLinesToDisplay` | \
/usr/local/bin/growlnotify -H localhost -s -t 'macports outdated:'
fi
fi
fi

if [ $debugMe ] ; then echo "`date "+%Y%m%d-%H%M%S"`: $potentialOutput" >> /var/log/port-outdated.log; fi

#end


(Old 2007/12/01 script here.)

2 comments:

seron said...

How do you schedule this script to run at set intervals? I would assume it's run as root, or do you have an different user set up that is allowed to run port sync?

Marcantonio Rendino said...

I haven't gotten any more fancy than cron (yes, as root).

Not elegant or terribly secure, though it's not a server, and the machine it pretty well locked down otherwise, so the risk is minimal.