Created
September 14, 2025 23:38
-
-
Save lidgnulinux/44d8d33848801e41839e8f1f29fe34d7 to your computer and use it in GitHub Desktop.
Revisions
-
lidgnulinux created this gist
Sep 14, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,112 @@ # Simple package builder and installer. ## Why ? 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. ## Basic Basically the build script contains 2 parts : - Variables. - Build function (it gets called at the bottom). ### Variables 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 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 ``` ## How to build the package using the build script ? Because the build script is bash script, we can just run it on terminal like : ``` $ ./our_package_build.build ``` ## How to install the package archive ? 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. ### usage The usage is pretty simple, just run it like : ``` $ sudo ./spi package_archive.tar.gz ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ #!/bin/bash set -e pkg=package-test version=0 release=0 desc="Test / dummy package" url="none" category=data # let's make a function to build our package. 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 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ #!/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