V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 1m40s

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-08-26 21:17:11 +02:00
parent 0d4698c553
commit a55cad2391
4 changed files with 57 additions and 18 deletions

View File

@@ -117,10 +117,12 @@ yaml_validator() {
fi
# shellcheck disable=SC2312
var_link_ipv4=$(ping -q -c 1 -W 1 -4 debian.org > /dev/null 2>&1 && echo "true" || echo "false")
var_link_ipv4="$(probe_link 4 heise.de)"
#var_link_ipv4=$(ping -q -c 1 -W 1 -4 heise.de > /dev/null 2>&1 && echo "true" || echo "false")
# shellcheck disable=SC2312
var_link_ipv6=$(ping -q -c 1 -W 1 -6 debian.org > /dev/null 2>&1 && echo "true" || echo "false")
var_link_ipv6="$(probe_link 6 heise.de)"
#var_link_ipv6=$(ping -q -c 1 -W 1 -6 heise.de > /dev/null 2>&1 && echo "true" || echo "false")
# shellcheck disable=SC2312
var_auto_fqdn="$( getent hosts "${var_auto_ipv4}" | awk '{print $2}' | head -n1 )"
@@ -173,7 +175,7 @@ yaml_validator() {
fi
if [[ "${network_autoconfig_enable}" == "true" && "${var_link_ipv6}" == "true" ]]; then
if [[ "${network_autoconfig_enable}" == "true" ]]; then
# shellcheck disable=SC2034
VAR_FINAL_IPV6="${var_auto_ipv6}"
@@ -209,4 +211,37 @@ yaml_validator() {
guard_dir && return 0
}
#######################################
# Network connectivity prober.
# Arguments:
# 1: IP-Family
# 2: TLD to probe
# Returns:
# 0: on success
#######################################
probe_link() {
declare -r var_fam="${1:-4}" # "4" or "6"
declare -r var_target="${2:-heise.de}" # hostname or IP
declare var_ok="false"
### 1) Try ping (quiet, 1 probe, 3s deadline)
if ping -q -c 1 -W "${network_timeout_linkwait:-3}" "-${var_fam}" "${var_target}" >/dev/null 2>&1; then
var_ok="true"
else
### 2) Fallback: mtr in report mode (non-interactive), no DNS to avoid TUI/delays.
if command -v mtr >/dev/null 2>&1; then
### Treat as success if ANY hop resolves to something other than "???".
### '-r = report', '-c 2 = two cycles', -n = no DNS, -4/-6 = address family
# shellcheck disable=SC2312
if mtr "-${var_fam}" -r -c 3 -n "${var_target}" 2>/dev/null \
| awk 'NR>2 && $2!="???"{ok=1} END{exit ok?0:1}'; then
var_ok="true"
fi
fi
fi
printf '%s' "${var_ok}"
return 0
}
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh

View File

@@ -27,7 +27,7 @@ guard_sourcing
# 0: on success
#######################################
setup_hostname() {
### Create '${TARGET}/etc/hostname' file.
### Create the '${TARGET}/etc/hostname' file.
cat << EOF >| "${TARGET}/etc/hostname"
${VAR_FINAL_FQDN}
EOF
@@ -35,7 +35,7 @@ EOF
do_log "info" "file_only" "4030() File generated: '${TARGET}/etc/hostname' | hostname '${VAR_FINAL_FQDN}'."
### Create '${TARGET}/etc/mailname' file.
### Create the '${TARGET}/etc/mailname' file.
cat << EOF >| "${TARGET}/etc/mailname"
${VAR_FINAL_FQDN}
EOF