This script provides a simple method for tracking software that you have built from source, or binaries that you want to repackage from another distribution. It also simplifies transferring the software to other machines for install or backup. It works as a nice secondary package management tool, without the need to work with complex, distro specific, build tools.
Concepts have been borrowed from Arch Linux's makepkg, CRUX's pkgmk, porg (formely paco) and other Linux package managers. Like makepkg/pkgmk it works by reading a meta file in the current working directory (in this case, named "BUILD"). This file specifies details about where to find the software, what it is called and how to build it. This information is combined with commands within the createpkg script itself, allowing for automation of source download, extraction, compilation and creation of installable “packages”. As with porg, these packages include a log of all the files present (including the log itself). This log can be used to precisely remove the files that form the package contents, even if they are scattered across the file system.
Unlike more comprehensive package management tools (including those from which it borrows ideas), this script has no major dependencies outside of a typical Linux build environment. This means that whilst its abilities are quite limited, it is very easy to setup (create a BUILD file and run the script). It also automatically handles many of the tedious, repeative steps such as source fetching/extraction, setting (root) file ownership, compressing man pages, stripping binaries and tracking of installed files.
In an empty directory create a BUILD file that sets basic variables
describing the package (usually only “name”, “version” and an array called
“source” [that links to source files] are required). Add a “build” function
that includes the build and installation steps. The familiar ./configure; make install
combo is often enough, with some method to redirect the output
to the packaging/staging directory (e.g. “DESTDIR=
”, “--prefix
”, etc.).
The easist way to explain how BUILD files work is with examples, so here are a selection.
name=dos2unix
version=7.4.0
source=("https://waterlan.home.xs4all.nl/$name/$name-$version.tar.gz")
build() {
make prefix="$pkg/usr/local" install
}
name=lz4
version=1.8.3
build() {
git clone -b v$version --single-branch --depth 1 https://github.com/$name/$name.git
cd $name
make install DESTDIR="$pkg"
}
name=slack-desktop
version=3.3.3
arch=x86_64 # Slack only offers x64 packages
options=(!man !strip)
source=("https://downloads.slack-edge.com/linux_releases/$name-$version-amd64.deb")
build() {
cp -R usr "$pkg"
rm -fr "$pkg/usr/share/lintian"
}
name=createpkg
_name=11246070 # Non-standard variable
version=master
arch=noarch
options=(clearsrc !man !strip)
source=("https://gist.github.com/ruario/${_name}/archive/$version.zip")
build() {
cd ${_name}-$version
prefix="$pkg/usr/local"
bindir="$prefix/bin"
docdir="$prefix/share/doc"
for script in $name.sh gen-BUILD.sh; do
install -Dm755 $script "$bindir/${script%.sh}"
done
for doc in README.md template-BUILD; do
install -Dm644 $doc "$docdir/$name/$doc"
done
}
The "options" array is used to change the default actions:
- clearsrc: Re-downloaded source packages on every run (Default = Off)
- man: Automatic compression of man pages (Default = On)
- root: Set all files as being owned by root:root (Default = On)
- strip: Strip symbols from binaries (Default = On)
To switch an option On, write its name in the array. To switch it Off, write it prefaced with “!”. Anything missing from the array will use the defaults (see above).
For example, “options=(!man !strip)
” would disable man page compression and
binary stripping, but ownership would still be set to “root:root” (within the
package) and source packages that are already locally present would not be
downloaded again.
Once a BUILD file has been created, all that is needed is to run the
createpkg
from within the directory where BUILD is housed and an installable
package should be created. Using the first BUILD file above, would result in
an installable package called “dos2unix-7.4.0-x86_64-1.pkg.tar.gz” being
created (on a 64-Bit machine). A nice advantage of a well made BUILD file is
that typically you need only adjust the version variable when a new release
comes out.
Installation of these packages simply requires extracting their contents directly into the top level of the file system.
sudo tar Cfx / dos2unix-7.4.0-x86_64-1.pkg.tar.gz
It is then possible to view a listing of the contents of the installed package at any time by reading the appropriate log file.
tr \\0 \\n < /var/lib/createpkg/dos2unix-7.4.0-x86_64-1
Should you ever need to remove the package contents from your system, it can be done by issuing a command like the following:
sudo xargs -0 rm < /var/lib/createpkg/dos2unix-7.4.0-x86_64-1
Tip: To do all creation steps except making a package, use the switch
“--no-package
” (or simply “-n
”). An alternative installation command will
be echoed back, at the end of the creation process (uninstall works the same
way).
All typical filetypes (including symlinks) that were included in the installed package can be removed in this way but not directories. They are intentionally omitted from the package log, since they may have been shared with other software previously present on your system. For the most part empty directories cause no problems and generally have negligible space requirements.
However, if it ever bothers you, construct a find
command to track down old
empty directories that you might want to consider removing. For example:
find /usr/local -type d -empty
⋮
/usr/local/share/doc/dos2unix-7.4.0/sv
/usr/local/share/doc/dos2unix-7.4.0/zh_CN
/usr/local/share/doc/dos2unix-7.4.0/es
/usr/local/share/doc/dos2unix-7.4.0/de
/usr/local/share/doc/dos2unix-7.4.0/fr
/usr/local/share/doc/dos2unix-7.4.0/uk
/usr/local/share/doc/dos2unix-7.4.0/pt_BR
/usr/local/share/doc/dos2unix-7.4.0/nl
/usr/local/share/doc/dos2unix-7.4.0/pl
⋮
You can remove a tree of nested empty folders, such as “/usr/local/share/doc/dos2unix-7.4.0”, quite easily.
sudo find /usr/local/share/doc/dos2unix-7.4.0 -depth -type d -empty -exec rmdir -v {} \;
Tip: The Filesystem Hierarchy Standard (3.0) documents the default directories you can expect to find on a Linux system.
A sample (template) BUILD file and an automatic BUILD file generator script are also included.
See also: pkgtrack
For playing in the weekend.