Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Dec 2006 03:16:21 -0500
From:      Vinny <>
Subject:   Python script to create packages, sane?
Message-ID:  <>

Next in thread | Raw E-Mail | Index | Archive | Help
Hi Everyone,

FreeBSD 6.1-RELEASE-p3 #0: Tue Aug 22 22:42:18 EDT 2006 
root@localhost:/usr/obj/usr/src/sys/THE  i386

I'm been working with and learning the ports and packages
system.  I enjoy the challenge because this stuff can get
awfully vexing every now and then.

I just finished running 'portmanager -u -f -l' after
several days (with a little 'portmanager -u -f -l --resume'
every now and then).  I have this nicely up-to-date large (450+)
set of ports installed.  It cost a lot in terms of time.
So I want to take all these installed ports and build
packages out of them.  Enter the following python program:

====================== 8< ===================
#!/usr/bin/env python
# Script to create packages for currently installed ports/packages.
# Uses pkg_create with the -b option.
# It will build packages in the current working directory so a
# 'cd /usr/ports/packages/All' command would be useful before
# running it.
# Usage: script make_package.log && /var/db/pkg/*

# needed modules
import sys, os

pkg_create = "/usr/sbin/pkg_create"
print '==========='

dash_b = '-b'

for name in sys.argv[1:]:

#    print ":: ", name
     pkg_name = name.split('/')[-1]
     print "Installed package:", pkg_name

     # run pkg_create command, capture errors but don't stop
     print "Command: ", pkg_create, dash_b, pkg_name
     status = os.spawnv(os.P_WAIT, pkg_create, [pkg_create, dash_b, pkg_name])
     print "Status:", status

====================== 8< ===================

The results of running it are encouraging:

# cd /usr/ports/packages/All
# script make_packages.log
Script started, output file is make_packages.log
# ~/bin/ /var/db/pkg/*
Installed package: GraphicsMagick-1.1.7
Command:  /usr/sbin/pkg_create -b GraphicsMagick-1.1.7
Status: 0
Installed package: ImageMagick-
Command:  /usr/sbin/pkg_create -b ImageMagick-
Status: 0
[... and so on for 450+ ports. only 3 errors below]

Installed package: pkgdb.db
Command:  /usr/sbin/pkg_create -b pkgdb.db
pkg_create: can't change directory to '/var/db/pkg/pkgdb.db'!
Status: 1
[of course]

Installed package: xorg-libraries-6.9.0
Command:  /usr/sbin/pkg_create -b xorg-libraries-6.9.0
tar: lib/libGL.a: Cannot stat: No such file or directory
pkg_create: make_dist: tar command failed with code 256
Status: 2
Installed package: xorg-server-6.9.0_5
Command:  /usr/sbin/pkg_create -b xorg-server-6.9.0_5
tar: lib/modules/extensions/ Cannot stat: No such file or directory
pkg_create: make_dist: tar command failed with code 256
Status: 2

I've seen the last few types of errors with
package creation before.  I was using both portupgrade
and 'make package' commands when I encountered such
errors.  To fix them is to simply force re-installation
of the port in question.  No big deal.

A brief directory listing shows fresh packages:

/usr/ports/packages/All# ls -lat | more
total 3019778
-rw-r--r--   1 root   ports      48352 Dec 30 02:21 make_packages.log
-rw-r--r--   1 root   ports   13217116 Dec 30 02:21 zope-3.3.0.tgz
drwxr-xr-x   2 root   ports      29184 Dec 29 18:33 .
-rw-r--r--   1 root   ports    1410567 Dec 29 18:33 xorg-vfbserver-6.9.0_2.tgz
-rw-r--r--   1 root   ports     176158 Dec 29 18:33 xterm-223.tgz
-rw-r--r--   1 root   ports     423100 Dec 29 18:33 xvid-1.1.2,1.tgz

To make a long story short and actually ask a question, will
building packages this way make proper packages?  Am I doing
something fundamentally wrong in this approach?  I'd like to
simply use the generated packages as a local repository for the
other FreeBSD systems I use.

Thanks for any comments.

Want to link to this message? Use this URL: <>