Altering scripts to use the jail

Recently, I wrote about using a jail to get better results. Today, I’m altering the scripts so they make use of this jail. For the most part, this will involve the creation of scripts that will run in the jail and duplicate the functionality of the existing FreshPorts code.

What needs to be changed?

I’m looking for stuff that uses ‘make -V’. I found three files:

  1. category.pm
  2. port.pm
  3. test-master-port.sh

We will deal with each script in turn.

NOTE: All of these scripts and the way they are invoked, changed before I committed them. See the follow-up article.

category.pm

This script obtains the COMMENT value for a category Makefile. For example, sysutils/Makefile, contains this: COMMENT = System utilities

The script works like this:

$ make -V COMMENT
System utilities

The existing code is:

    my $makecommand = "make -V COMMENT " .
                   "DISTDIR=$FreshPorts::Constants::DISTDIR " .
                   "PORTSDIR=$FreshPorts::Config::path_to_ports LOCALBASE=/nonexistentlocal 2>$TmpFile";

With the new jail approach, I won’t need to specify PORTSDIR. I am completely unsure as to why PORTSDIR is specified. I think that LOCALBASE parameter strives to eliminate some of the inaccurate results that I encountered early in the development of FreshPorts.

This is the shell script I just created, and named make-category-comment.sh:

#!/bin/sh
CATEGORYDIR=$1
cd ${CATEGORYDIR}
/usr/bin/make -V COMMENT -f ${CATEGORYDIR}/Makefile

It works like this:

$ sudo /usr/sbin/chroot -u dan /wdc/dan/FreshPorts/ports-jail/ /make-category-comment.sh /usr/ports/sysutils
System utilities

port.pm

This will be the big file. This is the main place where values are extracted. There is a lot of work done here.

I found these commands:

    $makecommand = "make -V PORTNAME -V PKGNAME -V DESCR -V CATEGORIES -V PORTVERSION -V PORTREVISION " .
        " -V COMMENT -V COMMENTFILE -V MAINTAINER -V EXTRACT_SUFX " .
        " -V BUILD_DEPENDS -V RUN_DEPENDS -V LIB_DEPENDS -V FORBIDDEN -V BROKEN -V DEPRECATED -V IGNORE ".
        " -V MASTER_PORT -V LATEST_LINK -V NO_LATEST_LINK -V NO_PACKAGE -V PKGNAMEPREFIX -V PKGNAMESUFFIX -V PORTEPOCH " .
        " -V RESTRICTED -V NO_CDROM -V EXPIRATION_DATE -V IS_INTERACTIVE " .
        " -V ONLY_FOR_ARCHS -V NOT_FOR_ARCHS -V LICENSE -f $Makefile " .
        " DISTDIR=$FreshPorts::Constants::DISTDIR " .
        " PORTSDIR=$FreshPorts::Config::path_to_ports LOCALBASE=/nonexistentlocal 2>$TmpFile";
        my $makecommand = "make -V DESCR -f $SVNDIR/$SVNITEM PORTSDIR=$FreshPorts::Config::path_to_ports " .
                          "LOCALBASE=/nonexistentlocal 2>$TmpFile";

The first command extracts all the major information regarding a port. The second pulls out the DESCR field for a port. Usually, that points to the pkg-descr file in the port directory. I seem to recall that the DESCR field could have specified an external file for the description. Scanning the logs, this command has not been executed in 2012 or 2011. I suspect it is no longer required and I’ll probably heavily modify the code to remove all that cruft. More investigation is required.

The first command has been ported to a shell script named make-port.sh which contains this:

#!/bin/sh

PORTDIR=$1

cd /usr/ports/${PORTDIR}

make -V PORTNAME    -V PKGNAME        -V DESCR           -V CATEGORIES     -V PORTVERSION    -V PORTREVISION  \
     -V COMMENT     -V COMMENTFILE    -V MAINTAINER      -V EXTRACT_SUFX   -V BUILD_DEPENDS  -V RUN_DEPENDS   \
     -V LIB_DEPENDS -V FORBIDDEN      -V BROKEN          -V DEPRECATED     -V IGNORE         -V MASTER_PORT   \
     -V LATEST_LINK -V NO_LATEST_LINK -V NO_PACKAGE      -V PKGNAMEPREFIX  -V PKGNAMESUFFIX  -V PORTEPOCH     \
     -V RESTRICTED  -V NO_CDROM       -V EXPIRATION_DATE -V IS_INTERACTIVE -V ONLY_FOR_ARCHS -V NOT_FOR_ARCHS \
     -V LICENSE \
     -f /usr/ports/${PORTDIR}/Makefile \
     PORTSDIR=/usr/ports               \
     LOCALBASE=/nonexistentlocal

It is invoked like this:

$ sudo /usr/sbin/chroot -u dan /wdc/dan/FreshPorts/ports-jail/ /make-port.sh sysutils/bacula-server
bacula
bacula-server-5.2.12
/usr/ports/sysutils/bacula-server/pkg-descr
sysutils
5.2.12
0
Network backup solution (server)

Dan Langille 
.tar.gz
/nonexistentlocal/lib/libcrypto.so.8:/usr/ports/security/openssl
/nonexistentlocal/lib/libcrypto.so.8:/usr/ports/security/openssl
bac:/usr/ports/sysutils/bacula-client intl:/usr/ports/devel/gettext pq.5:/usr/ports/databases/postgresql90-client





bacula-server



-server
0







All those blank lines are merely empty values.

test-master-port.sh

Some time ago, I had a problem with master ports. I created a shell script to test for failure. The command it runs is:

MASTER='sysutils/bacula-server'

cd ${PORTSDIR}/sysutils/bacula-client
COMMAND="make -V MASTER_PORT PORTSDIR=${PORTSDIR} LOCALBASE=/nonexistentlocal X11BASE=/nonexistentx"
MASTER_PORT=`${COMMAND}`

if [ "${MASTER_PORT}X" != "${MASTER}X" ]
then
    echo "make -V MASTER_PORT on sysutils/bacula-client does not give '${MASTER}'\nInstead, it gives '${MASTER_PORT}'." | mail -s "FAILED: MASTER_PORT" ${ADMINEMAIL}
fi

The new shell script I created (make-master-port-test.sh) looks like this:

#!/bin/sh

PORTDIR=$1

cd /usr/ports/${PORTDIR}

/usr/bin/make -V MASTER_PORT PORTSDIR=/usr/ports LOCALBASE=/nonexistentlocal X11BASE=/nonexistentx

It is invoked like this:

$ sudo /usr/sbin/chroot -u dan /wdc/dan/FreshPorts/ports-jail/ /make-master-port-test.sh sysutils/bacula-client
sysutils/bacula-server

So far, so good.

Other points to ponder

All the commands which use the jail have a similar pattern. I think I need to put that into a function/script and use that within the FreshPorts code. Do you have ideas/suggestions for that area? Keeping in mind that the existing code is invoked from perl and shell scripts.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top