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

Signed-off-by: Marc S. Weidner <msw@coresecret.dev>
This commit is contained in:
2025-08-12 20:13:01 +02:00
parent 0eb2b72d86
commit 3dc762283a
3 changed files with 71 additions and 33 deletions

View File

@@ -58,35 +58,78 @@ generate_subnetmask() {
# Returns: # Returns:
# 0: on success # 0: on success
####################################### #######################################
#grep_nic_driver_modules() {
# ### Collect all ethernet driver names and sort them uniquely.
# declare -a _mods
# declare var_nic_module var_nic_modules
# # shellcheck disable=SC2312
# readarray -t _mods < <(
# lspci -k \
# | grep -A2 -i ethernet \
# | grep 'Kernel driver in use' \
# | awk '{print $5}' \
# | sort -u
# )#
#
# ### If only one entry remains, save it in 'var_nic_module', otherwise save all modules in 'var_nic_modules'.
# if [[ "${#_mods[@]}" -eq 1 ]]; then
# var_nic_module="${_mods[0]}"
# else
# var_nic_modules="${_mods[*]}"
# fi
#
# if [[ -n "${var_nic_module}" ]]; then
# echo "${var_nic_module}"
# else
# echo "${var_nic_modules}"
# fi
#
# return 0
#}
#######################################
# Collect NIC driver modules for initramfs installation (no lspci required).
# Uses '/sys' introspection to stay independent of pciutils/ethtool.
# Arguments:
# None
# Output:
# One module name per line (suitable for initramfs-tools/modules)
# Returns:
# 0: on success
#######################################
grep_nic_driver_modules() { grep_nic_driver_modules() {
### Collect all ethernet driver names and sort them uniquely. declare -A _seen=()
declare -a _mods declare -a _mods=()
declare var_nic_module var_nic_modules declare var_dev="" var_if="" var_uevent="" var_key="" var_val=""
# shellcheck disable=SC2312
readarray -t _mods < <(
lspci -k \
| grep -A2 -i ethernet \
| grep 'Kernel driver in use' \
| awk '{print $5}' \
| sort -u
)
### If only one entry remains, save it in 'var_nic_module', otherwise save all modules in 'var_nic_modules'. for var_dev in /sys/class/net/*; do
if [[ "${#_mods[@]}" -eq 1 ]]; then [[ -d ${var_dev} ]] || continue
var_nic_module="${_mods[0]}" var_if="${var_dev##*/}"
else [[ "${var_if}" == "lo" ]] && continue
var_nic_modules="${_mods[*]}"
fi
if [[ -n "${var_nic_module}" ]]; then var_uevent="/sys/class/net/${var_if}/device/uevent"
echo "${var_nic_module}" [[ -r "${var_uevent}" ]] || continue
else
echo "${var_nic_modules}" ### Parse key=value lines and extract DRIVER
while IFS='=' read -r var_key var_val; do
if [[ "${var_key}" == "DRIVER" && -n "${var_val}" ]]; then
### De-duplicate
if [[ -z "${_seen[${var_val}]:-}" ]]; then
_seen["${var_val}"]=1
_mods+=("${var_val}")
fi fi
break
fi
done < "${var_uevent}"
done
### Print one per line (initramfs-tools/modules friendly)
((${#_mods[@]})) && printf '%s\n' "${_mods[@]}"
return 0 return 0
} }
####################################### #######################################
# Wrapper to insert the metadata field into the specified file. # Wrapper to insert the metadata field into the specified file.
# Globals: # Globals:

View File

@@ -122,16 +122,11 @@ yaml_validator() {
# shellcheck disable=SC2312 # 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=$(ping -q -c 1 -W 1 -6 debian.org > /dev/null 2>&1 && echo "true" || echo "false")
if [[ -f "/var/lib/dhcp/dhclient.${var_auto_nic}.leases" ]]; then
# shellcheck disable=SC2312 # shellcheck disable=SC2312
var_auto_fqdn=$(grep -m1 'option host-name' "/var/lib/dhcp/dhclient.${var_auto_nic}.leases" | sed -E 's/.*"([^"]+)".*/\1/') var_auto_fqdn="$( getent hosts "${var_auto_ipv4}" | awk '{print $2}' | head -n1 )"
var_auto_fqdn="${var_auto_fqdn:-$(dig +short -x "${var_auto_ipv4}")}"
else var_auto_fqdn="${var_auto_fqdn%.}"
var_auto_fqdn="${var_auto_fqdn,,}"
var_auto_fqdn=""
fi
do_log "info" "file_only" "1252() Live environment network check: Auto NIC ='${var_auto_nic}'." do_log "info" "file_only" "1252() Live environment network check: Auto NIC ='${var_auto_nic}'."
do_log "info" "file_only" "1252() Live environment network check: Auto IPv4 ='${var_auto_ipv4}'." do_log "info" "file_only" "1252() Live environment network check: Auto IPv4 ='${var_auto_ipv4}'."

View File

@@ -22,7 +22,7 @@ safe_exec() {
declare -a ary_cmd=("${@:1:$#-1}") # All but last arg. declare -a ary_cmd=("${@:1:$#-1}") # All but last arg.
declare var_errcode="${!#}" # Last arg. declare var_errcode="${!#}" # Last arg.
"${ary_cmd[@]}" && return 0 "${ary_cmd[@]}" && return 0
do_log "error" "file_only" "0011() Command '${ary_cmd[*]}' failed." do_log "error" "file_only" "0007() Command '${ary_cmd[*]}' failed."
return "${var_errcode}" return "${var_errcode}"
} }
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh # vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh