mrrl

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

system-config-init (9289B)


      1 #!/usr/bin/env pthbs-build
      2 #+busybox.379b7b2d8316b3678245563c8e592d71e6c380bc22a735c30c1c0e6f8f60caf3
      3 #+busybox-bzip2.4788e6edf9eeb73c7c665238a23aeed4703f8e25ab101509aee01440865ccdb1
      4 #+busybox-gzip.4fc908cacf4533192819578a079617c0cbe879b8ebd3e2140d896b067d3a574c
      5 #+busybox-lzop.e6e42a1a8451a4b845355899c9cd49efea2e395a0ef0c6ae7099103213a7bf4f
      6 #+busybox-unzip.93b5e83122059c87a2ddf489cdc7381bb80288630c508c218c2cfbadff524784
      7 #+busybox-xz.34137cc6ac8d23bf1bf5979b7fd047d4f50b34be07cd6ab636368952a199368d
      8 #+busybox-cpio.de88944ccff44a1f3abe06c42f83492a7e080de89fba27aadf5fe1a40e830cae
      9 #+busybox-dpkg.17e445a8089bc61db749a44c665597ecac3f21c4088daaa024f574412eb4d704
     10 #+busybox-rpm.669ed61ee218bc72206e069c896f392a025c88772ceb92ecb37b01ab0765baf8
     11 #+busybox-tar.15f67670238651149114006ae79359f24e1fa3c62be2e229a48f1334747ba413
     12 #+busybox-ed.78c51627a372c5b2ad3d046d0e77f341ae7c79917c4a16ca8abba284e7472cb7
     13 #+busybox-sed.8782396ae5c7b6e7d6bc8a93a7cff9912e6427e3d919dd5e5b00d1813ae88caf
     14 #+busybox-vi.e661d8eb052fbeebdd3be36ff6bd27651a7e59c857dad05c8633589790caa38c
     15 #+busybox-xxd.d2dc96e92cfdafae2c91d6fe897f42fdccae2dbc8b2d79f31eccc49d4e3a2d68
     16 #+busybox-process-extra.993cfd65eae2892ecb3fdfbece44b11e7ff6caa78f73e9f22bc2c97e7cd8a267
     17 #+busybox-procps.51ea8cb23d5eb1498f9167cc80b97c1a873758a8c1a7293079f50a2365466a71
     18 #+busybox-psmisc.ff1f9cf00f4c448946acb65d52b3b598e0495822af70b1504720cadf559e2090
     19 #+busybox-ash.7d10753f118afb2568e9f950c9cffa559b053a9b3ea516d6b46c3c73ebb6f8d8
     20 #+busybox-bc.c595636f103108c81f0ae55d2bf10d7cbc06ef1455a8353fcf04e42e765780a8
     21 #+busybox-coreutils.6b8071260ab4297f0e71013e42ac2a1a83fa99d92378d181ba49003fd349134a
     22 #+busybox-coreutils-extra.fc1b0766c881ee461d36c386833909553fcb0c31a547bfb563a7c6a50206bdcd
     23 #+busybox-daemontools.97aad28bbe5f38cff29db16c0f0d21e2fdc931825f683137df9bb57ef3a9b628
     24 #+busybox-grep.261a809c35cb58acc896143c2a81406a097f5870e02ce9906953181ef6b4c72b
     25 #+busybox-misc.5c2c025f1b74b9243a0128cd3f10dd1577b5ae123f53244d8e6895d4bdbd161d
     26 #+busybox-sh.25a9438d8449ade9c98af61b14af5711990dd002462a046b13b61969634c4d94
     27 #+busybox-util-linux-unpriv.4ea1c8c8746d7e80d36dea8924c576bc9666905b461dd543ceb5595394406c97
     28 #+busybox-findutils.052256c5bf9c3e7fef2e69d22f3d402d004f22113ce10b4d2c54ff417bf42622
     29 #+busybox-awk.f44da758ab8e737f05fb82ca4342acdf29ec44a9c2a9670cded75b04e8208058
     30 #+busybox-dosfstools.1d2b9edd5426588b64db50bbb58812ec321a745f3098e77b7885a1dea502157c
     31 #+busybox-e2fsprogs.d3f81870ed6114720a0f8fa957ce01ee3c4ca1dd9892c794bfa3882706efeb12
     32 #+busybox-iproute2.a5e6578168e3b608d3dfa07148a109f9cfa1a4701e74b44e6f92a59c4158af37
     33 #+busybox-iputils.8233bc9ace8965d538d33010d0324c90bccdcb71ee856a134395b47562a86859
     34 #+busybox-net-misc.bab4e5c7452fbf727d0b66eb25affc291e584ba58a1b023dc3ceb28a438492ac
     35 #+busybox-net-tools.b2c492d71f1f369d85138465b745bd9249efee3b2ca1d229b577b49fa03a7693
     36 #+busybox-traceroute.0c61c7a73c7b4004f1a88e134a534cc503cb53df511774a08193e674cca23e0c
     37 #+busybox-wget.3f3bb32e1a48616fe4ca8bdd7f69d4e281e42841e00175523c13b148c90b25cc
     38 #+busybox-chpst.30790f00d54403da6f0b9e2dc5e35d3a499db46a10928294eb3130ac9897d73d
     39 #+busybox-console.362bc79a1d38afa9666816d5b726eabc77f3a75bf145bb3b4f7562fcdc7019f6
     40 #+busybox-getty.a5db7cd285f5af5fe298afd3c0cf51fc2dbb4c116450ea9bb3403b77e57ef6e0
     41 #+busybox-i2c-tools.135c74be4f3cbcd45667f1749ff3124493f42707e204d178094828326df172eb
     42 #+busybox-linux-extra.1925e0cd6741f408301583323360f17a91f6c4e3143b6bb256fd6fbc82cd61c0
     43 #+busybox-mtd-utils.2f7c9f425030b22040d7fc75e86168d303857464448cd87e907d7ce824d541df
     44 #+busybox-shadow.1217e37cc209e4f8130c9290de26d0941c1690b1df6aa819e6bc6c4a08a1dcbb
     45 #+busybox-su.83da14ece711f6fdb33aebb0d0a2558827cc30ce9966f2696dbc95606951b175
     46 #+busybox-util-linux-priv.bcb37952ef97d61602b87ec1820f52fef4a5e6548c0f8b5b2f6ec768ddac2d02
     47 #+busybox-logging.a82bb2f2d07e0f30d1271482b142c052367a504a97b3803e7ad25148d53592c1
     48 #+busybox-cron.92a0481bcf3adea90752835bd7ee77641d7366ff84c1539f5562e01e9d14f01e
     49 #+s6.af31d85ebbb2bd67def86f46f702a872de0704ad1b77e1e52e5b3069f540fd54
     50 #+s6-rc.f77621d319bb146c643a78051d81af24a0062c5c51ff074708e947714b39f689
     51 #+s6-portable-utils.426dcf2bc59010960533bb68ff186d36386bbea55e390d2fdb928c8bea3fc87e
     52 #+s6-linux-init.536ee3819b3687a8da33dc343408b53ea5885900c7ee4553025a38cbb71ba1a6
     53 #+execline.5d88993134dc7d05e6124e7bd182279794ef9bac128f552aa1e98c17220e3c37
     54 #+system-config-rc.25f16a3f0b1f5e9d986f7690c1b50619611363251b9c25d2b7670b532995c5ac
     55 
     56 
     57 # - build script start -
     58 
     59 q() {  # quote list of strings to be suitable for execline
     60 	"s6-quote" "$@"
     61 }
     62 
     63 qx() {  # register executable as dependency and quote full path to be suitable for execline
     64 	exe=$(realpath "$(which "$1")")
     65 	name=$(basename "$1")
     66 	if ! test -x "$exe"; then
     67 		printf 'Error: executable not found: %s\n' "$1"
     68 	fi
     69 	mkdir -p "${dest}/deps/command"
     70 	ln -sf $exe "${dest}/deps/command/$name"
     71 	"s6-quote" "$prefix/deps/command/$name"
     72 }
     73 
     74 prefix=/home/ccx/versions/$pthbs_package
     75 dest=${pthbs_destdir%/}${prefix}
     76 cd '.'
     77 
     78 
     79 s6rcdb=/home/ccx/versions/system-config-rc.25f16a3f0b1f5e9d986f7690c1b50619611363251b9c25d2b7670b532995c5ac/config/s6-rc-db
     80 
     81 # Generate init (${dest} must not exist but parent dir does)
     82 mkdir -p "$pthbs_destdir//home/ccx/versions"
     83 s6-linux-init-maker \
     84 	-p "/run/current/command:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
     85 	-G "$(q "$prefix/deps/command/env") TERM=linux $(q "$prefix/deps/command/getty") 38400 tty9" \
     86 	-t 1 \
     87 	-N \
     88 	-c "$prefix" \
     89 	"${dest}"
     90 
     91 
     92 # Link deps that are passed to s6-l-i-m
     93 qx env
     94 qx getty
     95 
     96 # Link execlineb - can't quote shebang
     97 qx execlineb
     98 el=$prefix/deps/command/$name
     99 
    100 # Rewrite bin/init as it fails finding it's own s6-linux-init
    101 s6-cat >"${dest}/bin/init.new" <<EOF || exit $?
    102 #!$el -S0
    103 $(qx pthbs-enter)
    104 $(qx s6-envdir) -I /run/current/env
    105 EOF
    106 s6-cat >>"${dest}/bin/init.new" <"${dest}/bin/init"
    107 chmod +x "${dest}/bin/init.new"
    108 mv -v "${dest}/bin/init.new" "${dest}/bin/init"
    109 
    110 # Rewrite dynamically generated scripts
    111 s6-cat >"${dest}/scripts/rc.init" <<EOF || exit $?
    112 #!$el -S1
    113 $(qx export) TERM "linux"
    114 $(qx foreground) { $(qx s6-echo) "* Starting s6-rc from "$(q "$s6rcdb") }
    115 $(qx if) { $(qx s6-rc-init) -d -c $(q "$s6rcdb") /run/service }
    116 $prefix/scripts/runlevel \$1
    117 EOF
    118 
    119 s6-cat >"${dest}/scripts/rc.shutdown" <<EOF || exit $?
    120 #!$el -P
    121 
    122 ### Things to do before hardware halt/reboot/poweroff.
    123 ### Ideally, it should be a single call to the service manager,
    124 ### telling it to bring all the services down.
    125 
    126 $(qx redirfd) -w 1 /dev/console
    127 $(qx redirfd) -w 2 /dev/console
    128 $(qx s6-rc) -v2 -bDa change
    129 EOF
    130 
    131 s6-cat >"${dest}/scripts/runlevel" <<EOF || exit $?
    132 #!$el -S1
    133 export TERM "linux"
    134 
    135 # The requested runlevel is in "\$1" but currently ignored.
    136 
    137 # Run the service manager.
    138 # Call it twice because the first time may spuriously "timeout"
    139 # due to the clock jumping forward.
    140 
    141 $(qx ifelse) -X {
    142 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty 
    143 } {
    144 	# no timeout, start ttys properly
    145 	$(qx foreground) { $(qx s6-echo) "* System started normally (bundle ok-all-but-tty)" }
    146 	$(qx foreground) { sleep 0.3 }
    147 	$(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
    148 	$(qx s6-rc) -v 2 -t 600000 -- change ok-all
    149 }
    150 $(qx foreground) { $(qx s6-echo) "* System startup failure: retry" }
    151 # try again without tty and then with
    152 $(qx foreground) { $(qx s6-rc) -v 2 -t 600000 -- change ok-all-but-tty }
    153 $(qx foreground) { $(qx sleep) 0.1 }
    154 $(qx foreground) { $(qx s6-svc) -d /run/service/console-log-tail }
    155 $(qx s6-rc) -v 2 -t 600000 -- change ok-all
    156 EOF
    157 
    158 s6-mkdir "${dest}/run-image/service/console-log-tail" || exit $?
    159 s6-cat >"${dest}/run-image/service/console-log-tail/run" <<EOF || exit $?
    160 #!$el -P
    161 $(qx redirfd) -w 1 /dev/console
    162 $(qx fdmove) -c 2 1
    163 $(qx pipeline) -w { $(qx s6-tai64nlocal) }
    164 $(qx tail) -F -n +1 /run/uncaught-logs/current
    165 EOF
    166 s6-chmod 755 "${dest}/run-image/service/console-log-tail/run" exit $?
    167 
    168 
    169 
    170 
    171 cd "$pthbs_destdir/home/ccx/versions/$pthbs_package"
    172 find -type d -o -print | awk -F/ '
    173 BEGIN {
    174 	x["./bin/init"]=1
    175 	x["./bin/halt"]=1
    176 	x["./bin/poweroff"]=1
    177 	x["./bin/reboot"]=1
    178 }
    179 
    180 function r1(s) {
    181 	sub("^[.]/[^/]*", ".", s)
    182 	return s
    183 }
    184 function s1(repl, s) {
    185 	sub("^[.]/[^/]*", "./"repl, s)
    186 	return s
    187 }
    188 function link(src) {
    189 	x[$0]=0
    190 	printf "%s\t%s\n", $0, src
    191 	printf "genlinks >>%s\t%s<<\n", $0, src >>"/dev/stderr"
    192 }
    193 $1!="."{exit 1}
    194 
    195 
    196 $2 == "config" { link($0); next }
    197 $2 == "keys" { link($0); next }
    198 $2 == "zsh" { link($0); next }
    199 $2 == "env" { link($0); next }
    200 $2 == "command" { link($0); next }
    201 $2 == "bin" { link(s1("command", $0)); next }
    202 
    203 $2 == "library.so" { link($0); next }
    204 $2 == "library" { link($0); next }
    205 $2 == "lib" && $NF ~ /\.l?a$/ { link(s1("library", $0)); next }
    206 $2 == "lib" && $NF ~ /\.so(\..*)?$/ { link(s1("library.so", $0)); next }
    207 
    208 $2 == "share" && $3 ~ /^(info|man|doc|icons|terminfo)$/ { link(r1($0)); next }
    209 
    210 $2 == "man" { link($0); next }
    211 $2 == "info" { link($0); next }
    212 $2 == "doc" { link($0); next }
    213 $2 == "icons" { link($0); next }
    214 $2 == "terminfo" { link($0); next }
    215 $2 == "data" { link($0); next }
    216 $2 == "include" { link($0); next }
    217 
    218 { printf "genlinks ##%s## skipped\n", $0 >>"/dev/stderr" }
    219 
    220 END {
    221 	for(fname in x) { printf "DEBUG: x[\"%s\"]=\"%s\"\n", fname, x[fname] >"/dev/stderr" }
    222 	for(fname in x) {
    223 		if(x[fname]) {
    224 			printf "ERROR: missing expected file \"%s\"\n", fname >"/dev/stderr"
    225 			exit 3
    226 		}
    227 	}
    228 }' >.install-links.new
    229 mv .install-links.new .install-links
    230