commit befd56d5545c18bc0e0d84ae5d5eb40927f7107c
parent f398dad31560bf659a92273804e26fa9f66b542f
Author: Jan Pobříslo <ccx@te2000.cz>
Date: Sat, 16 Dec 2023 23:07:00 +0100
core-system-init and scripts
Diffstat:
10 files changed, 376 insertions(+), 2 deletions(-)
diff --git a/.gitmodules b/.gitmodules
@@ -83,3 +83,9 @@
[submodule "sources/core-system-conf"]
path = sources/core-system-conf
url = /home/ccx/git/carbon-conf.git
+[submodule "sources/core-system-init"]
+ path = sources/core-system-init
+ url = /home/ccx/git/carbon-init.git
+[submodule "sources/core-system-scripts"]
+ path = sources/core-system-scripts
+ url = /home/ccx/git/carbon-scripts.git
diff --git a/packages/core-system-init b/packages/core-system-init
@@ -0,0 +1,160 @@
+#!/usr/bin/env pthbs-build
+#+*
+#+busybox.2148c04100bdf3af4de264efec32f63b4d2b836189cae739a75035e9ec4ceff1
+#+s6.5842cf13ac273f44789effa073be8856e140c0c1c8e881e56b0953d8c3f9bfde
+#+s6-rc.d9477400ee9be61bbd377c180fc7cdc6a23ebad752775622078a8000f3485214
+#+s6-portable-utils.74e1284710969971e975e52a4a18c628df2c12db025139d5707e1a0af27dab64
+#+s6-linux-init.ae12bfa48868d8e6ebf8066df04a4d51751a879322992a6883586c4580c6a0d6
+#+execline.212907020e985bcf7a850b25114d7d264ae725bea35d0d631d58e1e5801eeefc
+#+core-system-rc.3ae386addf824444a7c470e615ec72fd61effa62221c6897eb4cbdb1c26700b5
+
+s6rcdb=/home/ccx/versions/core-system-rc.3ae386addf824444a7c470e615ec72fd61effa62221c6897eb4cbdb1c26700b5/s6-rc-db
+prefix=/home/ccx/versions/$pthbs_package
+pkgdir="$pthbs_destdir/$prefix"
+
+q() {
+ "s6-quote" "$@"
+}
+
+qx() {
+ exe=$(realpath "$(which "$1")")
+ name=$(basename "$1")
+ if ! test -x "$exe"; then
+ printf 'Error: executable not found: %s\n' "$1"
+ fi
+ mkdir -p "$pkgdir/deps/command"
+ ln -sf $exe "$pkgdir/deps/command/$name"
+ "s6-quote" "$prefix/deps/command/$name"
+}
+
+# Generate init ($pkgdir must not exist but parent dir does)
+mkdir -p "$pthbs_destdir//home/ccx/versions"
+s6-linux-init-maker \
+ -p "/command:/usr/local/bzr/all/sbin:/usr/local/bzr/all/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
+ -G "$(q "prefix/deps/command/env") TERM=linux $(q "prefix/deps/command/getty") 38400 tty9" \
+ -t 1 \
+ -c "$pkgdir" \
+ "$pkgdir"
+
+
+# Link deps that are passed to s6-l-i-m
+qx env
+qx getty
+
+# Link execlineb - can't quote shebang
+qx execlineb
+el=$prefix/deps/command/$name
+
+# Rewrite dynamically generated scripts
+s6-cat >"$pkgdir/scripts/rc.init" <<EOF || exit $?
+#!$el -S1
+$(qx export) TERM "linux"
+$(qx foreground) { $(qx s6-echo) "* Starting s6-rc from "$(q "$s6rcdb") }
+$(qx if) { $(qx s6-rc-init) -d -c $(q "$s6rcdb") /run/service }
+$prefix/scripts/runlevel \$1
+EOF
+
+s6-cat >"$pkgdir/scripts/rc.shutdown" <<EOF || exit $?
+#!$el -P
+
+### Things to do before hardware halt/reboot/poweroff.
+### Ideally, it should be a single call to the service manager,
+### telling it to bring all the services down.
+
+$(qx redirfd) -w 1 /dev/console
+$(qx redirfd) -w 2 /dev/console
+$(qx s6-rc) -v2 -bDa change
+EOF
+
+s6-cat >"$pkgdir/scripts/runlevel" <<EOF || exit $?
+#!$el -S1
+export TERM "linux"
+
+# The requested runlevel is in "\$1" but currently ignored.
+
+# Run the service manager.
+# Call it twice because the first time may spuriously "timeout"
+# due to the clock jumping forward.
+
+$(qx ifelse) -X {
+ $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty
+} {
+ # no timeout, start ttys properly
+ $(qx foreground) { $(qx s6-echo) "* System started normally (bundle ok-all-but-tty)" }
+ $(qx foreground) { sleep 0.3 }
+ $(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
+ $(qx s6-rc) -v 2 -t 600000 -- change ok-all
+}
+$(qx s6-echo) "* System startup failure: retry"
+# try again without tty and then with
+$(qx foreground) { $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty }
+$(qx foreground) { $(qx sleep) 0.1 }
+$(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
+$(qx s6-rc) -v 2 -t 600000 -- change ok-all
+EOF
+
+s6-mkdir "$pkgdir/run-image/service/console-log-tail" || exit $?
+s6-cat >"$pkgdir/run-image/service/console-log-tail/run" <<EOF || exit $?
+#!$el -P
+$(qx redirfd) -w 1 /dev/console
+$(qx fdmove) -c 2 1
+$(qx pipeline) -w { $(qx s6-tai64nlocal) }
+$(qx tail) -F -n +1 /run/uncaught-logs/current
+EOF
+s6-chmod 755 "$pkgdir/run-image/service/console-log-tail/run" exit $?
+
+
+cd "$pthbs_destdir/home/ccx/versions/$pthbs_package"
+find -type d -o -print | awk -F/ '
+BEGIN {
+ x["./bin/init"]=1
+ x["./bin/halt"]=1
+ x["./bin/poweroff"]=1
+ x["./bin/reboot"]=1}
+
+function r1(s) {
+ sub("^[.]/[^/]*", ".", s)
+ return s
+}
+function s1(repl, s) {
+ sub("^[.]/[^/]*", "./"repl, s)
+ return s
+}
+function link(src) {
+ x[$0]=0
+ printf "%s\t%s\n", $0, src
+ printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
+}
+$1!="."{exit 1}
+
+
+$2 == "command" { link($0); next }
+$2 == "bin" { link(s1("command", $0)); next }
+
+$2 == "library.so" { link($0); next }
+$2 == "library" { link($0); next }
+$2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
+$2 == "lib" && $NF ~ /\.so(|\..*)$/ { link(s1("library.so", $0)); next }
+
+$2 == "share" && $3 ~ /^(info|man|doc|icons|terminfo)$/ { link(r1($0)); next }
+
+$2 == "man" { link($0); next }
+$2 == "info" { link($0); next }
+$2 == "doc" { link($0); next }
+$2 == "icons" { link($0); next }
+$2 == "terminfo" { link($0); next }
+
+$2 == "include" { link($0); next }
+
+{ printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
+
+END {
+ for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
+ for(fname in x) {
+ if(x[fname]) {
+ printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
+ exit 3
+ }
+ }
+}' >.install-links.new
+mv .install-links.new .install-links
diff --git a/packages/core-system-scripts b/packages/core-system-scripts
@@ -0,0 +1,82 @@
+#!/usr/bin/env pthbs-build
+#+*
+#+busybox.2148c04100bdf3af4de264efec32f63b4d2b836189cae739a75035e9ec4ceff1
+#+zsh.ab347c2bf33345f5c8ccc911490305d65cb5d3fb86d29ab374e218a93fc6e268
+#+pthbs-banginstall.4acc05826812a65baca1dea7ce467bdbe33570c70e35a3ead46c43d24ae089ed
+#@git:98fabf6dffa7a3a7850f1797f557e181b7e8460f:core-system-scripts
+
+: ${JOBS:=1}
+prefix=/home/ccx/versions/$pthbs_package
+pkgdir="$pthbs_destdir/$prefix"
+mkdir -p "$pkgdir/"
+cd 'core-system-scripts'
+
+for d in bin sbin command; do
+ if test -d "$d"; then
+ pthbs-banginstall "$d"/* "$pkgdir"
+ fi
+done
+
+if test -d vim; then
+ mkdir -p "$pkgdir/vimfiles/pack/plugins/start"
+ mv -v vim "$pkgdir/vimfiles/pack/plugins/start/$pthbs_package"
+fi
+
+if test -d zsh-functions; then
+ mv -v zsh-functions "$pkgdir/"
+fi
+
+cd "$pthbs_destdir/home/ccx/versions/$pthbs_package"
+find -type d -o -print | awk -F/ '
+BEGIN {
+ x["./command/s"]=1
+ x["./command/issue-gen"]=1}
+
+function r1(s) {
+ sub("^[.]/[^/]*", ".", s)
+ return s
+}
+function s1(repl, s) {
+ sub("^[.]/[^/]*", "./"repl, s)
+ return s
+}
+function link(src) {
+ x[$0]=0
+ printf "%s\t%s\n", $0, src
+ printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
+}
+$1!="."{exit 1}
+
+
+$2 == "zsh-scripts" { link($0); next }
+$2 == "vimfiles" { link($0); next }
+$2 == "command" { link($0); next }
+$2 == "bin" { link(s1("command", $0)); next }
+
+$2 == "library.so" { link($0); next }
+$2 == "library" { link($0); next }
+$2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
+$2 == "lib" && $NF ~ /\.so(|\..*)$/ { link(s1("library.so", $0)); next }
+
+$2 == "share" && $3 ~ /^(info|man|doc|icons|terminfo)$/ { link(r1($0)); next }
+
+$2 == "man" { link($0); next }
+$2 == "info" { link($0); next }
+$2 == "doc" { link($0); next }
+$2 == "icons" { link($0); next }
+$2 == "terminfo" { link($0); next }
+
+$2 == "include" { link($0); next }
+
+{ printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
+
+END {
+ for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
+ for(fname in x) {
+ if(x[fname]) {
+ printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
+ exit 3
+ }
+ }
+}' >.install-links.new
+mv .install-links.new .install-links
diff --git a/packages/default.environment b/packages/default.environment
@@ -25,4 +25,6 @@
#+snaprep.1ed06cea3dda8aca11d7d3ec83742e10eabc2836633213b39806eafaa6ef078a
#+core-system-conf.47c9e8c97fd233c043f9b63abc8e0a915be08cb4ac26dd8d64e917f4e040cfb3
#+core-system-rc.3ae386addf824444a7c470e615ec72fd61effa62221c6897eb4cbdb1c26700b5
+#+core-system-scripts.3ee976e69ffcf28b2be06f881b98406c9c01ff56fde5ffad512e2e2f9e6f544b
+#+core-system-init.8303b54302da0040c8b14dbb051b28087ba71c4169a816b48e1e8695a485f984
#+linux.6f1590762b7d76ff71297f21c313b58800c8d8b4cd18f013d3a275e75b41c2dd
\ No newline at end of file
diff --git a/packages/userspace.environment b/packages/userspace.environment
@@ -24,4 +24,6 @@
#+logincaps.d1cbcbb8c5bca5c69e85fbe821229189ded7b9eb29d83e6c4fc6b9c6196826bc
#+snaprep.1ed06cea3dda8aca11d7d3ec83742e10eabc2836633213b39806eafaa6ef078a
#+core-system-conf.47c9e8c97fd233c043f9b63abc8e0a915be08cb4ac26dd8d64e917f4e040cfb3
-#+core-system-rc.3ae386addf824444a7c470e615ec72fd61effa62221c6897eb4cbdb1c26700b5-
\ No newline at end of file
+#+core-system-rc.3ae386addf824444a7c470e615ec72fd61effa62221c6897eb4cbdb1c26700b5
+#+core-system-scripts.3ee976e69ffcf28b2be06f881b98406c9c01ff56fde5ffad512e2e2f9e6f544b
+#+core-system-init.8303b54302da0040c8b14dbb051b28087ba71c4169a816b48e1e8695a485f984+
\ No newline at end of file
diff --git a/sources/core-system-init b/sources/core-system-init
@@ -0,0 +1 @@
+Subproject commit e1bc62ec78acc46e723b0fb86d81f2ce69f4c0c5
diff --git a/sources/core-system-scripts b/sources/core-system-scripts
@@ -0,0 +1 @@
+Subproject commit 98fabf6dffa7a3a7850f1797f557e181b7e8460f
diff --git a/templates/pkg/core-system-init b/templates/pkg/core-system-init
@@ -0,0 +1,113 @@
+{% extends "genlinks" %}
+{%- block script %}
+#+*
+#+{{pkg_install_name("busybox")}}
+#+{{pkg_install_name("s6")}}
+#+{{pkg_install_name("s6-rc")}}
+#+{{pkg_install_name("s6-portable-utils")}}
+#+{{pkg_install_name("s6-linux-init")}}
+#+{{pkg_install_name("execline")}}
+#+{{pkg_install_name("core-system-rc")}}
+
+s6rcdb={{pkg_install_dir("core-system-rc")}}/s6-rc-db
+prefix={{versions}}/$pthbs_package
+pkgdir="$pthbs_destdir/$prefix"
+
+q() {
+ "s6-quote" "$@"
+}
+
+qx() {
+ exe=$(realpath "$(which "$1")")
+ name=$(basename "$1")
+ if ! test -x "$exe"; then
+ printf 'Error: executable not found: %s\n' "$1"
+ fi
+ mkdir -p "$pkgdir/deps/command"
+ ln -sf $exe "$pkgdir/deps/command/$name"
+ "s6-quote" "$prefix/deps/command/$name"
+}
+
+# Generate init ($pkgdir must not exist but parent dir does)
+mkdir -p "$pthbs_destdir/{{versions}}"
+s6-linux-init-maker \
+ -p "/command:/usr/local/bzr/all/sbin:/usr/local/bzr/all/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
+ -G "$(q "prefix/deps/command/env") TERM=linux $(q "prefix/deps/command/getty") 38400 tty9" \
+ -t 1 \
+ -c "$pkgdir" \
+ "$pkgdir"
+
+
+# Link deps that are passed to s6-l-i-m
+qx env
+qx getty
+
+# Link execlineb - can't quote shebang
+qx execlineb
+el=$prefix/deps/command/$name
+
+# Rewrite dynamically generated scripts
+s6-cat >"$pkgdir/scripts/rc.init" <<EOF || exit $?
+#!$el -S1
+$(qx export) TERM "linux"
+$(qx foreground) { $(qx s6-echo) "* Starting s6-rc from "$(q "$s6rcdb") }
+$(qx if) { $(qx s6-rc-init) -d -c $(q "$s6rcdb") /run/service }
+$prefix/scripts/runlevel \$1
+EOF
+
+s6-cat >"$pkgdir/scripts/rc.shutdown" <<EOF || exit $?
+#!$el -P
+
+### Things to do before hardware halt/reboot/poweroff.
+### Ideally, it should be a single call to the service manager,
+### telling it to bring all the services down.
+
+$(qx redirfd) -w 1 /dev/console
+$(qx redirfd) -w 2 /dev/console
+$(qx s6-rc) -v2 -bDa change
+EOF
+
+s6-cat >"$pkgdir/scripts/runlevel" <<EOF || exit $?
+#!$el -S1
+export TERM "linux"
+
+# The requested runlevel is in "\$1" but currently ignored.
+
+# Run the service manager.
+# Call it twice because the first time may spuriously "timeout"
+# due to the clock jumping forward.
+
+$(qx ifelse) -X {
+ $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty
+} {
+ # no timeout, start ttys properly
+ $(qx foreground) { $(qx s6-echo) "* System started normally (bundle ok-all-but-tty)" }
+ $(qx foreground) { sleep 0.3 }
+ $(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
+ $(qx s6-rc) -v 2 -t 600000 -- change ok-all
+}
+$(qx s6-echo) "* System startup failure: retry"
+# try again without tty and then with
+$(qx foreground) { $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty }
+$(qx foreground) { $(qx sleep) 0.1 }
+$(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
+$(qx s6-rc) -v 2 -t 600000 -- change ok-all
+EOF
+
+s6-mkdir "$pkgdir/run-image/service/console-log-tail" || exit $?
+s6-cat >"$pkgdir/run-image/service/console-log-tail/run" <<EOF || exit $?
+#!$el -P
+$(qx redirfd) -w 1 /dev/console
+$(qx fdmove) -c 2 1
+$(qx pipeline) -w { $(qx s6-tai64nlocal) }
+$(qx tail) -F -n +1 /run/uncaught-logs/current
+EOF
+s6-chmod 755 "$pkgdir/run-image/service/console-log-tail/run" exit $?
+
+{% endblock -%}
+{% block genlinks_begin %}
+ x["./bin/init"]=1
+ x["./bin/halt"]=1
+ x["./bin/poweroff"]=1
+ x["./bin/reboot"]=1
+{%- endblock %}
diff --git a/templates/pkg/core-system-scripts b/templates/pkg/core-system-scripts
@@ -0,0 +1,5 @@
+{% extends "scriptsetup" %}
+{% block genlinks_begin %}
+ x["./command/s"]=1
+ x["./command/issue-gen"]=1
+{%- endblock %}
diff --git a/templates/pkg/userspace.environment b/templates/pkg/userspace.environment
@@ -25,3 +25,5 @@
#+{{pkg_install_name("snaprep")}}
#+{{pkg_install_name("core-system-conf")}}
#+{{pkg_install_name("core-system-rc")}}
+#+{{pkg_install_name("core-system-scripts")}}
+#+{{pkg_install_name("core-system-init")}}