Welcome to little lamb

Code » anopa » jjk » tree

[jjk] / src / scripts / aa-stage0

#!/bin/execlineb -P
#
# anopa - Copyright (C) 2015-2017 Olivier Brunel
#
# aa-stage0
# Copyright (C) 2015-2018 Olivier Brunel <jjk@jjacky.com>
#
# This file is part of anopa.
#
# anopa is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# anopa is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# anopa. If not, see http://www.gnu.org/licenses/
#
#
/bin/emptyenv /bin/s6-envdir /etc/anopa/env /bin/exec

# Set up a pipe to log messages
piperw 3 4
background
{
    fdclose 4 fdmove 0 3
    redirfd -a 1 /boot.log
    fdmove -c 2 1
    s6-tai64n
}

# aa-* tools will duplicate their output to 3 via -O3
fdclose 3
fdmove 3 4
foreground { aa-echo -O3 "Stage 0: Mounting root file system..." }

# Safety
cd /
umask 022

# Start services
foreground {
    foreground {
        emptyenv -c s6-setsid aa-ctty -O3 -s aa-start -O3 -r /services -l onboot
    }
    if { aa-test -e /services/.anopa/post-start }
    importas -u RC ? emptyenv -c /services/.anopa/post-start $RC
}

# if "break" was specified on kernel cmdline, let's open a shell
foreground {
    if -t { aa-incmdline -O3 -qf /root-fs/proc/cmdline break }
    foreground { aa-echo -O3 -B "Break requested" }
    foreground { aa-echo -O3 -t "Trying to open a shell; " +g exit +w " to continue" }
    emptyenv -c sh -i
}


if { aa-echo -O3 -B "Moving /root-fs to /..." }
# First we mount bind the rootfs (initramfs) onto /run/initramfs so we can come
# back to it for stage 4
if { aa-mount -O3 -Bd / /root-fs/run/initramfs }
backtick -n -D /sbin/init INIT { aa-incmdline -rf /root-fs/proc/cmdline init }
importas -u INIT INIT
fdclose 3
cd /root-fs
if { aa-mount -M . / }
./run/initramfs/bin/emptyenv -c ./run/initramfs/bin/aa-chroot . $INIT