live-bootstrap/steps/improve/after.sh
Dor Askayo f91002b681 Abort execution on non-0 exit status from "after" scripts
Failures in "after" scripts do not currently result in bootstrap
failures since "find" ignores the exit code of commands that it
executes.

There are no simple options in "find" to both propagate non-0 exit
statuses of executed commands and also abort its command execution
sequence in such an event. As such, use "find" only for listing
script names and otherwise use a simple loop to execute them.

While at it, execute scripts in numerical order according to their
basename. This gives consumers control over the execution order of
their scripts. For example, 50-sign.sh will be executed before
51-upload.sh.
2025-02-26 09:08:54 +00:00

33 lines
982 B
Bash

#!/bin/sh
#
# SPDX-FileCopyrightText: 2024 Gábor Stefanik <netrolller.3d@gmail.com>
# SPDX-FileCopyrightText: 2025 Dor Askayo <dor.askayo@gmail.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# After bootstrap, drop to a shell if needed, then shut down cleanly.
. /steps/bootstrap.cfg
. /steps/env
if [ -d /steps/after ]; then
after_scripts=$(find /steps/after -maxdepth 1 -type f -name '*.sh' -printf '%f\t%p\n' | sort -k1 -n | cut -f2)
for script in $after_scripts; do
bash "$script"
done
fi
if [ "${INTERACTIVE}" = True ]; then
env - PATH=${PREFIX}/bin PS1="\w # " setsid openvt -fec1 -- bash -i
fi
if [ "${CHROOT}" = False ]; then
# ignore errors due to fstab or swapfile not existing
swapoff -a &> /dev/null || true
sync
# sysrq to avoid device busy; then mount to wait for it to finish
echo u > /proc/sysrq-trigger
mount -o remount,ro /
echo o > /proc/sysrq-trigger # power off
while true; do sleep 1; done
fi