Chapter 2. Getting started

Table of Contents

Compiling and installing urpkg
Extracting the tarball
Configuring the build
Compiling urpkg
Installing urpkg
Creating a test package
Creating the destination directories
Creating the source files
Adding installation directories and shared files
Installing a program
Playing with the program's files
Pre and post install scripts
The preinstall script
The postinstall scripts
Creating a Slackware package
Listing the package's file
Creating the package
Uninstalling a program

Compiling and installing urpkg

This section details how to compile and install urpkg from source on your machine.


You need a UNIX-like system for urpkg to work. I have tested it on GNU/Linux (LFS and Slackware 12.1), but other systems should work as well. You will also need root access on that system. By design, urpkg is useless if you cannot get root access, since it needs to be able to create new users to install a package. Some scripts assume that your user list is in /etc/passwd and your group list in /etc/group. If that is not the case, you should change them accordingly.

Build time dependencies

urpkg uses CMake as build system, so you will need to download and install it. You will also need the standard make and gcc tools.

If you want to build the documentation yourself (this should not be necessary if you are installing a release tarball), you should have the necessary tools to build docbook documentation, that is

You must also have the useradd, usermod, etc. programs available, because urpkg looks for them before compiling the software. Any standard linux distribution has these tools.

Run time dependencies

urpkg relies on some external shell scripts using standard tools that should be available on your system. Those are:

Most of those software should already be on your system, so urpkg is indeed very light on dependencies.

Extracting the tarball

First, extract the urpkg tarball and cd to it.

    $ tar -xf <Your .tar.gz file>
    $ cd <filename without .tar.gz>

Then, you should create a build directory

    $  mkdir build
    $  cd build

Configuring the build

Now it is time to configure your build. The command is of the form

cmake -DBuildVariable1=Content1 ... -DBuildVariablen=Contentn ..

In general, you should not need to set a lot of variables. A simple

    $ cmake ..

should be enough. The possible variables and their default values are listed below.

  • CMAKE_BUILD_TYPE: specify what kind of build you want to do. It is either "release" or "debug". The default is "release".

  • DEBUG: If this variable is 1, the program will act in debug mode, e.g it will coredump if something is wrong. The default is 0 if CMAKE_BUILD_TYPE is release, 1 otherwise.

  • DESTDIR: The destination directory, defaulting to /. This is the root directory where everything will be copied. This can be useful if for example you want to install urpkg on some other filesystem, and then mount it as the root filesystem.
  • CMAKE_INSTALL_PREFIX: The installation prefix, defaulting to /usr/local. All urpkg files will be installed there.
  • DOCDIR: Where all the documentation will be installed. It defaults to ${CMAKE_INSTALL_PREFIX}/share/doc
  • MANDIR: Where the manpage are on the system. Default to ${CMAKE_INSTALL_PREFIX}/share/man
  • PKGDIR: Path to the package directories, where all package user will have their home directory. See the section called “Package directories” for more information. The default is ${CMAKE_INSTALL_PREFIX}/urpkg/
  • CONFIGDIR: Path to the configuration directory, where urpkg keeps its scripts and some information about what is installed (see the section called “The configuration directory”). The default is ${CMAKE_INSTALL_PREFIX}/etc/urpkg/

  • INST_LOG: Where error outputted by the installation script will be logged. By default, /var/tmp/install.log

  • FINDCMD: The script urpkg uses to find the files belonging to a given package. See also the section called “The find script”. You should not change that variable unless you know what you are doing. It defaults to ${CONFIGDIR}/find

  • PREINST: The script urpkg runs before any installation. See also the section called “Pre and post install scripts”. You should not change that variable unless you know what you are doing. It defaults to ${CONFIGDIR}/preinst

  • POSTINST_DIR: Directory where all the scripts urpkg runs after an installation should be. See also the section called “Pre and post install scripts”. You should not change that variable unless you know what you are doing. It defaults to ${CONFIGDIR}/postinst/

  • UADD_PATH, UMOD_PATH, UDEL_PATH, GADD_PATH, GDEL_PATH: Specify the path for respectively useradd, usermod, userdel, groupadd and groupdel. You need to change those only if cmake cannot find them automatically.

Compiling urpkg

Now everything should be ready. Compile the program.

    $ make

If you want to compile the documentation as well (if you downloaded a release tarball that should not be necessary, as it has already been compiled to most format for you), run

    $ make doc

Installing urpkg

To install urpkg, you have two choices: the first is to directly run

    $ make install

with root privileges if necessary. However, if you have read all I said in the section called “How can urpkg be useful ?” about installation programs changing file permissions behind your back, you may not even want to trust the installation commands generated by cmake.

This is perfectly fine. Since you have compiled urpkg, you can use it to install itself in a secure way. The following section lists the necessary steps. I recommend this method only to users already familiar with how urpkg works. If you are doing this often, you should write yourself a script that automates this action. One such script is in helpers/ in the top level directory of urpkg's source.

Bootstrapping urpkg

In these instructions, I assume you are at urpkg's top level directory and you have already build the software in build/. The shell variable VERSION is assumed to contain urpkg's version number. You can replace it with whatever you like.

First, cd to the build directory.

      $ cd build/

For various reasons, you should create the package directory first, as root. Replace PKGDIR in the following instructions with whatever you configured the program with in the section called “Configuring the build”

      $ mkdir ${PKGDIR}

You should not forget to create the install and shared group, and then mark places where you want urpkg to be installed as install directories.

      $ groupadd urpkgrp-install
      $ groupadd urpkgrp-shared
      $ src/urpkg --gen ${CMAKE_INSTALL_PREFIX}/bin
      $ src/urpkg --gen $DOCDIR
      $ src/urpkg --gen ${MANDIR}/man*
      $ src/urpkg --gen $(dirname $CONFIGDIR)

Then, you have to create a temporary package directory where urpkg will put all files of the urpkg package. You will then copy this temporary package directory to the real package directory (which is created during urpkg's installation).

      $ PKGDIR="$(mktemp -d /var/tmp/urpkg.XXXXXXX)"

To avoid any permission problem when the install script tries to create files in the build directory, change its access permissions.

      $ chmod -Rv o+xrw .

You are now ready to run urpkg. Be aware though that no find command, no postinstall script and no preinstall script are available so you have to either specify the path explicitly or disable them when you invoke urpkg.

      $ src/urpkg --install --pkg-name=urpkg-$VERSION \
      --findcmd=../scripts/find --pkg-dir=$PKGDIR --no-preinst --no-postinst \
      make install

Normally, everything should go fine and urpkg should be installed. Check it by running

      $ urpkg --info

You still have to copy the temporary package directory to the real package directory. You can know its location by looking at the output of urpkg --info. I will refer to it as TRUE_PKGDIR

      $ cp -rav ${PKGDIR}/urpkg-$VERSION $TRUE_PKGDIR

That's not completely finished. The package user has been created with the temporary package directory as its home directory. To change that, you need to know what the package user is. You can find it using

      $ USERNAME="$(stat --format=%U ${TRUE_PKGDIR}/urpkg-$VERSION)"

Finally, change the package user's home directory and remove the temporary package directory

      $ usermod --home ${TRUE_PKGDIR}/urpkg-$VERSION $USERNAME
      $ rm -rv $PKGDIR

I leave up to you whether you want the package to own the package directory. I like to keep the package directory owned by root, because even if you remove urpkg from your system, you might want to keep some files from various package directories.