#!/bin/sh

set -e
set -u

PROFILES_NAMES=$(perl -nE 'if (m,^(?:profile\s+)?([a-z/-]+)\s,) {say $1}' \
                      $(find profiles -maxdepth 1 -type f))

AA_STATUS_JSON=$(aa-status --pretty-json)

profile_status() {
    echo "$AA_STATUS_JSON" | jq --raw-output ".profiles.\"${1}\""
}

for profile_name in $PROFILES_NAMES ; do
   echo "Checking that profile ${profile_name} is loaded..."
   status=$(profile_status "$profile_name")
   echo "Status of profile ${profile_name} is: ${status}"
   [ "$status" = 'enforce' ] || [ "$status" = 'complain' ]
done
