From ac163e3808e981d742b805adc52b33c20e4e16a7 Mon Sep 17 00:00:00 2001 From: librelad Date: Sun, 24 May 2026 18:45:33 +0100 Subject: [PATCH] fix(desudo): don't run init.sh install-mode detect/write when sourced MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit start.sh sources init.sh for its function defs at runtime (Model A). The top-level install-mode auto-detect + initUpdateConfigOption write ran on every source, rewriting CFG_INSTALL_MODE via 'sudo sed' on the manager-owned config — denied under the scoped sudoers (the last per-command 'a password is required'), and spurious '"Auto-detected ..."' noise. Gate both on BASH_SOURCE==$0 (executed directly only); also drop the needless sudo from initUpdateConfigOption (config is manager-owned). Co-Authored-By: Claude Opus 4.7 Signed-off-by: librelad --- init.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/init.sh b/init.sh index e9bde21..10249b6 100755 --- a/init.sh +++ b/init.sh @@ -169,8 +169,11 @@ if [ "$init_local_install" = true ]; then param7="local" fi -# Auto-detect installation mode based on provided parameters -if [[ -z "$param7" ]]; then +# Auto-detect installation mode based on provided parameters. Only when init.sh +# is EXECUTED directly (install time) — start.sh sources init.sh for its function +# definitions at runtime (Model A, as the manager), and this block must not run +# then (it would print a spurious "Auto-detected ..." and rewrite the config). +if [[ "${BASH_SOURCE[0]}" == "$0" && -z "$param7" ]]; then # A reinstall that doesn't re-pass the git args must not silently # downgrade an existing git install to local (that disables the updater # and blanks the saved creds). Honor a git URL already saved from a @@ -208,9 +211,9 @@ initUpdateConfigOption() { local comment_part=$(echo "$original_line" | sed -n "s|^$config_option=[^#]*\(#.*\)|\1|p") if [[ -n "$comment_part" ]]; then - sudo sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file" + sed -i "s|^$config_option=.*|$config_option=$escaped_value $comment_part|" "$config_file" else - sudo sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file" + sed -i "s|^$config_option=.*|$config_option=$escaped_value|" "$config_file" fi source "$config_file" return 0 @@ -223,7 +226,7 @@ initUpdateConfigOption() { return 1 } -if [[ -n "$param7" && -f "${configs_dir}general/general_install" ]]; then +if [[ "${BASH_SOURCE[0]}" == "$0" && -n "$param7" && -f "${configs_dir}general/general_install" ]]; then initUpdateConfigOption "CFG_INSTALL_MODE" "$param7" fi