pthbs_genpkgpy

Template engine for producing packages for pthbs written using Python and Jinja
git clone https://ccx.te2000.cz/git/pthbs_genpkgpy
Log | Files | Refs | Submodules | README

commit d39c3eba3462f3de17632963857c16640a5b1808
parent c3ac8f2c03060c52c677f1ce8fb837a0f5404f99
Author: ccx <ccx@te2000.cz>
Date:   Wed,  6 Mar 2024 21:42:37 +0000

core-system-conf reworked

Diffstat:
Mcommand/pthbs-enter-gen | 34++++++++++++++++++++++++++++++++++
Mgenpkg.py | 9+++++++++
Mtemplates/pkg/core-system-conf | 52++++++++++++++++++++++++++++++++++++++++------------
3 files changed, 83 insertions(+), 12 deletions(-)

diff --git a/command/pthbs-enter-gen b/command/pthbs-enter-gen @@ -47,3 +47,37 @@ EOF chmod +x "$exe" "$exe" true # TODO: don't run executables without sandbox fi + +if test -x "$envcommand/install-as-current-environment.postinstall"; then + cat >"$exe" <<EOF +#!$envcommand/execlineb -P +"$envcommand/s6-envdir" "$envdir" "$envcommand/exec" +printf "%s\n" TODO +exit 100 +ifelse -n { test -L /run/current } { + if { ln -s -f -v "$envdir" } + "$envcommand/install-as-current-environment.postinstall" +} +foreground { + fdmove -c 1 2 + printf "* Swapping /run/current from %s to " "$envdir" + readlink /run/command +} +getpid NS_PID +importas -i NS_PID NS_PID +if { mv -v /run/current /run/previous.\${NS_PID} } +if { ln -s -f -v "$envdir" } +ifelse { + "$envcommand/install-as-current-environment.postinstall" /run/previous.\${NS_PID} +} { } +foreground { + fdmove -c 1 2 + printf "* %s returned error, reverting to " "$envcommand/install-as-current-environment.postinstall" + readlink /run/previous.\${NS_PID} +} +if { rm -v /run/current } +if { mv -v /run/previous.\${NS_PID} /run/current } +foreground { /run/command/install-as-current-environment.postinstall } +exit 1 +EOF + chmod +x "$exe" diff --git a/genpkg.py b/genpkg.py @@ -30,6 +30,15 @@ class SubmoduleInfo: os.symlink("../" + repo, str(self._by_commit / commit)) return self._current_commits + def commit_info(self, commit_id): + assert '/' not in commit_id + assert '.' not in commit_id + assert (self._by_commit / commit_id).exists() + out = subprocess.check_output( + ('git', 'show', '-s', '--pretty=format:%ai by %an'), + cwd=(self._by_commit / commit_id).as_posix(), + ).decode('utf8') + return out class DownloadsInfo: def __init__(self): diff --git a/templates/pkg/core-system-conf b/templates/pkg/core-system-conf @@ -5,21 +5,49 @@ #+{{pkg_install_name("gnu-make")}} #+{{pkg_install_name("aat")}} #+{{pkg_install_name("fileset")}} +#+{{pkg_install_name("rsync")}} #@git:{{submodule.current[name]}}:{{name}} -: ${JOBS:=1} -prefix={{versions}}/$pthbs_package -pkgdir="$pthbs_destdir/$prefix" -mkdir -p "$pkgdir/" -cp -av '{{name}}' "$pkgdir/" -# verify build -{{make}} -C '{{name}}' clean -{{make}} -C '{{name}}' all -rm -rf '{{name}}/build' -diff -ru '{{name}}/' "$pkgdir/{{name}}/" +{% include "functions/vars" %} +def_prefix +def_dest +linkdep() { + exe=$(realpath "$(which "$1")") + name=$(basename "$1") + if ! test -x "$exe"; then + printf 'Error: executable not found: %s\n' "$1" + fi + mkdir -p "$dest/deps/command" + ln -sf $exe "$dest/deps/command/$name" +} + +cd '{{name}}' +printf '%s\n' >config/etc/motd \ + "Welcome to $(<./config/hostname)!" + 'Current running configuration was generated from {{name}}:{{submodule.current[name]}}' \ + 'Last change on {{submodule.commit_info(submodule.current[name])}}' + +env 'pthbs_path_{{name}}'="$prefix" \ + 'pthbs_path_containers={{pkg_install_dir("containers.environment"}}' \ + {{make}} all + +sort -u build/execfile | while IFS= read exename; do + linkdep "$exename" +done + +mkdir "$dest/command" +awk <./postinstall >./install-as-current-environment.postinstall ' +/@@current@@/ { print "current=/run/current"; next } +/@@versions@@/ { print "versions='{{versions}}'"; next } +1 +' +pthbs-banginstall ./install-as-current-environment.postinstall "$dest/command" + +mkdir -p "$dest/config/" +rsync -aAi ./config/ "$dest/config/" +rsync -aAi ./out/ "$dest/config/" {% endblock -%} {% block rules %} -$2 == "static" { link(r1($0)); next } -$2 == "authorized_keys" { link($0); next } +$2 == "config" { link($0); next } {% endblock -%}