diff --git a/src/init/init b/src/init/init index 11f12370..a860069f 100755 --- a/src/init/init +++ b/src/init/init @@ -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" @@ -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="" @@ -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" diff --git a/src/slash-bedrock/bin/brl b/src/slash-bedrock/bin/brl index e8c5eb59..0036511b 100755 --- a/src/slash-bedrock/bin/brl +++ b/src/slash-bedrock/bin/brl @@ -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} @@ -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}" "${@}" diff --git a/src/slash-bedrock/libexec/brl-init b/src/slash-bedrock/libexec/brl-init new file mode 100755 index 00000000..791923c5 --- /dev/null +++ b/src/slash-bedrock/libexec/brl-init @@ -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 +# Copyright (c) 2026 TheOddCell +# +# 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 diff --git a/src/slash-bedrock/share/bash/completion/brl b/src/slash-bedrock/share/bash/completion/brl index fcdb39ba..802ab65a 100755 --- a/src/slash-bedrock/share/bash/completion/brl +++ b/src/slash-bedrock/share/bash/completion/brl @@ -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 @@ -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