Improve prep and smoke test tooling

This commit is contained in:
Aaron
2026-01-03 17:20:18 -05:00
parent 1ddffee077
commit 808934cbec
2 changed files with 278 additions and 0 deletions

View File

@@ -197,6 +197,40 @@ clean_home_dir() {
fi
}
reset_iface_to_dhcp() {
local iface="$1"
local file="/etc/network/interfaces"
if [ ! -f "$file" ]; then
status SKIP "network config missing: $file"
return
fi
if ! grep -Eq "^[[:space:]]*iface[[:space:]]+$iface[[:space:]]+inet" "$file"; then
status SKIP "no iface config for $iface"
return
fi
local tmp
tmp="$(mktemp)"
awk -v target="$iface" '
BEGIN{in=0}
/^[[:space:]]*iface[[:space:]]+/ {
split($0, parts, /[[:space:]]+/);
if (parts[2]==target) { in=1; print "iface " target " inet dhcp"; next; }
else { in=0; }
}
{
if (in==1) {
if ($1=="address"||$1=="netmask"||$1=="gateway"||$1=="dns-nameservers") next;
}
print;
}' "$file" > "$tmp"
if mv "$tmp" "$file"; then
status CLEANED "forced DHCP for $iface in $file"
else
rm -f "$tmp" || true
status FAIL "update $file for $iface"
fi
}
prep_image() {
section "Prep"
@@ -418,6 +452,10 @@ prep_image() {
# --- DHCP leases ---
clean_file /var/lib/dhcp/dhclient.eth0.leases
# --- Network config ---
reset_iface_to_dhcp eth0
reset_iface_to_dhcp wlan0
# --- Nginx caches ---
if [ -d /var/lib/nginx ]; then
find /var/lib/nginx -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} + 2>/dev/null
@@ -486,6 +524,20 @@ check_file_empty_or_missing() {
fi
}
check_iface_dhcp() {
local iface="$1"
local file="/etc/network/interfaces"
if [ ! -f "$file" ]; then
status WARN "network config missing: $file"
return
fi
if grep -Eq "^[[:space:]]*iface[[:space:]]+$iface[[:space:]]+inet[[:space:]]+static" "$file"; then
status WARN "$iface set to static in $file"
else
status OK "$iface not static in $file"
fi
}
check_image() {
section "Check"
@@ -595,6 +647,10 @@ check_image() {
section "DHCP lease"
check_file_missing /var/lib/dhcp/dhclient.eth0.leases
section "Network config"
check_iface_dhcp eth0
check_iface_dhcp wlan0
section "Nginx cache dirs"
if [ -d /var/lib/nginx ]; then
local nginx_cache