Skip to content

Compliance Script Layout

The compliance script is a zsh script with functions for checking settings, applying fixes, and reporting results. Understanding the structure helps you troubleshoot or customize the script.


SectionDescription
HeaderShebang, variables, paths to audit plist and log file
Utility functionsLogging, prompts, menu display
Rule checksIndividual check function for each rule
Rule fixesIndividual fix function for each rule
Main logicMenu system and command-line argument handling

FunctionPurpose
run_scanExecute all rule checks and write results to plist
run_fixApply remediation commands for non-compliant settings
generate_statsDisplay pass/fail counts and compliance percentage
show_menusDisplay interactive menu
logmessageWrite results to log file

Each rule in your baseline becomes a check block in the script:

  1. Extract current value - Run a command to get the current system setting
  2. Compare to expected - Check if the value matches the baseline requirement
  3. Log result - Record pass, fail, or exempt status to the audit plist

Each rule with a fix becomes a fix block in the script:

  1. Check exemption - Skip if the rule is marked exempt
  2. Check compliance - Skip if the rule already passed
  3. Prompt user - Ask for confirmation (unless running with --fix)
  4. Apply fix - Run the remediation command

FilePurpose
/Library/Preferences/org.BASELINE_NAME.audit.plistStores check results and exemptions
/Library/Logs/BASELINE_NAME_baseline.logTimestamped log of all actions