Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/init/init
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ ensure_essential_environment() {

# If the user runs a non-zstd-aware depmod with a zstd-based module
# set, it may clear modules.dep. If so, fix modules.dep.
if [ -e /lib/modules/$(uname -r)/modules.dep ] && \
[ "$(stat -c%s "/lib/modules/$(uname -r)/modules.dep")" -eq 0 ]; then
if [ -e /lib/modules/$(uname -r)/modules.dep ] &&
[ "$(stat -c%s "/lib/modules/$(uname -r)/modules.dep")" -eq 0 ]; then
printf "Regenerating modules.dep... "
/sbin/depmod
echo "done"
Expand Down Expand Up @@ -385,6 +385,12 @@ complete_upgrade

init_timeout="$(cfg_values "init" "timeout")"
def_tuple="$(cfg_values "init" "default")"
tmpinit=""
if [ -f "/bedrock/etc/tmpinit" ]; then
def_tuple="$(cat "/bedrock/etc/tmpinit")"
rm "/bedrock/etc/tmpinit"
tmpinit="true"
fi
def_stratum="$(deref "$(echo "${def_tuple}" | cut -d: -f1)")"
def_cmd="$(echo "${def_tuple}" | cut -d: -f2-)"
def_path=""
Expand All @@ -398,7 +404,11 @@ if [ -n "${def_tuple}" ] && [ -d "/bedrock/strata/${def_stratum}" ]; then
umount "${sproc}"
fi
if [ -n "${def_tuple}" ] && [ -z "${def_path:-}" ]; then
notice "${color_warn}WARNING: ${color_file}/bedrock/etc/bedrock.conf [init]/default ${color_warn}value does not describe a valid stratum:init pair.${color_norm}"
if [ -z "$tmpinit" ]; then
notice "${color_warn}WARNING: ${color_file}/bedrock/etc/bedrock.conf [init]/default ${color_warn}value does not describe a valid stratum:init pair.${color_norm}"
else
notice "${color_warn}WARNING: ${color_file}/bedrock/etc/tmpinit ${color_warn} does not describe a valid stratum:init pair.${color_norm}"
fi
fi
if [ -z "${def_path:-}" ]; then
init_timeout="-1"
Expand Down
4 changes: 2 additions & 2 deletions src/slash-bedrock/bin/brl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ${color_term}Strata${color_norm} status management commands:
${color_cmd}enable ${color_norm}${color_term}Enable${color_norm} ${color_term}strata${color_norm}
${color_cmd}disable ${color_norm}${color_term}Disable${color_norm} ${color_term}strata${color_norm}
${color_cmd}repair ${color_norm}Repairs ${color_term}broken${color_norm} ${color_term}strata${color_norm}

${color_cmd}init ${color_norm}Choose which ${color_term}stratum${color_norm} the next reboot's init be.
${color_term}Strata${color_norm} visibility management commands:
${color_cmd}hide ${color_norm}${color_term}Hide${color_norm} ${color_term}strata${color_norm}
${color_cmd}show ${color_norm}${color_term}Show${color_norm} ${color_term}strata${color_norm}
Expand All @@ -61,7 +61,7 @@ case "${1:-}" in
print_help
exit_success
;;
"strat" | "list" | "which" | "fetch" | "import" | "remove" | "rename" | "copy" | "status" | "enable" | "disable" | "repair" | "hide" | "show" | "alias" | "deref" | "apply" | "update" | "version" | "report" | "tutorial")
"strat" | "list" | "which" | "fetch" | "import" | "remove" | "rename" | "copy" | "status" | "enable" | "disable" | "repair" | "init" | "hide" | "show" | "alias" | "deref" | "apply" | "update" | "version" | "report" | "tutorial")
backend="/bedrock/libexec/brl-${1}"
shift
exec "${backend}" "${@}"
Expand Down
46 changes: 46 additions & 0 deletions src/slash-bedrock/libexec/brl-init
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bedrock/libexec/busybox sh
#
# brl init
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# Copyright (c) 2012-2018 Daniel Thau <danthau@bedrocklinux.org>
# Copyright (c) 2026 TheOddCell <me@oddcell.a>
#
# Choose which stratum should be used as the default init for simply the next reboot.

. /bedrock/share/common-code

print_help() {
printf "Usage: ${color_cmd}brl init ${color_sub}[strat]${color_norm}

Choose which ${color_term}stratum${color_norm} the next reboot's init be.

Examples:
${color_cmd}$ brl init ${color_strat}arch${color_norm}:/lib/systemd/systemd # make the ${color_strat}arch${color_term} stratum ${color_norm}the next reboot's init, using /lib/systemd/systemd

${color_cmd}$ brl init ${color_strat}void${color_norm}:/sbin/init # make the ${color_strat}void${color_term} stratum ${color_norm}the next reboot's init, using /sbin/init

${color_cmd}$ brl init ${color_strat}debian${color_norm} # make the ${color_strat}debian${color_term} stratum ${color_norm}the next reboot's init, using /sbin/init

${color_norm}"
}

handle_help "${@:-}"
min_args "${#}" "1"

require_root
case "$1" in
*:*)
echo "$1">/bedrock/etc/tmpinit
;;
*)
echo "$1:/sbin/init">/bedrock/etc/tmpinit
;;
esac

notice "Please reboot manually to switch init systems."

exit_success
5 changes: 4 additions & 1 deletion src/slash-bedrock/share/bash/completion/brl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ _brl() {
if [ "${COMP_CWORD}" -eq 1 ]; then
opts="${opts} help strat list which fetch"
opts="${opts} remove rename status enable"
opts="${opts} disable reename copy hide show"
opts="${opts} disable init copy hide show"
opts="${opts} alias deref update reload"
opts="${opts} version report tutorial"
fi
Expand Down Expand Up @@ -186,6 +186,9 @@ _brl() {
"enable")
opts="${opts} $(/bedrock/bin/brl list -dD)"
;;
"init")
opts="${opts} $(/bedrock/bin/brl list -dD)"
;;
"disable")
for stratum in $(brl list -eE); do
if [ "$(/bedrock/bin/brl deref "${stratum}")" = "bedrock" ]; then
Expand Down