I've tried some packaging tools / builder on some distros (debian and its based, archlinux, alpine, slackware, crux and dragora). I want to write my own package builder using bash and stow as its manager. It's inspired by slackbuild and qi recipe but I really want to make it really understandable.
Basically the build script contains 2 parts :
- Variables.
- Build function (it gets called at the bottom).
The variables consist of :
- Package name (e.g pkg=package).
- Package version.
- Package description.
- Package homepage / URL.
- Package category.
We can make an example like this :
pkg=package-test
version=0
release=0
desc="Test / dummy package"
url="none"
category=data
Build function consists of some commands / actions. It depends on how you build your package. Build function are ended by creating package archive and deleting package directory once the package archive is created. We can make an example like :
build() {
# create package directory / destination.
destdir="${pkg}_${version}-${release}@${category}"
mkdir $destdir
# create particular directory for package (e.g /etc/test).
mkdir -p $destdir/etc/test
mkdir -p $destdir/var/lib/build
# copy files to our package directory.
cp -r test.txt $destdir/etc/test
cp -r $pkg.build $destdir/var/lib/build/${pkg}_${version}-${release}@${category}.build
# create our package archive.
echo "creating package archive."
tar -czvf ${pkg}_${version}-${release}@${category}.tar.gz $destdir
# cleanup the destdir directory
echo "cleanup the destdir directory"
rm -rf $destdir
}
# let's run our build function
build
Because the build script is bash script, we can just run it on terminal like :
$ ./our_package_build.build
We can make an installer script like this (let's call it as spi) :
#!/bin/bash
install_package() {
package_dir=$(basename $1 | cut -d "." -f-1)
echo "extracting package archive to /usr/local/stow ...."
tar -xvf $1 -C /usr/local/stow
echo "stowing directory to root directory"
pushd /usr/local/stow/
stow -t / $package_dir
popd
}
install_package $1
Basically the script does :
- extracting the archive to /usr/local/stow.
- stowing the package directory to root as target.
The usage is pretty simple, just run it like :
$ sudo ./spi package_archive.tar.gz