forked from obel1x/fedora-OEMDRV
d363a806c0
Instead of obtaining a Nextcloud WebDAV token, verify the configured servers directly: - Nextcloud: check /status.php for "installed":true and show version - FreeIPA: check /ipa/session/json for HTTP 200 or 401 Both checks offer restart or quit on failure. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
114 lines
3.9 KiB
Bash
Executable File
114 lines
3.9 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
|
|
|
|
echo ""
|
|
echo "=== System Configuration ==="
|
|
echo "Press Enter to keep the current value, or type a new one."
|
|
echo ""
|
|
|
|
source "$CONF_FILE"
|
|
VARS=("TLDOMAIN" "DOMAIN" "SERVERFQDN_IPA" "SERVERFQDN_NC" "CLIENTADMINGROUP" "IPAVAULTUSE" )
|
|
for ELE in "${VARS[@]}"
|
|
do
|
|
new_ELE=$(prompt_value "${ELE}" "${!ELE}")
|
|
set_conf_var "${ELE}" "${new_ELE}"
|
|
source "$CONF_FILE"
|
|
done
|
|
|
|
echo ""
|
|
echo "Configuration written to: ${CONF_FILE}"
|
|
}
|
|
|
|
while true; do
|
|
do_configure
|
|
|
|
echo ""
|
|
echo "=== Testing: Nextcloud server ==="
|
|
NC_STATUS=$(curl -fsSL "https://${SERVERFQDN_NC}/status.php" 2>/dev/null)
|
|
if echo "$NC_STATUS" | grep -q '"installed":true'; then
|
|
NC_VERSION=$(echo "$NC_STATUS" | grep -oP '(?<="versionstring":")[^"]+')
|
|
echo "Nextcloud confirmed at ${SERVERFQDN_NC} (version ${NC_VERSION})."
|
|
else
|
|
echo ""
|
|
echo "WARNING: '${SERVERFQDN_NC}' does not appear to be a valid Nextcloud server."
|
|
echo " Could not reach https://${SERVERFQDN_NC}/status.php or response was unexpected."
|
|
read -rp "Start configuration again (a) or quit (q)? [a/q]: " ans
|
|
if [[ "${ans,,}" == "q" ]]; then
|
|
echo "Quitting."
|
|
exit 1
|
|
fi
|
|
continue
|
|
fi
|
|
|
|
echo ""
|
|
echo "=== Testing: FreeIPA server ==="
|
|
IPA_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
"https://${SERVERFQDN_IPA}/ipa/session/json" 2>/dev/null)
|
|
if [[ "$IPA_CODE" == "200" || "$IPA_CODE" == "401" ]]; then
|
|
echo "FreeIPA server confirmed at ${SERVERFQDN_IPA}."
|
|
else
|
|
echo ""
|
|
echo "WARNING: '${SERVERFQDN_IPA}' does not appear to be a valid FreeIPA server."
|
|
echo " https://${SERVERFQDN_IPA}/ipa/session/json returned: ${IPA_CODE:-no response}"
|
|
read -rp "Start configuration again (a) or quit (q)? [a/q]: " ans
|
|
if [[ "${ans,,}" == "q" ]]; then
|
|
echo "Quitting."
|
|
exit 1
|
|
fi
|
|
continue
|
|
fi
|
|
|
|
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
|