Fix firstboot tls bundle script and prep checks
This commit is contained in:
@@ -23,6 +23,7 @@ DID_PREP=0
|
||||
|
||||
ERRORS=0
|
||||
WARNINGS=0
|
||||
STOPPED_PIHOLE_FTL=0
|
||||
|
||||
usage() {
|
||||
cat <<'USAGE'
|
||||
@@ -211,14 +212,14 @@ reset_iface_to_dhcp() {
|
||||
local tmp
|
||||
tmp="$(mktemp)"
|
||||
awk -v target="$iface" '
|
||||
BEGIN{in=0}
|
||||
BEGIN{in_iface=0}
|
||||
/^[[:space:]]*iface[[:space:]]+/ {
|
||||
split($0, parts, /[[:space:]]+/);
|
||||
if (parts[2]==target) { in=1; print "iface " target " inet dhcp"; next; }
|
||||
else { in=0; }
|
||||
if (parts[2]==target) { in_iface=1; print "iface " target " inet dhcp"; next; }
|
||||
else { in_iface=0; }
|
||||
}
|
||||
{
|
||||
if (in==1) {
|
||||
if (in_iface==1) {
|
||||
if ($1=="address"||$1=="netmask"||$1=="gateway"||$1=="dns-nameservers") next;
|
||||
}
|
||||
print;
|
||||
@@ -321,7 +322,14 @@ prep_image() {
|
||||
fi
|
||||
|
||||
if command -v pihole >/dev/null 2>&1; then
|
||||
pihole -f >/dev/null 2>&1 && status CLEANED "pihole logs via pihole -f" || status FAIL "pihole -f"
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
if systemctl stop pihole-FTL >/dev/null 2>&1; then
|
||||
status CLEANED "stopped pihole-FTL"
|
||||
STOPPED_PIHOLE_FTL=1
|
||||
else
|
||||
status WARN "unable to stop pihole-FTL"
|
||||
fi
|
||||
fi
|
||||
clean_logs_dir /var/log/pihole '*'
|
||||
clean_file /etc/pihole/pihole-FTL.db
|
||||
clean_file /etc/pihole/pihole-FTL.db-wal
|
||||
@@ -609,12 +617,22 @@ check_image() {
|
||||
|
||||
section "Logs"
|
||||
if [ -d /var/log ]; then
|
||||
local nonempty
|
||||
nonempty="$(find /var/log -type f -size +0c 2>/dev/null | wc -l | tr -d ' ')"
|
||||
if [ "$nonempty" -gt 0 ]; then
|
||||
status WARN "/var/log has non-empty files: $nonempty"
|
||||
local nonempty filtered
|
||||
nonempty="$(find /var/log -type f -size +0c 2>/dev/null)"
|
||||
filtered="$(printf "%s\n" "$nonempty" | grep -Ev '/(lastlog|faillog|btmp|wtmp)$' || true)"
|
||||
if [ -n "$filtered" ]; then
|
||||
local count
|
||||
count="$(printf "%s\n" "$filtered" | wc -l | tr -d ' ')"
|
||||
status WARN "/var/log has non-empty files: $count"
|
||||
printf "%s\n" "$filtered" | head -n 5 | sed 's/^/[WARN] /'
|
||||
else
|
||||
status OK "/var/log empty"
|
||||
if [ -n "$nonempty" ]; then
|
||||
local count
|
||||
count="$(printf "%s\n" "$nonempty" | wc -l | tr -d ' ')"
|
||||
status WARN "/var/log has only login tracking files: $count"
|
||||
else
|
||||
status OK "/var/log empty"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
status WARN "/var/log missing"
|
||||
@@ -713,6 +731,13 @@ maybe_shutdown() {
|
||||
status OK "Shutting down"
|
||||
shutdown -f now || status FAIL "shutdown"
|
||||
else
|
||||
if [ "$STOPPED_PIHOLE_FTL" -eq 1 ] && command -v systemctl >/dev/null 2>&1; then
|
||||
if systemctl start pihole-FTL >/dev/null 2>&1; then
|
||||
status OK "restarted pihole-FTL (shutdown skipped)"
|
||||
else
|
||||
status WARN "failed to restart pihole-FTL after prep"
|
||||
fi
|
||||
fi
|
||||
status OK "Shutdown skipped"
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user