From 8684f17cd5d3a27c6c7180bb309b5db00befe957 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Tue, 12 May 2026 11:37:51 +0200 Subject: translate: add English translation of "Slackware Templates for Packages" --- .../slackware-templates-for-packages/index.md | 193 +++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 content/en/articles/slackware-templates-for-packages/index.md (limited to 'content/en') diff --git a/content/en/articles/slackware-templates-for-packages/index.md b/content/en/articles/slackware-templates-for-packages/index.md new file mode 100644 index 0000000..04c001a --- /dev/null +++ b/content/en/articles/slackware-templates-for-packages/index.md @@ -0,0 +1,193 @@ ++++ +title = "Slackware Templates for Packages" + +author = "Danilo M." +type = "tech" +date = "2026-05-11T18:51:37+02:00" +draft = true +excerpt = "slackpkg and dependency management in Slackware." + +image = "" +tags = ["linux", "howto", "do it yourself"] +categories = ["Code", "DIY"] + ++++ +Slackware is great for system management because it allows you to easily modify anything by simply changing a value in a text file. + +Slackware is a little less great when you need to install a package for software that has several dependencies :sweat:. It doesn't have automatic dependency management by default, so all the work falls on the user who manages the system. + +The same applies to package compilation; since it doesn't manage dependencies, you also have to do everything manually during compilation, compiling the packages in the correct order to get the software you want to install. + +## SlackRepo + +To solve this last problem, there are software programs like [sbopkg](https://www.sbopkg.org/) that allow you to generate compilation queues to compile the packages needed for the software in the correct order. + +One step further than sbopkg is **slackrepo**, software that I have already talked about in my [articolo sulla gestione dei pacchetti nel 2026](../manage-slackware-packages-2026/), as it also allows you to compile the packages in the correct order with respect to the dependencies of each individual program, but in addition, it installs the already compiled dependencies one by one and then removes them once the compilation of the software that required them is finished. + +The most interesting feature of slackrepo, however, is the ability to queue "hooks" to the execution of the program, i.e., to execute code that is not part of slackrepo to extend its functionality. In particular, in my setup, I use several hooks: + +- I update the repository via git by performing the rebase each time. +- I generate the HTML files that are then inserted into the [repository](https://packages.danix.xyz/). +- I generate the .template files for those software programs that have one or more dependencies. +- I upload the files to the repository using rsync. + +{{< actions url="https://packages.danix.xyz" desc="I miei pacchetti" use="site" caption="Il mio repository di pacchetti per slackware64-current" >}} + +### hook "git fetch" + +This hook takes care of updating the local repository by cloning Ponce's git (it's on *-current*), then it performs the rebase and stops the execution if there are any conflicts, so I know if any of my personal packages conflict with SBo's. In case of conflicts, I can resolve them by deleting my package or the official one, depending on the situation. + +```bash +function danix_gitfetch_hook +{ + local upstream_branch='current' + local personal_branch='danix-current' + + cd "$SR_SBREPO" || return 1 + + local currbranch + currbranch=$(git rev-parse --abbrev-ref HEAD) + if [ "$currbranch" != "$personal_branch" ]; then + echo "slackrepo: WARNING: SBREPO is on branch '$currbranch', expected '$personal_branch'. Skipping git update." + return 0 + fi + + local muck + muck=$(git status -s .) + if [ -n "$muck" ]; then + echo "slackrepo: WARNING: SBREPO has uncommitted changes. Skipping git update." + return 0 + fi + + echo "slackrepo: Fetching upstream SBo..." + git fetch origin || { echo "slackrepo: WARNING: git fetch failed."; return 1; } + + echo "slackrepo: Rebasing $personal_branch onto origin/$upstream_branch..." + git rebase --rebase-merges -X theirs origin/"$upstream_branch" || { + echo "slackrepo: ERROR: rebase failed. Resolve conflicts in $SR_SBREPO and run 'git rebase --continue'." + return 1 + } + + return 0 +} +``` + +### hook "gen web files" + +This hook takes care of launching my script `gen_web_hook.sh` (visible on [mio git](https://git.danix.xyz/pkgs-html-structure/tree/gen_web_hook.sh)) to generate the HTML files that will then be uploaded online to the package repository and that are used for viewing the repository online. + +```bash +function gen_web_hook +{ + if [ "$OPT_DRY_RUN" = 'y' ] || [ ! -s "$CHANGELOG" ]; then + return 0 + fi + SR_PKGREPO="$SR_PKGREPO" /usr/local/bin/gen_web_hook.sh + local stat=$? + [ $stat -ne 0 ] && log_warning "gen_web_hook failed, status $stat" + return $stat +} +``` + +{{< actions url="https://git.danix.xyz" desc="Il mio repository git" use="repo" caption="Dai un'occhiata al mio codice sul repo git." >}} + +### hook "template generator" + +Here is the function that takes care of generating the .template files used by slackpkg to install the packages. + +```bash +function dep_template_hook +{ + local template_dir="${TEMPLATE_DIR:-/repo/templates}" + + [ "$OPT_DRY_RUN" = 'y' ] && return 0 + [ ${#OKLIST[@]} -eq 0 ] && return 0 + + mkdir -p "$template_dir" || return 1 + + local itemid prgnam dep depname outfile + for itemid in "${OKLIST[@]}"; do + [ -z "${FULLDEPS[$itemid]}" ] && continue + + prgnam="${ITEMPRGNAM[$itemid]}" + outfile="$template_dir/${prgnam}.template" + + { + for dep in ${FULLDEPS[$itemid]}; do + depname="${ITEMPRGNAM[$dep]}" + printf '%s\n' "${depname:-$dep}" + done + printf '%s\n' "$prgnam" + } > "$outfile" + + log_normal "dep_template_hook: wrote $outfile" + done + + return 0 +} +``` + +### hook "rsync push" + +Finally, the hook that takes care of uploading the modified files to my online repository: + +```bash +function rsync_push_hook +{ + # RSYNC_TARGET/RSYNC_EXCLUDES are unset by slackrepo after config sourcing; + # use hardcoded values here since they can't be passed via SR_ prefix mechanism. + local rsync_target='' + local rsync_excludes='' + local rsync_password_file='' + + if [ "$OPT_DRY_RUN" = 'y' ] || [ ! -s "$CHANGELOG" ]; then + return 0 + fi + + local rsync_bin + rsync_bin=$(which rsync 2>/dev/null) + if [ ! -x "$rsync_bin" ]; then + log_warning "rsync not found, skipping rsync_push_hook" + return 1 + fi + + local args=( -havz --delete-after ) + [ -n "$rsync_excludes" ] && [ -f "$rsync_excludes" ] && \ + args+=( --exclude-from="$rsync_excludes" ) + [ -f "$rsync_password_file" ] && args+=( --password-file="$rsync_password_file" ) + + log_normal "Pushing packages to $rsync_target ..." + "$rsync_bin" "${args[@]}" "$SR_PKGREPO"/ "$rsync_target" + local rsyncstat=$? + if [ "$rsyncstat" != 0 ]; then + log_warning "rsync_push_hook failed, status $rsyncstat" + return 1 + fi + log_normal "rsync push complete." + return 0 +} +``` + +## The .template files and slackpkg + +At the end of the compilation of software that has some dependencies, in my repository, the file `.template` will be generated, which I can copy into `/etc/slackpkg/templates` and call with: + +```bash +slackpkg install-template nome_pacchetto +``` + +and slackpkg will automatically prompt me to install all the dependencies listed in the template, effectively simplifying dependency management. + +An example of a template, directly from my repository, is [waybar.template](https://packages.danix.xyz/templates/waybar.template): + +``` +date +jsoncpp +Catch2 +spdlog +waybar +``` + +I hope this article can be useful to someone, even if only as a starting point to simplify things a bit :wink: + +{{< actions url="/it/is/here/" desc="Scrivimi" use="site" caption="Se hai dei commenti, lasciami pure un messaggio" >}} \ No newline at end of file -- cgit v1.2.3