configure: Better detection and choice between predefined configs
This commit is contained in:
+47
-25
@@ -5,15 +5,9 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
|
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"
|
CONF_DIST="${SCRIPTDIR}/config.dist/setup_system.conf.dist"
|
||||||
fi
|
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 for a single value; returns the old value unchanged if the user presses Enter.
|
||||||
prompt_value() {
|
prompt_value() {
|
||||||
@@ -26,38 +20,66 @@ prompt_value() {
|
|||||||
# Replace the first matching simple export line in configure.conf.
|
# Replace the first matching simple export line in configure.conf.
|
||||||
set_conf_var() {
|
set_conf_var() {
|
||||||
local varname="$1" value="$2"
|
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.
|
# Update an existing bare "export VAR=…" line at the top level, or append one.
|
||||||
override_conf_var() {
|
override_conf_var() {
|
||||||
local varname="$1" value="$2"
|
local varname="$1" value="$2"
|
||||||
if grep -q "^export ${varname}=" "$CONF_FILE"; then
|
if grep -q "^export ${varname}=" "$CONF_PRE"; then
|
||||||
sed -i "s|^export ${varname}=.*|export ${varname}=\"${value}\"|" "$CONF_FILE"
|
sed -i "s|^export ${varname}=.*|export ${varname}=\"${value}\"|" "$CONF_PRE"
|
||||||
else
|
else
|
||||||
printf 'export %s="%s"\n' "$varname" "$value" >> "$CONF_FILE"
|
printf 'export %s="%s"\n' "$varname" "$value" >> "$CONF_PRE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
do_configure() {
|
do_configure() {
|
||||||
|
# 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
|
if [[ -f "$CONF_FILE" ]]; then
|
||||||
echo "Existing preconfig found: $CONF_FILE"
|
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
|
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
|
case "${CHOICE}" in
|
||||||
1)
|
"p")
|
||||||
echo "Using the existing File"
|
if [[ -f "$CONF_PRE" ]]; then
|
||||||
|
echo "Using the existing config run file."
|
||||||
break
|
break
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
2)
|
"c")
|
||||||
rm "$CONF_FILE"
|
if [[ -f "$CONF_FILE" ]]; then
|
||||||
cp "${CONF_DIST}" "$CONF_FILE"
|
rm "$CONF_PRE" >/dev/null 2>&1
|
||||||
break
|
cp "$CONF_FILE" "$CONF_PRE" && break
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
*)
|
"d")
|
||||||
echo " Please enter 1 or 2."
|
rm "$CONF_PRE" >/dev/null 2>&1
|
||||||
|
cp "$CONF_DIST" "$CONF_PRE" && break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
echo "Invalid choice or error in selection made."
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
cp "${CONF_DIST}" "$CONF_FILE"
|
cp "${CONF_DIST}" "$CONF_FILE"
|
||||||
@@ -79,7 +101,7 @@ do_configure() {
|
|||||||
set_conf_var "REPO_BRANCH" "$REPO_BRANCH"
|
set_conf_var "REPO_BRANCH" "$REPO_BRANCH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source "$CONF_FILE"
|
source "$CONF_PRE"
|
||||||
VARS=("TLDOMAIN" "SERVERFQDN_IPA" "DOMAIN" "SERVERFQDN_NC" "IPAVAULTUSE" "IPAVAULTNAME" "DISTCONFIGPATH_SRC" "CLIENTADMINGROUP" )
|
VARS=("TLDOMAIN" "SERVERFQDN_IPA" "DOMAIN" "SERVERFQDN_NC" "IPAVAULTUSE" "IPAVAULTNAME" "DISTCONFIGPATH_SRC" "CLIENTADMINGROUP" )
|
||||||
for ELE in "${VARS[@]}"
|
for ELE in "${VARS[@]}"
|
||||||
do
|
do
|
||||||
@@ -87,7 +109,7 @@ do_configure() {
|
|||||||
echo ""
|
echo ""
|
||||||
new_ELE=$(prompt_value "${ELE}" "${!ELE}")
|
new_ELE=$(prompt_value "${ELE}" "${!ELE}")
|
||||||
set_conf_var "${ELE}" "${new_ELE}"
|
set_conf_var "${ELE}" "${new_ELE}"
|
||||||
source "$CONF_FILE"
|
source "$CONF_PRE"
|
||||||
REPEAT_TEST=1
|
REPEAT_TEST=1
|
||||||
case ${ELE} in
|
case ${ELE} in
|
||||||
"SERVERFQDN_NC") echo "=== Testing: Nextcloud server ==="
|
"SERVERFQDN_NC") echo "=== Testing: Nextcloud server ==="
|
||||||
@@ -159,7 +181,7 @@ do_configure() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Configuration written to: ${CONF_FILE}"
|
echo "Configuration written to: ${CONF_PRE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|||||||
Reference in New Issue
Block a user