core-system-init-freebsd

core-system init submodule, FreeBSD version
git clone https://ccx.te2000.cz/git/core-system-init-freebsd
Log | Files | Refs

install (4102B)


      1 #!/bin/sh
      2 
      3 test -d "$1" || exit 1
      4 dst=$1
      5 
      6 test -d "$sm_dst_all" || exit 1
      7 test -d "$sm_dst_package" || exit 1
      8 cmd=$sm_dst_package/command
      9 
     10 src=$("$cmd/s6-dirname" "$0")
     11 test -d "$src/run-image/service/.s6-svscan" || exit 1
     12 
     13 q() {
     14 	"$sm_dst_package/command/s6-quote" "$@"
     15 }
     16 
     17 q_all=$(q "$sm_dst_all") || exit $?
     18 q_package=$(q "$sm_dst_package") || exit $?
     19 qc=$q_package/command
     20 
     21 mkdir -p "$dst/init/scripts" || exit $?
     22 
     23 # s6-svscanboot {{{1
     24 "$cmd/s6-cat" >"$dst/init/s6-svscanboot" <<EOF || exit $?
     25 #!$sm_dst_package/command/execlineb -P
     26 # make sure we have sane environment first
     27 $qc/redirfd -w 2 /dev/console
     28 $qc/redirfd -w 1 /dev/console
     29 $qc/redirfd -r 0 /dev/null
     30 $qc/export PATH "/command:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
     31 $qc/execline-umask 022
     32 
     33 #foreground { kldload tmpfs.ko }
     34 # we don't seem to have simple check to see if /run is mounted specifically,
     35 # so this will have to do
     36 $qc/if { mount -a -t tmpfs }
     37 
     38 # wait for catch-all logger fifo to appear
     39 $qc/if { $qc/s6-test -p /run/s6-svscan.fifo }
     40 $qc/redirfd -w 1 /run/s6-svscan.fifo
     41 $qc/fdmove -c 2 1
     42 
     43 $qc/if { printf "%s\n" "Starting S6" }
     44 $qc/if {
     45   $qc/if -Xnt { $qc/s6-test -d /run/service/.s6-svscan }
     46   $q_all/init/scripts/populate-run
     47 }
     48 
     49 $qc/pipeline -w
     50 {
     51   $qc/foreground { head -n 1 }
     52   $qc/s6-setsid --
     53   $qc/redirfd -r 0 /dev/null
     54   $qc/if -Xnt { $qc/s6-test -f /run/s6-rc/state }
     55   $q_all/init/scripts/rc.init ok-all
     56 }
     57 $qc/fdmove -c 3 1
     58 $qc/fdmove -c 1 2
     59 
     60 $qc/unexport !
     61 $qc/cd /run/service
     62 $qc/s6-svscan -t0 -d3 /run/service
     63 EOF
     64 "$cmd/s6-chmod" 755 "$dst/init/s6-svscanboot" || exit $?
     65 
     66 # s6-svscan-log {{{1
     67 "$cmd/s6-cat" >"$dst/init/s6-svscan-log" <<EOF || exit $?
     68 #!$sm_dst_package/command/execlineb -P
     69 # make sure we have sane environment first
     70 $qc/redirfd -w 2 /dev/console
     71 $qc/redirfd -w 1 /dev/console
     72 $qc/redirfd -r 0 /dev/null
     73 $qc/export PATH "/command:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
     74 $qc/execline-umask 022
     75 
     76 #foreground { kldload tmpfs.ko }
     77 # we don't seem to have simple check to see if /run is mounted specifically,
     78 # so this will have to do
     79 $qc/if { mount -a -t tmpfs }
     80 
     81 $qc/if { mkdir -p /run/uncaught-logs }
     82 $qc/if {
     83   $qc/if -nt { $qc/s6-test -p /run/s6-svscan.fifo }
     84   mkfifo /run/s6-svscan.fifo
     85 }
     86 $qc/redirfd -rnb 0 /run/s6-svscan.fifo
     87 $qc/s6-log -b -- t /run/uncaught-logs
     88 EOF
     89 "$cmd/s6-chmod" 755 "$dst/init/s6-svscan-log" || exit $?
     90 
     91 # populate-run {{{1
     92 "$cmd/s6-cat" >"$dst/init/scripts/populate-run" <<EOF || exit $?
     93 #!$sm_dst_package/command/execlineb -P
     94 $qc/fdmove -c 2 1
     95 $qc/ifelse { $qc/s6-test -e /run/service } {
     96   $qc/foreground { $qc/s6-echo -- "ERROR: /run/service already exists" }
     97   false
     98 } $qc/ifelse { $qc/s6-test -e /run/s6-rc } {
     99   $qc/foreground { $qc/s6-echo -- "ERROR: /run/s6-rc already exists" }
    100   false
    101 }
    102 elglob GLOB $(q "$(realpath "$src")")/run-image/* cp -a \$GLOB /run
    103 EOF
    104 "$cmd/s6-chmod" 755 "$dst/init/scripts/populate-run" || exit $?
    105 
    106 # rc.init {{{1
    107 "$cmd/s6-cat" >"$dst/init/scripts/rc.init" <<EOF || exit $?
    108 #!$sm_dst_package/command/execlineb -S1
    109 $qc/foreground { $qc/s6-echo "* Starting s6-rc from "$q_all/s6-rc-db" runlevel \${1}" }
    110 $qc/if { $qc/s6-rc-init -d -c $q_all/s6-rc-db /run/service }
    111 $q_all/init/scripts/runlevel \$1
    112 EOF
    113 "$cmd/s6-chmod" 755 "$dst/init/scripts/rc.init" || exit $?
    114 
    115 # rc.shutdown {{{1
    116 "$cmd/s6-cat" >"$dst/init/scripts/rc.shutdown" <<EOF || exit $?
    117 #!$sm_dst_package/command/execlineb -S1
    118 $qc/foreground
    119 {
    120   $qc/s6-echo "rc.shutdown called"
    121 }
    122 
    123 # Shut down all services
    124 if -n { $qc/s6-rc -da change }
    125 $qc/foreground { $qc/s6-echo "\`s6-rc -da change\` failed" }
    126 $qc/foreground { sleep 0.5s }
    127 EOF
    128 "$cmd/s6-chmod" 755 "$dst/init/scripts/rc.shutdown" || exit $?
    129 
    130 # runlevel {{{1
    131 "$cmd/s6-cat" >"$dst/init/scripts/runlevel" <<EOF || exit $?
    132 #!$sm_dst_package/command/execlineb -S1
    133 # The requested runlevel is in "\$1", use it as bundle name
    134 $qc/if -Xnt { $qc/s6-rc -v 2 -t 600000 -- change \$1 }
    135 $qc/foreground { $qc/s6-echo "* System startup failure: retry once" }
    136 $qc/foreground { sleep 0.1 }
    137 $qc/s6-rc -v 2 -t 300000 -- change \$1
    138 EOF
    139 "$cmd/s6-chmod" 755 "$dst/init/scripts/runlevel" || exit $?