OpenPKG Project
OpenPKG ProjectDevelopmentEnvironment

Development Environment

Ad-Hoc Tweaking Packages

Some people want to tweak OpenPKG packages beyond the finite options already avaiable or they even want to create their very own OpenPKG package. Ignoring the complexities of maintaining individual adjustments over time, here is a very simple and ad-hoc way of quickly hacking OpenPKG package specifications.

All examples assume you switch the identity to the "management user" of the OpenPKG instance. Trick: in case you just know the filesystem prefix, use the following command to switch to the management user:

# switch to instance management user
$ su – `prefix/bin/openpkg rpm --eval '%{l_musr}'`
Now build the package. Let's assume it is the make package.
# download source package
$ ~/lib/openpkg/curl -s -O \
  ftp://ftp.openpkg.org/current/SRC/CORE/make-3.81-*.src.rpm

# build corresponding binary package
$ openpkg rpm --rebuild make-3.81-*.src.rpm
[…]
Wrote: prefix/RPM/PKG/make-3.81-date.arch-os-tag.rpm
[…]

Oops, the binary package is now already rolled! But package specification tweaking must happen between unpacking the source archive and before building the binary, so let's break the rebuild action into smaller pieces.

# download source package
$ ~/lib/openpkg/curl -s -O \
  ftp://ftp.openpkg.org/current/SRC/CORE/make-3.81-*.src.rpm

# unpack source package (by installing it)
$ openpkg rpm -Uvh make-3.81-*.src.rpm

# find the package ingredients
$ cd ~/RPM/SRC/make
$ ls -l
-rw-r--r— 1564560 2006-04-01 19:09 make-3.81.tar.gz
-rw-r--r—     896 2006-04-01 20:25 make.patch
-rw-r--r—    3408 2006-10-16 16:31 make.spec

# edit the package specification file
# (practice calls for an editor session here, of course)
$ ~/lib/openpkg/shtool subst -i \
  -e 's;^\(Release: .*\);.foo;' \
  make.spec

# build package
$ openpkg rpm -ba make.spec
[…]
Wrote: prefix/RPM/PKG/make-3.81-date.foo.src.rpm
Wrote: prefix/RPM/PKG/make-3.81-date.foo.arch-os-tag.rpm
[…]

Voila! Your first custom source and binary package pair resulted. Time to copy your work to a safe place. Keep in mind, the next time someone installs the source package, even indirectly via openpkg rpm --rebuild — or even more indirectly via "openpkg build" — your changes will be discarded. No questions will be asked. You have been warned.

Well, perhaps you even want to share your package with others in the OpenPKG Community. For this just upload the file to the FTP service upload area. But keep in mind that your contribution can be only taken over into the official OpenPKG distribution, if you additionally accede the OpenPKG Contributor Agreement (OCA) and drop a notice to openpkg-dev@openpkg.org telling the others that the uploaded file was contributed by you.

# upload package to OpenPKG contribution area
$ ~/lib/openpkg/curl -s --upload-file \
  prefix/RPM/PKG/make-3.81-date.foo.src.rpm \
  ftp://ftp.openpkg.org/contrib/00UPLOAD/
The openpkg rpm -ba command above built both source and binary packages. But even this can be broken down into -bs (build source) and -bb (build binary). Where in turn -bb is just the last in a sequence of -bp (prepare), -bc (build/compile), -bi (install), -bl (file list) and -bb (build binary). Those sequences reflect sections in the package specification, blocks of code identified by a leading % sign. Just see yourself:
# check the specification sections
$ grep ^% make.spec
%description
%track
%prepprepapre
%buildbuild/compile
%installinstall
%files -f filesfile list
%clean

Running those sections independently usually restarts the whole build from scratch and works all the way through the item specified. To just start where the previous step stopped, add the option --short-circuit.

# build source and binary packages in individual steps
$ openpkg rpm -bs make.spec
$ openpkg rpm -bp make.spec
$ openpkg rpm -bc make.spec --short-circuit
$ openpkg rpm -bi make.spec --short-circuit
$ openpkg rpm -bl make.spec --short-circuit
$ openpkg rpm -bb make.spec --short-circuit
$ openpkg rpm --clean make.spec

Serious Development

If you want to perform serious package development and especially want to maintain your local modifications in parallel to the upstream package changes of OpenPKG, you have to establish a full-size OpenPKG development environment. This environment consists mainly of the following parts:
  1. a reasonable OpenPKG instance with the necessary tools, e.g. /openpkg
  2. a scratch OpenPKG instance for bare development purposes, e.g. /openpkg-dev
  3. a regular non-privileged Unix user account of the developer, e.g. foo with home directory /u/foo/
  4. the possibility to switch from the developer account foo to the superuser account root through the addressing root@localhost.
  5. an openpkg dev working area, e.g. /u/foo/work/openpkg.
So, first create the OpenPKG instance /openpkg which at least should contain the packages openpkg, make, binutils, gcc, bash, vim and last but not least openpkg-tools.
# establish OpenPKG instance /openpkg
$ cd /tmp
$ wget ftp://ftp.openpkg.org/current/SRC/CORE/openpkg-[0-9]*.src.sh
$ sh openpkg-*.src.sh \
  --prefix=/openpkg \
  --user=openpkg \
  --group=openpkg \
  --tag=openpkg
