fix(audit): emit valid zero counts without nounset failures

This commit is contained in:
2026-10-30 11:01:17 -03:00
parent 0730f51d03
commit ee93df167c
4 changed files with 73 additions and 20 deletions
+12 -5
View File
@@ -37,7 +37,8 @@ check_mdm_status() {
else
echo -e " ${YEL}(none)${NC}"
fi
local count; count=$(echo "$matches" | grep -c . 2>/dev/null || echo 0)
local count; count=$(echo "$matches" | grep -c . 2>/dev/null || true)
count="${count:-0}"
echo -e " ${CYAN}Total: $count of 13 expected domains blocked${NC}"
else
echo -e " ${YEL}(hosts not found)${NC}"
@@ -99,10 +100,11 @@ deep_status() {
step "Installed Configuration Profiles"
if command -v profiles &>/dev/null; then
local profile_count
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
profile_count="${profile_count:-0}"
if [ "$profile_count" -gt 0 ]; then
warn "$profile_count profile(s) installed:"
sudo profiles -C -output=xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" | sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
sudo profiles -C -output stdout-xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" | sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
else
info "No configuration profiles installed"
fi
@@ -183,7 +185,11 @@ deep_status() {
step "Overall Assessment"
local risk="LOW"
[ "$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)" -gt 0 ] && risk="MEDIUM"
local cfg="/private/var/db/ConfigurationProfiles/Settings"
local installed
installed=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
installed="${installed:-0}"
[ "$installed" -gt 0 ] && risk="MEDIUM"
pgrep -i "mdm|managedclient" >/dev/null 2>&1 && risk="HIGH"
[ -f "$cfg/.cloudConfigRecordFound" ] && risk="CRITICAL"
@@ -203,7 +209,8 @@ deep_status_json() {
local profile_count=0
if command -v profiles &>/dev/null; then
profile_count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
profile_count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
profile_count="${profile_count:-0}"
fi
json="${json} \"profile_count\": $profile_count,\n"