Checkout specific patchset of FreeBSD sources

Following is a script to checkout FreeBSD sources (from its subversion repository) to specific patch-level as asked by a friend on IRC:

#!/bin/sh

if [ -z "$1" -o -z "$2" ]; then
        echo Usage: $0 release patchlevel
        echo e.g. To get 8.0-p5, $0 8.0 5

        exit 0
fi

RVER=$1
PVER=$2

SVNBASE=svn://svn.freebsd.org/base/releng
NEWVERS=sys/conf/newvers.sh
LIMIT=40
RETVAL=0

SVNLOG=$(mktemp -t $(basename $0))

if svn log -l $LIMIT $SVNBASE/$RVER/$NEWVERS >$SVNLOG; then
        BASEREV=$(awk 'BEGIN { sec=1; i=0; } /^r[[:digit:]]+/ { sec=0; revs[i++]=rev=$1; } /^(Security|Errata):/ { sec=1; } /^-+$/ { if(sec == 0) { print revs[i-'$PVER'-1]; exit 0; } }' <$SVNLOG)
        echo svn co -$BASEREV $SVNBASE/$RVER
else
        echo Error executing svn log
        RETVAL=$1
fi

rm -f $SVNLOG
exit $RETVAL

Obligatory screenshot:

chateau.d.if!abbe [~/bin] % co-freebsd-sources 7.0 4
svn co -r182740 svn://svn.freebsd.org/base/releng/7.0
chateau.d.if!abbe [~/bin] % svn cat -r 182740 svn://svn.freebsd.org/base/releng/7.0/sys/conf/newvers.sh|grep RELEASE-p
BRANCH="RELEASE-p4"
Download link: http://www.lostca.se/~abbe/scripts/co-freebsd-sources
SHA256 sum: c9958c4fd7cae5a5e9ff3fa84ba3af6adf38d9c8494b7913ad5b3a2f265a3f48

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti-Spam Quiz: