Port upgrading - my way

Joshua Tinnin krinklyfig at spymac.com
Sat Sep 25 00:04:54 PDT 2004


On Friday 24 September 2004 03:55 pm, "W. D." <WD at us-webmasters.com> wrote:
<snip>
> OK, how about adding a cron job by root like this?
> 
> (Line will wrap.  Everything between '===' on one line)
> ==========================================================
> 15 3 * * * /usr/local/bin/cvsup -h cvsup7.FreeBSD.org /usr/share/examples/cvsup/ports-supfile && portsdb -Uu && pkgdb -fu && cd /usr/ports && make index
> ==========================================================
> 
> 
> Then in the morning running:
> 
> portversion -l "<"
> 
> Would this automate things without causing problems?
> Any other safe ways to automate the process?

I run a script in a cron job every day (I changed the name of the user
in the script to username - just use whatever path points to your ports 
supfile). I am new at scripting, so the out to /dev/null on every 
command might be redundant or unnecessary, and some of it probably
isn't coded efficiently, but it works. Also, I still use portindex, 
which has been removed from ports, but the script can easily be 
modified to use portsdb -Uu. The script also depends on fastest_cvsup 
to pick the fastest server (/usr/ports/sysutils/fastest_cvsup).


Here's root's crontab:

# mail any output to username, no matter whose crontab this is
MAILTO=username
#
# run 4am, every day
1       4       *       *       *       /bin/sh /home/username/supfiles/sup > /var/log/crontab.log 2&>1


Here's the script:

#!/bin/sh
# modified from script found:
# http://www.freebsdforums.org/forums/showthread.php?s=&threadid=1162
# posted by ajr
TODAY=$(date +"%d-%m-%y")
touch /var/log/supscript-$TODAY
SERVER=`/usr/local/bin/fastest_cvsup -q -c us`

if [ "${SERVER}" != "" ]; then
        # update ports, for cvsup-without-gui
        /usr/local/bin/cvsup -L 2 -h $SERVER /home/username/supfiles/ports-supfile 2>&1 | tee -a /var/log/supscript-$TODAY > /dev/null

        # update /usr/ports/INDEX and create INDEX.db; machines with lots
        # of RAM (>64Mb) and swap can use 'portsdb -Uu' as one command, 
 # but portindex is faster
        # !!! portindex is no longer in ports
        /usr/local/bin/portindex 2>&1 | tee -a /var/log/supscript-$TODAY > /dev/null && /usr/local/sbin/portsdb -u 2>&1 | tee -a /var/log/supscript-$TODAY > /dev/null

        # check to see if we need any ports upgrading
        BODY=`/usr/local/sbin/portversion -v | grep needs`

        if [ "${BODY}" != "" ]; then
                echo "$BODY" | mail -s "Ports that need upgrading" username | tee -a /var/log/supscript-$TODAY > /dev/null
        fi

        # clean out /usr/ports/*/*/work and any outdated distfiles
        # prefer to run this manually
        # /usr/local/sbin/portsclean -CD 2>&1 | tee -a /var/log/supscript-$TODAY > /dev/null
fi


Here's my ports-supfile:

#*default host=cvsup10.freebsd.org
# sup script uses output of fastest-cvsup to determine host
*default base=/usr/local/etc/cvsup
*default prefix=/usr
*default release=cvs tag=.
*default delete use-rel-suffix
*default compress
ports-all


I get two emails every day, one of which is the output of the the cron 
job, and the other is a verbose list of ports which have newer versions 
available. Everything is logged to /var/log/supscript-$TODAY (date on
the end in dd-mm-yy). I run portupgrade manually, as I want to be able 
to choose what to upgrade first (and, depending on the changes, it 
might not be necessary to upgrade at all).

- jt


More information about the freebsd-questions mailing list