V8.00.000.2025.06.17
All checks were successful
🛡️ Shell Script Linting / 🛡️ Shell Script Linting (push) Successful in 55s
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:
@@ -58,35 +58,78 @@ generate_subnetmask() {
|
||||
# Returns:
|
||||
# 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() {
|
||||
### 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
|
||||
)
|
||||
declare -A _seen=()
|
||||
declare -a _mods=()
|
||||
declare var_dev="" var_if="" var_uevent="" var_key="" var_val=""
|
||||
|
||||
### 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
|
||||
for var_dev in /sys/class/net/*; do
|
||||
[[ -d ${var_dev} ]] || continue
|
||||
var_if="${var_dev##*/}"
|
||||
[[ "${var_if}" == "lo" ]] && continue
|
||||
|
||||
if [[ -n "${var_nic_module}" ]]; then
|
||||
echo "${var_nic_module}"
|
||||
else
|
||||
echo "${var_nic_modules}"
|
||||
var_uevent="/sys/class/net/${var_if}/device/uevent"
|
||||
[[ -r "${var_uevent}" ]] || continue
|
||||
|
||||
### 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
|
||||
break
|
||||
fi
|
||||
done < "${var_uevent}"
|
||||
done
|
||||
|
||||
### Print one per line (initramfs-tools/modules friendly)
|
||||
((${#_mods[@]})) && printf '%s\n' "${_mods[@]}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
#######################################
|
||||
# Wrapper to insert the metadata field into the specified file.
|
||||
# Globals:
|
||||
|
||||
@@ -122,16 +122,11 @@ yaml_validator() {
|
||||
# shellcheck disable=SC2312
|
||||
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
|
||||
var_auto_fqdn=$(grep -m1 'option host-name' "/var/lib/dhcp/dhclient.${var_auto_nic}.leases" | sed -E 's/.*"([^"]+)".*/\1/')
|
||||
|
||||
else
|
||||
|
||||
var_auto_fqdn=""
|
||||
|
||||
fi
|
||||
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}")}"
|
||||
var_auto_fqdn="${var_auto_fqdn%.}"
|
||||
var_auto_fqdn="${var_auto_fqdn,,}"
|
||||
|
||||
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}'."
|
||||
|
||||
@@ -22,7 +22,7 @@ safe_exec() {
|
||||
declare -a ary_cmd=("${@:1:$#-1}") # All but last arg.
|
||||
declare var_errcode="${!#}" # Last arg.
|
||||
"${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}"
|
||||
}
|
||||
# vim: number et ts=2 sw=2 sts=2 ai tw=128 ft=sh
|
||||
|
||||
Reference in New Issue
Block a user