system-config-init (9610B)
1 #!/usr/bin/env pthbs-build 2 #+busybox.504428034e649f598212c8994966e36667178683ec90987355f495ad3ca4abac 3 #+busybox-bzip2.4ea548a271f41e7147568dc02e5071fb200eab38a9a22e733d3106b71e354812 4 #+busybox-gzip.0999e8c6a8b7df82fc1cf10ade2468fb2bc4352f76d4b1d2af5099a65ccada9b 5 #+busybox-lzop.f0d93621bfd8ca106a8590562d93158b05087e5ef48068c7a84d9967b67d2d25 6 #+busybox-unzip.737f61aac20ef6c0554fca59bb599bf98e4fb77fbd97fba65a3692ac9d4afb84 7 #+busybox-xz.639cf99dd37a7d6f719b937d13af92202e01adf11c130f8647574c1d9ef5b0d2 8 #+busybox-cpio.d22266c2b6c056c0ea96873402d06591aa23368ea24d91f1fbf8a8327cb210f8 9 #+busybox-dpkg.2b0dd2fa41e946e98f2f8948ae3d3a152a069c77460768d9c76d41f56974e514 10 #+busybox-rpm.62bb242b4fbb3fd51b233ed9ce6c257ab997b1ee3a68ef3048656addc98f3d97 11 #+busybox-tar.dd3d9b0075fc038df431ce2a16fc1b140de521e1aa6d154dc7b607f9403d5ac0 12 #+busybox-ed.6ff6cd59168705c6b256d800cde7e8c69dd05c556520317dae6a0b492029fe6b 13 #+busybox-sed.8793bcd2536ab32fa528bbb0c22f0c014663ac5e045193aa7bd113a07f58c5b9 14 #+busybox-vi.db3d29c62845a55b7c5491d057cb9ea6c6deba93c567f4ef9eb15f06be8ad171 15 #+busybox-xxd.9dff38f0c9dbf57856a0824bc23cc99cb31a67ce5138de7a6de2e255880a5696 16 #+busybox-process-extra.448a35fa5362e576a23ef306ec6e0da2f625adae08cc5c3b12a01d5d28f76ce6 17 #+busybox-procps.835712dc539d5583773d175255a5c4e27b5823d97e855948d27cc2c194247b0f 18 #+busybox-psmisc.f2434b74cd3e07ddea335da52c222567bc111b621f0f060afef8bcc26a8d96fd 19 #+busybox-ash.039eb4051853cdde4d03b8dbd5d6128957bf933be5ac398471666e5db0d33dab 20 #+busybox-bc.e731e83c11906525d676777835256a3f478779eafe7152701adfc46558d73009 21 #+busybox-coreutils.a57a12f85d58388c284d4f93f6c485d4bc2a7eac0d0f4be57b20d2ddbd4c8b8f 22 #+busybox-coreutils-extra.09de38ce2d65026888577e8314766e4b17205b2a99a4fecfdd5cd89c1cd82aed 23 #+busybox-daemontools.d12e277e7154028f0beaae44ad1e2c7e1cd12d28549b6861604fc634c3e09aaf 24 #+busybox-grep.474abd8ddad6afb320c55141078cb4507d02c4610181a4d72a4d98ba93434a60 25 #+busybox-misc.ea211db457ee098923eeff82a4388d5864254a6c2718f38471b5b2867c73d158 26 #+busybox-sh.49a7505969c9882c8a9a7ad3f5dba6d1382add3559f4da21ceafb2708d3fd4c8 27 #+busybox-util-linux-unpriv.95b792cd49d1f00d5488b15d93809166916ef3b8a63a69ea11f3bf6e92a74f24 28 #+busybox-findutils.db22f512240124b15d61cf8d0ceafebc98649f6f137608a2d1bd66f18e81ad8c 29 #+nawk.ec8a7f9ea4618a151470a1c1a0026f688a5032eb06b8e459510fe82316c17a60 30 #+busybox-dosfstools.179546bcd6ecb66c6539894d62d901e727b7ad1a7a314c6a6f3765eab9405090 31 #+busybox-e2fsprogs.a245d4da1f6a891c026409abc8b13aa012ce68db7dc02930dcd3e4d5384842a8 32 #+busybox-iproute2.2822ef07216c1b433ab6bd19871080d568c92fea2a26e8426c28e6adad2aeb29 33 #+busybox-iputils.9b88d3ac1988b296f3fcee8cec5f52d4a48a7663db0f98b359ef651e5a0760f2 34 #+busybox-net-misc.184d15a75f96f84c2d5ea201cbe58f8aec454ea601244764b374ceabc4fc6f9f 35 #+busybox-net-tools.3c6cac9d84e0b4f46317732bcbdc12d817879778d29f8b5b74fcac0e8fb97404 36 #+busybox-traceroute.1c04a547b3624077f5f494f0a0dd5c337d3aceae789725c0845cb7737a828b37 37 #+busybox-wget.6b7bb97a67eaa6dfe9f7d6b3e5be0962949e2b7e6ae80209a22144357742a14f 38 #+busybox-chpst.e73c721864c0b7b040fdb39e0d35fa32989e05ee813aad6dc901013c2aca37e3 39 #+busybox-console.70304cc8fe0cefc87bb7af67cb28509c71dd3c3bdf135172151b5d965ac5202e 40 #+busybox-getty.d5e78232db781cba4ac4c02a96262e18c8b52c4878d8c80879372327c40ab0ca 41 #+busybox-linux-extra.f198e630cc9428c7aba67c0d384144b71043f0d30dfa2d198a5f32d028728bc5 42 #+busybox-mtd-utils.2a0057a22776d92c89cfe12c28ad895f1c1a8a5f015a0fafe70661c3bc13620f 43 #+busybox-shadow.5ffa856469711a1550867610fdf3f0e161f27a79efebc6f232a085372f7586bb 44 #+busybox-su.b90c285664f5f1761b6f76bacbc155f89deb55ae38bd1668396a275bea461bff 45 #+busybox-util-linux-priv.9a041dc43dbcf3c67bac149789e819b0bb3934768de2d5f2785feda2d66a2d8e 46 #+busybox-logging.d216f2ce8e94dbbd8f29849959e3b3dfeda95ff53cfc5df1ee5533255b0b5b38 47 #+busybox-cron.d75134f370a00d415670bd831a43ffbc88d8abb59afa0920457f14458d3ed35c 48 #+s6.8995e7d6191578e627f1a57d90c25a0e52d9afa701bbbe951f12494e5880351c 49 #+s6-rc.9aac5b15b54c183366ab03f193a967d0fc66134b1623410032766e062e77bc5d 50 #+s6-portable-utils.ed9b2a1a2b2eade3f210e876b2e8c08d680c2fb0f4f5a1ec4137dd262a3d9e3d 51 #+s6-linux-init.7af048a1da88cb89e227afc4ce78f722cfde5a4bbe2f8fef1b1c4c37b1a12b8d 52 #+execline.403a4e1645c681e8c2ca9a75704a27658b788db460265916951d1d7a1e59ce8a 53 #+system-config-rc.4331458418d30a8b58158e829382d683b2532062cfa12c57a33d737dc7a63f4b 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=/home/ccx/versions/$pthbs_package 74 dest=${pthbs_destdir%/}${prefix} 75 cd '.' 76 77 78 s6rcdb=/home/ccx/versions/system-config-rc.4331458418d30a8b58158e829382d683b2532062cfa12c57a33d737dc7a63f4b/config/s6-rc-db 79 80 # Generate init (${dest} must not exist but parent dir does) 81 mkdir -p "$pthbs_destdir//home/ccx/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/home/ccx/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