$ sh openpkg-*.*-*-openpkg.src.sh
$ /openpkg/bin/openpkg build \
  make binutils gcc bash vim openpkg-tools | sh
Now create the OpenPKG instance /openpkg-dev. It doesn't need any packages, but as you usually always need a few development tools sooner or later, it is reasonable to install a few of them already at this point.
# establish OpenPKG instance /openpkg-dev
$ sh openpkg-*.src.sh \
  --prefix=/openpkg-dev \
  --user=openpkg-dev \
  --group=openpkg-dev \
  --tag=openpkg-dev
$ sh openpkg-*.*-*-openpkg-dev.src.sh
$ /openpkg-dev/bin/openpkg build \
  make binutils gcc | sh
The Unix user account of the developer usually already exists. If not, please consult your local Unix manual pages on how to create the account foo.
# create developer account (FreeBSD)
$ pw groupadd foo
$ pw useradd foo -g foo -d /u/foo -s /openpkg/bin/bash

# create developer account (Linux or Solaris)
$ groupadd foo
$ useradd -d /u/foo -s /openpkg/bin/bash -g foo foo

Now make sure that the user foo can switch to the superuser root with the command "ssh root@localhost". This is usually achieved by installing OpenSSH into the /openpkg instance, allowing root access, creating an SSH key for foo and then installing the public key of foo into ~root/.ssh/authorized_keys.

# install OpenSSH
$ /openpkg/bin/openpkg build openssh | sh

# enable root access
$ vi /openpkg/etc/openssh/sshd_config
<< PermitRootLogin no
>> PermitRootLogin yes

# start OpenSSH
$ /openpkg/bin/openpkg rc openssh start

# generate SSH private/public key pair for "foo"
$ su – foo
$ umask 022
$ ssh-keygen -b 1024 -t DSA
$ exit

# grant "foo" access to "root" account via SSH
$ umask 022
$ test -d ~root/.ssh && mkdir ~root/.ssh
$ cat ~foo/.ssh/id_dsa.pub >> ~root/.ssh/authorized_keys
Now finally create the "openpkg dev" configuration and corresponding development working area and fill it with content from the official OpenPKG CVS repository:
$ su – foo
$ mkdir ~/work
$ mkdir ~/work/openpkg
$ mkdir ~/.openpkg
$ cat <<EOF >>~/.bash_login
. $HOME/.bashrc
EOF
$ cat <<EOF >>~/.bashrc
export PATH=/openpkg/bin:/openpkg/sbin:/bin:/usr/bin:/sbin:/usr/sbin:$HOME/bin
export MANPATH=/openpkg/man:/usr/share/man
export INFOPATH=/openpkg/info:/usr/share/info
export TMPDIR=/tmp/foo
test ! -d $TMPDIR && mkdir $TMPDIR && chmod 711 $TMPDIR
export EDITOR=vim
alias ll="ls -l"
alias lx="ls -la"
alias opd="export INPUTRC=~/.openpkg/dev.inputrc; openpkg dev"
EOF
$ cat <<EOF >>~/.inputrc
set meta-flag on
set convert-meta off
set output-meta on
set show-all-if-ambiguous on
EOF
$ cat <<EOF >>~/.openpkg/dev.inputrc
"\ev": "vi *.spec\n"
"\ep": "opd bp\n"
"\ec": "cd $TMPDIR/openpkg/$P*\n"
"\eb": "opd bu -f\n"
"\ep": "opd pe\n"
"\ei": "opd inst -f\n"
"\ee": "opd er\n"
"\et": "opd tr "
"\ed": "cvs diff\n"
"\er": "opd rel "
EOF
$ cat <<EOF >>~/.openpkg/dev.rc
TMPDIR=${OPENPKG_TMPDIR-/tmp/foo}
export TMPDIR
OPENPKG_NAME="Mr. Foo"
OPENPKG_TEMP=${TMPDIR}/openpkg
OPENPKG_MODE=contributor
OPENPKG_TRUN=/openpkg-dev
OPENPKG_INST=/openpkg-dev
OPENPKG_WORK=${HOME}/work/openpkg
OPENPKG_RMOD=openpkg-src
OPENPKG_REPO=:pserver:anonymous@cvs.openpkg.org:/v/openpkg/cvs
OPENPKG_SAVE=ftp://ftp.openpkg.org/contrib/00UPLOAD
EOF
$ openpkg dev setup
Now, for entering the "openpkg dev" (aka "opd") shell, just run
# enter OpenPKG development shell
$ opd
You'll find yourself in ~/work/openpkg/src/ which is containing the content of the package specifications from the OpenPKG CVS repository. The usually first step when starting new work is to bring your development environment up-to-date with the upstream changes:
# update sources with upstream changes
$ opd up
Then for modifying the make package:
# edit "make" package
$ cd make
$ opd vi

# build "make" package
$ opd build -f

# install "make" package
$ opd install -f
Once you want to share your changes with the OpenPKG Community, run:
# release package to OpenPKG contribution area
$ opd rel
For more details about all the other commands please run:
# determine information about other commands
$ opd help