#!/bin/execlineb -S0
#
# anopa - Copyright (C) 2015 Olivier Brunel
#
# aa-stage4
# Copyright (C) 2015 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

foreground { aa-echo -B "Stage 4: Unmounting root file system..." }
foreground { emptyenv -c aa-stop -r /services -a }

# At this point everything should be unmounted, so we need to remount what's
# needed for aa-terminate to work. We can't not umount /proc & /dev in aa-stop
# above and then assume they're here, since e.g. moving them back (from root-fs)
# might have failed. (And trying to mount /dev on top of it won't prevent
# aa-terminate from doing its thing properly.)
foreground { aa-echo -B "Mounting /dev & /proc and terminating..." }
foreground { aa-mount -t devtmpfs dev /dev }
foreground { aa-mount -t proc proc /proc }
foreground { aa-terminate -la }
aa-reboot --${1}
