From ab7dc208ad4e8b17dbf95b9fa99b84ae6bb98d96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20unbrot=20P=C3=A4tzold?= Date: Wed, 6 May 2026 08:42:53 +0200 Subject: [PATCH] configure: Better detection and choice between predefined configs --- system_setup/configure.sh | 78 +++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/system_setup/configure.sh b/system_setup/configure.sh index d2d6ce1..030a94e 100755 --- a/system_setup/configure.sh +++ b/system_setup/configure.sh @@ -5,15 +5,9 @@ # SPDX-License-Identifier: AGPL-3.0-or-later SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)" -CONF_FILE="${SCRIPTDIR}/../config.d/configure.conf" - -CONF_EXISTING="${SCRIPTDIR}/../config/setup_system.conf" -if [[ -f "$CONF_EXISTING" ]]; then - echo "Found existing config in $CONF_EXISTING . Will try to use it." - CONF_DIST="$CONF_EXISTING" -else - CONF_DIST="${SCRIPTDIR}/config.dist/setup_system.conf.dist" -fi +CONF_DIST="${SCRIPTDIR}/config.dist/setup_system.conf.dist" +CONF_FILE="${SCRIPTDIR}/../config/setup_system.conf" +CONF_PRE="${SCRIPTDIR}/../config.d/configure.conf" # Prompt for a single value; returns the old value unchanged if the user presses Enter. prompt_value() { @@ -26,38 +20,66 @@ prompt_value() { # Replace the first matching simple export line in configure.conf. set_conf_var() { local varname="$1" value="$2" - sed -i "s|^[[:space:]]*export ${varname}=.*|export ${varname}=\"${value}\"|" "$CONF_FILE" + sed -i "s|^[[:space:]]*export ${varname}=.*|export ${varname}=\"${value}\"|" "$CONF_PRE" } # Update an existing bare "export VAR=…" line at the top level, or append one. override_conf_var() { local varname="$1" value="$2" - if grep -q "^export ${varname}=" "$CONF_FILE"; then - sed -i "s|^export ${varname}=.*|export ${varname}=\"${value}\"|" "$CONF_FILE" + if grep -q "^export ${varname}=" "$CONF_PRE"; then + sed -i "s|^export ${varname}=.*|export ${varname}=\"${value}\"|" "$CONF_PRE" else - printf 'export %s="%s"\n' "$varname" "$value" >> "$CONF_FILE" + printf 'export %s="%s"\n' "$varname" "$value" >> "$CONF_PRE" fi } do_configure() { - if [[ -f "$CONF_FILE" ]]; then - echo "Existing preconfig found: $CONF_FILE" + # Possibilities: + # 1 Found CONF_FILE="${SCRIPTDIR}/../config/setup_system.conf": This is a preinstalled company-value filled complete conf file + # 2 Found CONF_PRE="${SCRIPTDIR}/../config.d/configure.conf": This a a configure file from a previous configure run + # 3 Found none of these: use CONF_DIST="${SCRIPTDIR}/config.dist/setup_system.conf.dist" + # -> if 1 or 2 found, ask the user if to use one of them + # -> either choice, the CONF_PRE="${SCRIPTDIR}/../config.d/configure.conf" is written from it and used for further setup + + if [ -f "$CONF_FILE" ] || [ -f "$CONF_PRE" ]; then + echo "Some alternatives found for configure source:" + if [[ -f "$CONF_PRE" ]]; then + echo " Choice (p): Another config run result was found in $CONF_PRE ." + echo " Hint: May contain Values that already were setup different for your details" + else + unset CONF_PRE + fi + if [[ -f "$CONF_FILE" ]]; then + echo " Choice (c): Found companys full config in $CONF_FILE ." + echo " This may be a full config, that is valid for your company." + else + unset CONF_FILE + fi + # Always possible: Use new dist + echo " Choice (d): You may discard all, and use distributed defaults from the maintainers." + echo " Hint: Will always start from scratch which guaranties to have a valid config for your current version" + while true; do - read -r -p " Do you want to use it (1) or start with a new config (2): " CHOICE + read -r -p " Please make a coice: " CHOICE case "${CHOICE}" in - 1) - echo "Using the existing File" - break + "p") + if [[ -f "$CONF_PRE" ]]; then + echo "Using the existing config run file." + break + fi ;; - 2) - rm "$CONF_FILE" - cp "${CONF_DIST}" "$CONF_FILE" - break + "c") + if [[ -f "$CONF_FILE" ]]; then + rm "$CONF_PRE" >/dev/null 2>&1 + cp "$CONF_FILE" "$CONF_PRE" && break + fi ;; - *) - echo " Please enter 1 or 2." + "d") + rm "$CONF_PRE" >/dev/null 2>&1 + cp "$CONF_DIST" "$CONF_PRE" && break ;; esac + echo "Invalid choice or error in selection made." done else cp "${CONF_DIST}" "$CONF_FILE" @@ -79,7 +101,7 @@ do_configure() { set_conf_var "REPO_BRANCH" "$REPO_BRANCH" fi - source "$CONF_FILE" + source "$CONF_PRE" VARS=("TLDOMAIN" "SERVERFQDN_IPA" "DOMAIN" "SERVERFQDN_NC" "IPAVAULTUSE" "IPAVAULTNAME" "DISTCONFIGPATH_SRC" "CLIENTADMINGROUP" ) for ELE in "${VARS[@]}" do @@ -87,7 +109,7 @@ do_configure() { echo "" new_ELE=$(prompt_value "${ELE}" "${!ELE}") set_conf_var "${ELE}" "${new_ELE}" - source "$CONF_FILE" + source "$CONF_PRE" REPEAT_TEST=1 case ${ELE} in "SERVERFQDN_NC") echo "=== Testing: Nextcloud server ===" @@ -159,7 +181,7 @@ do_configure() { done echo "" - echo "Configuration written to: ${CONF_FILE}" + echo "Configuration written to: ${CONF_PRE}" } while true; do