#!@BINDIR@/execlineb -P
#
# anopa - Copyright (C) 2015-2017 Olivier Brunel
#
# aa-stage1
# 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/
#
@BINDIR@/emptyenv @BINDIR@/s6-envdir /etc/anopa/env @BINDIR@/exec
# Import log messages from initramfs, if possible
foreground {
if -X { aa-test -f /run/initramfs/boot.log }
redirfd -a 1 /var/log/boot/current cat /run/initramfs/boot.log
}
# Set up a pipe to log messages
piperw 3 4
background
{
fdclose 4 fdmove 0 3
redirfd -a 1 /var/log/boot/current
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 -B "Stage 1: Preparing system..." }
# Safety
cd /
umask 022
# Create the repository
backtick -n -D onboot REPODIR { aa-incmdline -rs aa }
backtick -n -D onboot REPODIR {
importas -u REPODIR REPODIR
if { aa-test -e /var/lib/repodir/$REPODIR } echo $REPODIR
}
importas -u REPODIR REPODIR
foreground { aa-echo -O3 -t "Copying ${REPODIR} repodir as /run/services..." }
foreground { emptyenv -c aa-hiercopy -O3 /var/lib/repodir/$REPODIR /run/services }
foreground { aa-echo -O3 -t "Starting s6-svscan..." }
# Make sure the FIFO needed for the switch to stage 2 is there
ifelse -X -n { aa-test -O3 -p /run/services/.scandir/uncaught-logs/fifo }
{
foreground { aa-echo -O3 -Be "Cannot start s6-svscan: No uncaught-logs fifo found" }
foreground { aa-echo -O3 -t "Trying to open a shell; " +g exit +w " to continue" }
emptyenv -c sh -i
}
# Reopen stdin/stdout/stderr to make them point to the right places
redirfd -r 0 /dev/null
redirfd -wnb 1 /run/services/uncaught-logs/fifo # (black magic: doesn't block)
fdmove -c 2 1
# close logger
fdclose 3
# Fork the "real" init (stage2) script and have it ready to start as soon as the
# catch-all logger is in place
background
{
s6-setsid
redirfd -w 1 /run/services/uncaught-logs/fifo # (blocks until the logger reads)
/run/services/.anopa/init
}
# Start the real init (as far as PID 1 goes)
emptyenv -c s6-svscan -t0 /run/services/.scandir