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.
- First create a jail and build/install packages. I have created a build jail only for this purpose.
- Use the script posted below to backup currently installed packages and setup a package tree similar to “make package” used at ports build. (Modify the first line according to your needs)
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
donefor 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=`ls1 | 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
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.
- Put the files onto a webserver using the following directory scheme:
pub/FreeBSD/ports/<arch>/packages-<version>-release
Example:
pub/FreeBSD/ports/i386/packages-7.2-release/Latest/bash.tbz
- Use this as a source with pkg_add (or pkg_replace):
export PACKAGEROOT=http://example.com
Usingpkg_add -r bashwill fetch from the following URL:
http://example.com/pub/FreeBSD/ports/i386/packages-7.2-release/Latest/bash.tbz
Posted 2010/03/23 23:10 by jos
Comments
← FreeBSD 7 jail source address selection Firewall for VMware vSphere virtual machines →

ldvpskw Says:
dslDow <a href=“http://zanthlayiyai.com/”>zanthlayiyai</a>, [url=http://dgwcbchvxnqo.com/]dgwcbchvxnqo[/url], [link=http://vvwzoglsadke.com/]vvwzoglsadke[/link], http://qcqonrwoskjx.com/
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 :)
ozblwhlbre Says:
x847Kt <a href=“http://lheiasisrqei.com/”>lheiasisrqei</a>, [url=http://uaxvnmftehwu.com/]uaxvnmftehwu[/url], [link=http://hbfqwjsrtoem.com/]hbfqwjsrtoem[/link], http://guetehizhtbj.com/
cheap Montblanc pens Says:
This article is very good, very appealing. Affects every reader chord, hoping to share with you the exchange. Thank articles.
Day Date II swiss watches Says:
This article is very good, very appealing. Affects every reader chord, hoping to share with you the exchange. Thank articles.
knockoff Fendi watches Says:
This article is good, very good, let I learned a lot from ~ you don’t miss, hurry to join!
Hublot wristwatch replicas Says:
Articles are moving every reader with heart, and full of appeal. Let us have to admire, thank your article!
crystal case for iphone 4 Says:
You really surpassed visitors’ expected results. Thanks for rendering such informative, safe, educational and in addition fun tips on your topic to Julie.
time for a smile Says:
Wow, awesome blog layout! How long have you been blogging for?
you made blogging look easy. The overall look of your web site
is wonderful, as well as the content!