Subscribe to the RSS Feed

 

FreeBSD binary package repository howto

For a long time we have been trying to come up with a way to have a binary package repository which is based on heterogeneous package sources. (pkg_add/ports)
After playing with “portupgrade” and “make package” which often failed due to various reasons, it became obvious this method wont be beneficial in long-term.
This howto explains how to create the exact package replica of a jail full of installed packages.



PACKAGEDIR=/packages
mkdir -p $PACKAGEDIR/All
PACKAGELIST=`find /var/db/pkg -type d | awk -F/ {‘print $NF’} | tail -n +2`
for i in $PACKAGELIST; do cd $PACKAGEDIR/All if [ ! -r $i.tbz ]; then echo “Packaging $i” pkg_create -b $i else echo “Packaging $i skipped” fi
done

for i in $PACKAGELIST; do cd $PACKAGEDIR/All ORIGIN=`grep “@comment ORIGIN” /var/db/pkg/$i/+CONTENTS | awk -F: {‘print $2’}` ORIGIN_CAT=`echo $ORIGIN | awk -F/ {‘print $1’}` ORIGIN_PORTNAME=`echo $ORIGIN | awk -F/ {‘print $2’}`

echo “Linking $ORIGIN_CAT/$ORIGIN_PORTNAME” [ -f $PACKAGEDIR/$ORIGIN_CAT/$i.tbz ] && rm $PACKAGEDIR/$ORIGIN_CAT/$i.tbz [ -f $PACKAGEDIR/Latest/$ORIGIN_PORTNAME.tbz ] && rm $PACKAGEDIR/Latest/$ORIGIN_PORTNAME.tbz FINDNAME=`echo $i | sed ‘s/\(.\)\-./\1/’` OLD_TARGETS=`ls 1 | grep -e “$FINDNAME[-]*\.tbz” | grep -v $i` [ ! -d $PACKAGEDIR/$ORIGIN_CAT ] && mkdir -p $PACKAGEDIR/$ORIGIN_CAT [ ! -d $PACKAGEDIR/Latest ] && mkdir -p $PACKAGEDIR/Latest for x in $OLD_TARGETS; do TEMP_ORIGIN_NAME=`tar -xjOf $x “+CONTENTS” | grep “@comment ORIGIN” | awk -F: {‘print $2’} | awk -F/ {‘print $2’}` if [ $ORIGIN_PORTNAME == $TEMP_ORIGIN_NAME ]; then echo “Deleting unneeded target: $x” [ -r $PACKAGEDIR/$ORIGIN_CAT/$x ] && rm $PACKAGEDIR/$ORIGIN_CAT/$x; [ -r $PACKAGEDIR/All/$x ] && rm $PACKAGEDIR/All/$x; fi done cd $PACKAGEDIR/$ORIGIN_CAT && ln -s ../All/$i.tbz $i.tbz cd $PACKAGEDIR/Latest && ln -s ../All/$i.tbz $ORIGIN_PORTNAME.tbz done


Download

Explanation:
The first loop backs up all the installed packages on the system to $PACKAGEDIR/All. Then by going through the packages again the script recreates the symlinks used in FreeBSD packaging. It also checks for package files with different versions (but same origin) and deletes those which are not installed.
Example #1:
A common roll-back scenario

mysql-server-5.1.43.tbz [installed]
mysql-server-5.1.45.tbz
To be deleted: mysql-server-5.1.45.tbz

Example #2:
Packages with different versions that can co-exist on the same system

ruby-1.8.7.248,1 [installed]
ruby-1.9.1.376_1,1 [installed]
To be deleted: none

The script checks for package origins and by determining that lang/ruby18 is different from lang/ruby19 both packages remain untouched and included to the repository.

Known bugs: Does not check for deleted packages. It’s better to recreate the whole repository after a big portupgrade anyway.

Posted 2010/03/23 23:10 by jos


Comments

  1. Feb 7, 12:11 PM

    adrian ilarion ciobanu Says:

    “cleanup test operator fix”: http://slwdc.shrd.net/f/bsdbased_com_pkg_repo_fix_cleanup_test_operator.diff

    this textile thing doesn’t seem to do what it says :)

Leave a Comment

Add your comment. Preview then Submit.


Hidden


Textile Help