Files
fedora-OEMDRV/system_setup/configure.sh
T

126 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# configure.sh - Interactive first-time configuration wizard
#
# SPDX-FileCopyrightText: Daniel Pätzold
# SPDX-License-Identifier: AGPL-3.0-or-later
SCRIPTDIR="$(cd "$(dirname "$0")" && pwd)"
CONF_DIST="${SCRIPTDIR}/../config/setup_system.conf.dist"
CONF_FILE="${SCRIPTDIR}/../config.d/configure.conf"
if [[ "$EUID" -eq 0 ]]; then
echo "ERROR: This script must not be run as root." >&2
exit 1
fi
# Prompt for a single value; returns the old value unchanged if the user presses Enter.
prompt_value() {
local name="$1" current="$2" new_val
printf ' %-28s [%s]: ' "$name" "$current" >&2
read -r new_val
printf '%s' "${new_val:-$current}"
}
# 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"
}
# 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"
else
printf 'export %s="%s"\n' "$varname" "$value" >> "$CONF_FILE"
fi
}
do_configure() {
mkdir -p "$(dirname "$CONF_FILE")"
cp "$CONF_DIST" "$CONF_FILE"
# Source the dist defaults (unset computed vars first so they are re-evaluated).
unset TLDOMAIN DOMAIN SERVERFQDN_IPA SERVERFQDN_NC CLIENTADMINGROUP \
DECRYPTEDDATADIR ENCRYPTEDDATADIR IPAVAULTUSE IPAVAULTNAME HOSTNM FQDN
# shellcheck disable=SC1090
source "$CONF_FILE"
echo ""
echo "=== System Configuration ==="
echo "Press Enter to keep the current value, or type a new one."
echo ""
new_TLDOMAIN=$(prompt_value "TLDOMAIN" "$TLDOMAIN")
TLDOMAIN="$new_TLDOMAIN"
DOMAIN="ipa.$TLDOMAIN}"
new_DOMAIN=$(prompt_value "DOMAIN" "$DOMAIN")
DOMAIN="${new_DOMAIN}"
SERVERFQDN_IPA="ipa.${TLDOMAIN}"
new_SERVERFQDN_IPA=$(prompt_value "SERVERFQDN_IPA" "$SERVERFQDN_IPA")
SERVERFQDN_IPA="$new_SERVERFQDN_IPA"
SERVERFQDN_NC="nextcloud.${TLDOMAIN}"
new_SERVERFQDN_NC=$(prompt_value "SERVERFQDN_NC" "$SERVERFQDN_NC")
SERVERFQDN_NC="$new_SERVERFQDN_NC"
new_CLIENTADMINGROUP=$(prompt_value "CLIENTADMINGROUP" "$CLIENTADMINGROUP")
CLIENTADMINGROUP="$new_CLIENTADMINGROUP"
set_conf_var "TLDOMAIN" "$new_TLDOMAIN"
set_conf_var "DOMAIN" "$DOMAIN"
set_conf_var "SERVERFQDN_IPA" "$new_SERVERFQDN_IPA"
set_conf_var "SERVERFQDN_NC" "$new_SERVERFQDN_NC"
set_conf_var "CLIENTADMINGROUP" "$new_CLIENTADMINGROUP"
# Re-source with the updated TLDOMAIN so DOMAIN and FQDN are recomputed correctly.
unset DOMAIN HOSTNM FQDN
source "$CONF_FILE"
echo ""
echo "Configuration written to: ${CONF_FILE}"
}
while true; do
do_configure
# Load setup_system.inc.sh (which re-sources configure.conf and defines all functions).
# shellcheck disable=SC1090
source "${SCRIPTDIR}/setup_system.inc.sh"
echo ""
echo "=== Testing: obtaining Nextcloud WebDAV token ==="
while true; do
# This makes the Token only available for this session
unset DAVTOKENFILENAME
get_nc_token
current_user="$(id -un)"
if [[ "${DAVTOKEN_USER}" == "${current_user}" ]]; then
echo "Token obtained successfully for user '${DAVTOKEN_USER}'."
break
fi
echo ""
if [[ -z "${DAVTOKEN_USER}" ]]; then
echo "Token could not be obtained (DAVTOKEN_USER is empty)."
else
echo "Token user '${DAVTOKEN_USER}' does not match current user '${current_user}'."
fi
read -rp "Retry get_nc_token (r) or quit (q)? [r/q]: " ans
if [[ "${ans,,}" == "q" ]]; then
echo "Quitting."
exit 1
fi
done
echo ""
echo "=== Configuration complete ==="
echo "All values have been configured and verified successfully."
echo "The system is now ready for the new installation."
echo "Boot from the Fedora USB installer — Anaconda will detect the OEMDRV partition"
echo "and run the Kickstart automatically."
exit 0
done