mrrl

Minimal Reliable Reproducible Linux
git clone https://ccx.te2000.cz/git/mrrl
Log | Files | Refs | Submodules | README

system-config-init (9574B)


      1 #!/usr/bin/env pthbs-build
      2 #+busybox.7f0e4d86f69de7624b0468018b9933c3e3c1757c8ff73938746c292196f916dd
      3 #+busybox-bzip2.52d2053dff44277d3c6f700eec6807d2c64c226e0f1bf589372ff5ff625be40e
      4 #+busybox-gzip.085fc42ce36be284c89a9dec6889cca59dedd07b9ba93a21d3198c4adcac5840
      5 #+busybox-lzop.bccd8f86de85a74d466d34f802ab1ea355f0a9d9886bdfa4d7bb4a785d695be6
      6 #+busybox-unzip.237a4ec36283b7fbdb85df583c7c77c0aaf70d335b1cbae09a40a9bb4b6c82bb
      7 #+busybox-xz.db25ed2ffbfc91e7b5cff54faf2e80de59ab5b15167c2c5bb338fa1ee62de122
      8 #+busybox-cpio.307e9495bcd9b79fd9559882115d55d22c5b687e08886e696f1e53d8db7eebcd
      9 #+busybox-dpkg.3aec8347093bb5b774a0c25795cdf9e624268a3b04cc48e867d74e4e06461db7
     10 #+busybox-rpm.8435251ea7058aea0cbcd41478b144b1a15c5aa121509af887847c0ef45bf5aa
     11 #+busybox-tar.c77139157bce13db8820740b756572c22e29cfbd8bb8c2a3b22b465b70e2eae9
     12 #+busybox-ed.4ac872215d7b9c8096c4cfd508434fbd2e825aebd9a9ea8589a0033b8e50aac2
     13 #+busybox-sed.14269a860b3706f7122b827818365fecaa0e62ce5bc3273e89948685c0953f2d
     14 #+busybox-vi.7e41b306c9c47aaaa281aa8347b9fa6dca260788fd73f53a7ba9260b315627ee
     15 #+busybox-xxd.9df3407fd75b89cb640d65870298eaba77327d6e387d25d8ce1ebab01cb47857
     16 #+busybox-process-extra.65afeaded3cb8fdeea327262f28f08e50f18d51a2b456ea97b293d200c7f558e
     17 #+busybox-procps.e5dc609521d29d8aec8253147269314439131c088a6beeacc172fc07594c4a37
     18 #+busybox-psmisc.7d760b69f45bb1b8d458f2f408b9cb3a42e919e8022f0508c440a5fd20ebb66f
     19 #+busybox-ash.fd5d266905d40248735e0e2e1ae22165b6f0d42c0bacb652660f69f39c1ee71e
     20 #+busybox-bc.6f2fe17efab2237c3036eba1c37d432d696d1b5dba130e21365016ceae0a3184
     21 #+busybox-coreutils.7e581faa6901f832a2a022d72b2858c3091f47afc80a4a463adb2f2a68f1843d
     22 #+busybox-coreutils-extra.5ab183b839676b0780a9a83d75cc345a06221fa34627c44aa3732c4a5a47f9b9
     23 #+busybox-daemontools.bcea69c867a61fe1d49d2f6a27e406959c484ed20d54fd7c0341828d3cdbd428
     24 #+busybox-grep.ac20e6a4295eb7fb0a09d700e10e5fe55e2009d2858e0a1525e461d4914e820b
     25 #+busybox-misc.7f0588b97809fac8061c489b686424de1a7dd17d8eb3431aae56513c7288f1e7
     26 #+busybox-sh.288f0583edc783a176bbbc59a3e854b186258ba2605291377a545cc3191c3d52
     27 #+busybox-util-linux-unpriv.5a286246aa7204f7fa8c9a247f1c93c751979690a65200030f29e255645c1eae
     28 #+busybox-findutils.207f73a9f41a8f9e279072e920cbf0c38ba6516734fa3cf2c1faf55565613487
     29 #+nawk.84c186be0a6d09a951a8c6a5377d16b0ba0a9e476e6b554c0c832d6407ebb5b2
     30 #+busybox-dosfstools.b37683efd8b4a72e54d6c44a0c50119969fc5331bf8c221e95278599981783cd
     31 #+busybox-e2fsprogs.97b040545ab4209283aac65aa362041e4d4e74cd11e5c5e3ad1a35baed1aee04
     32 #+busybox-iproute2.2d9ca6b8a14c23200905e2a52dd50cc5e9c1fc1fef9324bfacbaaa6b6d6ff4c5
     33 #+busybox-iputils.09996cd8ce0c7b00f4351a5f37745ffdea5d6a871bb3b5a028b8c391f5cd4c1a
     34 #+busybox-net-misc.b189cea6d06bb88205a90bb359683d92c0f0e5e9d46d3ae0f9c0f3396eb7bbf7
     35 #+busybox-net-tools.0fd5dabc9430492bc29368e7e49ed47832659b9d4050657d10696fcb09f77de2
     36 #+busybox-traceroute.eca457a6db7d2b6c4cdb73d5646a179d43dff829a639697830fb5f853bde7dfe
     37 #+busybox-wget.358809effbe6ae614f474a7017e69853b7d6e9a1580d39a38dd69b6d05bb0975
     38 #+busybox-chpst.a9512afcfaa21f42980402ce2b6680bb99ad81b1f7c61094989fcb1536519c0d
     39 #+busybox-console.fbd958c51fc7d0f4cd54d3fabc201a25a1de39c997462044140bc20ebb99486d
     40 #+busybox-getty.700f4cb7326d9bf82d7d7997199407b882bd621a81afb0c87faf93d2920dc753
     41 #+busybox-linux-extra.46da1347e8a30f6c1594965c38db5f696941c3b91c3f330d4f55dd2c1b3ab358
     42 #+busybox-mtd-utils.7429f56c67b00231a66d877d908f422caf19093fc4d9b24650f7ca2a095d8a7d
     43 #+busybox-shadow.39e6b8449d43b09bde9cfd431b08b1a7cb726699194db6921b4c17a3234b3f6b
     44 #+busybox-su.499b81dc79366bb990e8019aca341b8e71d0bc6b5a38062234008313401ec502
     45 #+busybox-util-linux-priv.83cec28c6e04ad9a7ec5c32a38ec38885c3e8abdb399122820a44c956d52edda
     46 #+busybox-logging.3b0dc10d3df1d292038f7a739f91b96749ede1ac11b26e8e256eb033845ab027
     47 #+busybox-cron.1623c4a03b1450cadf4f0e5df5d71f0a0120af068e6bfbb5fe7efb122108a9af
     48 #+s6.64db7103e34ea2b2dd5d657ebf1a62bea89d31b2a5df8cd6ef0c140ef574828f
     49 #+s6-rc.e09e2d9c42a1bbc18b406ff114d945db0d3187fd09b703ddd7c28a4d64357ad3
     50 #+s6-portable-utils.215fcbacf399929de5124e7f2b5d6ca4549007ccd2319a874170887bedca9a08
     51 #+s6-linux-init.de74cb1d43a63d9c9e4e2a44ee5a7f9a50deab7776bd2b2bd0c3d67cb44f01c3
     52 #+execline.4e773f1ba308227aa5402fd63038f6dcbaf3866ca3fa70555a8bec9b81c8e2d2
     53 #+system-config-rc.b4fa2835cb24cd49c16b1ff2766213f2d0a02bccbc1286df15e24951dd44c85f
     54 
     55 
     56 # - build script start -
     57 
     58 q() {  # quote list of strings to be suitable for execline
     59 	"s6-quote" "$@"
     60 }
     61 
     62 qx() {  # register executable as dependency and quote full path to be suitable for execline
     63 	exe=$(realpath "$(which "$1")")
     64 	name=$(basename "$1")
     65 	if ! test -x "$exe"; then
     66 		printf 'Error: executable not found: %s\n' "$1"
     67 	fi
     68 	mkdir -p "${dest}/deps/command"
     69 	ln -sf $exe "${dest}/deps/command/$name"
     70 	"s6-quote" "$prefix/deps/command/$name"
     71 }
     72 
     73 prefix=/versions/$pthbs_package
     74 dest=${pthbs_destdir%/}${prefix}
     75 cd '.'
     76 
     77 
     78 s6rcdb=/versions/system-config-rc.b4fa2835cb24cd49c16b1ff2766213f2d0a02bccbc1286df15e24951dd44c85f/config/s6-rc-db
     79 
     80 # Generate init (${dest} must not exist but parent dir does)
     81 mkdir -p "$pthbs_destdir//versions"
     82 s6-linux-init-maker \
     83 	-p "/run/current/command:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
     84 	-G "$(q "$prefix/deps/command/env") TERM=linux $(q "$prefix/deps/command/getty") 38400 tty9" \
     85 	-t 1 \
     86 	-N \
     87 	-c "$prefix" \
     88 	"${dest}"
     89 
     90 
     91 # Link deps that are passed to s6-l-i-m
     92 qx env
     93 qx getty
     94 
     95 # Link execlineb - can't quote shebang
     96 qx execlineb
     97 el=$prefix/deps/command/$name
     98 
     99 # Rewrite bin/init as it fails finding it's own s6-linux-init
    100 s6-cat >"${dest}/bin/init.new" <<EOF || exit $?
    101 #!$el -S0
    102 $(qx pthbs-enter)
    103 $(qx s6-envdir) -I /run/current/env
    104 EOF
    105 s6-cat >>"${dest}/bin/init.new" <"${dest}/bin/init"
    106 chmod +x "${dest}/bin/init.new"
    107 mv -v "${dest}/bin/init.new" "${dest}/bin/init"
    108 
    109 # Rewrite dynamically generated scripts
    110 s6-cat >"${dest}/scripts/rc.init" <<EOF || exit $?
    111 #!$el -S1
    112 $(qx export) TERM "linux"
    113 $(qx foreground) { $(qx s6-echo) "* Starting s6-rc from "$(q "$s6rcdb") }
    114 $(qx if) { $(qx s6-rc-init) -d -c $(q "$s6rcdb") /run/service }
    115 $prefix/scripts/runlevel \$1
    116 EOF
    117 
    118 s6-cat >"${dest}/scripts/rc.shutdown" <<EOF || exit $?
    119 #!$el -P
    120 
    121 ### Things to do before hardware halt/reboot/poweroff.
    122 ### Ideally, it should be a single call to the service manager,
    123 ### telling it to bring all the services down.
    124 
    125 $(qx redirfd) -w 1 /dev/console
    126 $(qx redirfd) -w 2 /dev/console
    127 $(qx s6-rc) -v2 -bDa change
    128 EOF
    129 
    130 s6-cat >"${dest}/scripts/runlevel" <<EOF || exit $?
    131 #!$el -S1
    132 export TERM "linux"
    133 
    134 # The requested runlevel is in "\$1" but currently ignored.
    135 
    136 # Run the service manager.
    137 # Call it twice because the first time may spuriously "timeout"
    138 # due to the clock jumping forward.
    139 
    140 $(qx ifelse) -X {
    141 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty 
    142 } {
    143 	# no timeout, start ttys properly
    144 	$(qx foreground) { $(qx s6-echo) "* System started normally (bundle ok-all-but-tty)" }
    145 	$(qx foreground) { sleep 0.3 }
    146 	$(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
    147 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all
    148 }
    149 $(qx foreground) { $(qx s6-echo) "* System startup failure: retry" }
    150 # try again without tty and then with
    151 $(qx foreground) { $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty }
    152 $(qx foreground) { $(qx sleep) 0.1 }
    153 $(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
    154 $(qx s6-rc) -v 2 -t 600000 -- change ok-all
    155 EOF
    156 
    157 s6-mkdir "${dest}/run-image/service/console-log-tail" || exit $?
    158 s6-cat >"${dest}/run-image/service/console-log-tail/run" <<EOF || exit $?
    159 #!$el -P
    160 $(qx redirfd) -w 1 /dev/console
    161 $(qx fdmove) -c 2 1
    162 $(qx pipeline) -w { $(qx s6-tai64nlocal) }
    163 $(qx tail) -F -n +1 /run/uncaught-logs/current
    164 EOF
    165 s6-chmod 755 "${dest}/run-image/service/console-log-tail/run" exit $?
    166 
    167 
    168 
    169 
    170 cd "$pthbs_destdir/versions/$pthbs_package"
    171 find -type d -o -print | awk -F/ '
    172 BEGIN {
    173 	x["./bin/init"]=1
    174 	x["./bin/halt"]=1
    175 	x["./bin/poweroff"]=1
    176 	x["./bin/reboot"]=1
    177 }
    178 
    179 function r1(s) {
    180 	sub("^[.]/[^/]*", ".", s)
    181 	return s
    182 }
    183 function s1(repl, s) {
    184 	sub("^[.]/[^/]*", "./"repl, s)
    185 	return s
    186 }
    187 function link(src) {
    188 	x[$0]=0
    189 	printf "%s\t%s\n", $0, src
    190 	printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
    191 }
    192 $1!="."{exit 1}
    193 $2 == "env" { link($0); next }
    194 $2 == ".env-template" { link($0); next }
    195 
    196 $2 == "command" { link($0); next }
    197 $2 == "command" { link($0); next }
    198 $2 == "bin" { link(s1("command", $0)); next }
    199 $2 == "sbin" { link(s1("command", $0)); next }
    200 
    201 $2 == "library.so" { link($0); next }
    202 $2 == "library" { link($0); next }
    203 $2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
    204 $2 == "lib" && $NF ~ /\.so(\..*)?$/ { link(s1("library.so", $0)); next }
    205 
    206 $2 == "share" && $3 == "info" { link(s1("info", r1($0))); next }
    207 $2 == "share" && $3 == "man" { link(s1("man", r1($0))); next }
    208 $2 == "share" && $3 == "doc" { link(s1("doc", r1($0))); next }
    209 
    210 $2 == "config" { link($0); next }
    211 $2 == "man" { link($0); next }
    212 $2 == "info" { link($0); next }
    213 $2 == "doc" { link($0); next }
    214 $2 == "data" { link($0); next }
    215 $2 == "include" { link($0); next }
    216 
    217 $2 == "share" && $3 ~ /^(icons|terminfo)$/ { link(r1($0)); next }
    218 
    219 $2 == "library.ocaml" { link($0); next }
    220 
    221 $2 == "keys" { link($0); next }
    222 $2 == "zsh" { link($0); next }
    223 $2 == "vimfiles" { link($0); next }
    224 $2 == "icons" { link($0); next }
    225 $2 == "terminfo" { link($0); next }
    226 
    227 
    228 { printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
    229 
    230 END {
    231 	for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
    232 	retcode = 0
    233 	for(fname in x) {
    234 		if(x[fname]) {
    235 			printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
    236 			retcode = 3
    237 		}
    238 	}
    239 	exit retcode
    240 }' >.install-links.new
    241 mv .install-links.new .install-links
    242