fix(audit): emit valid zero counts without nounset failures
This commit is contained in:
+9
-5
@@ -30,10 +30,11 @@ generate_report() {
|
||||
step "Installed Profiles"
|
||||
if command -v profiles &>/dev/null; then
|
||||
local count
|
||||
count=$(sudo profiles -C -output=xml 2>/dev/null | grep -c "ProfileDisplayName" || echo 0)
|
||||
count=$(sudo profiles -C -output stdout-xml 2>/dev/null | grep -c "ProfileDisplayName" || true)
|
||||
count="${count:-0}"
|
||||
if [ "$count" -gt 0 ]; then
|
||||
echo " $count profile(s) installed"
|
||||
sudo profiles -C -output=xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" \
|
||||
sudo profiles -C -output stdout-xml 2>/dev/null | grep -A1 "ProfileDisplayName" | grep "<string>" \
|
||||
| sed 's/.*<string>\(.*\)<\/string>.*/ - \1/'
|
||||
else
|
||||
echo " No profiles installed"
|
||||
@@ -78,7 +79,8 @@ generate_report() {
|
||||
step "Hosts Block"
|
||||
if grep -q "iprofiles.apple.com" /private/etc/hosts 2>/dev/null; then
|
||||
local blocked
|
||||
blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || echo 0)
|
||||
blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || true)
|
||||
blocked="${blocked:-0}"
|
||||
echo " $blocked domain(s) blocked in /etc/hosts"
|
||||
else
|
||||
echo " No block entries found"
|
||||
@@ -117,7 +119,8 @@ generate_report_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
|
||||
report="${report} \"installed_profiles\": $profile_count,\n"
|
||||
|
||||
@@ -147,7 +150,8 @@ generate_report_json() {
|
||||
report="${report} },\n"
|
||||
|
||||
local hosts_blocked=0
|
||||
hosts_blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || echo 0)
|
||||
hosts_blocked=$(grep -c "0.0.0.0" /private/etc/hosts 2>/dev/null || true)
|
||||
hosts_blocked="${hosts_blocked:-0}"
|
||||
report="${report} \"hosts_blocked\": $hosts_blocked\n"
|
||||
|
||||
report="${report}}"
|
||||
|
||||
Reference in New Issue
Block a user