{{- /* apparmor.d - Full set of apparmor profiles */ -}}
{{- /* Copyright (C) 2021-2024 Alexandre Pujol <alexandre@pujol.io> */ -}}
{{- /* SPDX-License-Identifier: GPL-2.0-only */ -}}

{{- define "rules" -}}

    {{- $oldkind := "" -}}
    {{- range . -}}
        {{- $kind := kindof . -}}
        {{- if eq $kind "" -}}
            {{- "\n" -}}
            {{- continue -}}
        {{- end -}}
        {{- if eq $kind "comment" -}}
            {{- indent "" -}}
            {{- template "comment" . -}}
            {{- "\n" -}}
            {{- continue -}}
        {{- end -}}

        {{- if and (ne $kind $oldkind) (ne $oldkind "") -}}
            {{- "\n" -}}
        {{- end -}}
        {{- indent "" -}}

        {{- if eq $kind "abi" -}}
            {{- template "abi" . -}}
        {{- end -}}

        {{- if eq $kind "alias" -}}
            {{- template "alias" . -}}
        {{- end -}}

        {{- if eq $kind "include" -}}
            {{- template "include" . -}}
        {{- end -}}

        {{- if eq $kind "variable" -}}
            {{- template "variable" . -}}
        {{- end -}}

        {{- if eq $kind "all" -}}
            {{- template "all" . -}}
        {{- end -}}

        {{- if eq $kind "rlimit" -}}
            {{- template "rlimit" . -}}
        {{- end -}}

        {{- if eq $kind "userns" -}}
            {{- template "userns" . -}}
        {{- end -}}

        {{- if eq $kind "capability" -}}
            {{- template "capability" . -}}
        {{- end -}}

        {{- if eq $kind "network" -}}
            {{- template "network" . -}}
        {{- end -}}

        {{- if eq $kind "mount" -}}
            {{- template "mount" . -}}
        {{- end -}}

        {{- if eq $kind "remount" -}}
            {{- template "remount" . -}}
        {{- end -}}

        {{- if eq $kind "umount" -}}
            {{- template "umount" . -}}
        {{- end -}}

        {{- if eq $kind "pivot_root" -}}
            {{- template "pivot_root" . -}}
        {{- end -}}

        {{- if eq $kind "change_profile" -}}
            {{- template "change_profile" . -}}
        {{- end -}}

        {{- if eq $kind "mqueue" -}}
            {{- template "mqueue" . -}}
        {{- end -}}

        {{- if eq $kind "io_uring" -}}
            {{- template "io_uring" . -}}
        {{- end -}}

        {{- if eq $kind "unix" -}}
            {{- template "unix" . -}}
        {{- end -}}

        {{- if eq $kind "ptrace" -}}
            {{- template "ptrace" . -}}
        {{- end -}}

        {{- if eq $kind "signal" -}}
            {{- template "signal" . -}}
        {{- end -}}

        {{- if eq $kind "dbus" -}}
            {{- template "dbus" . -}}
        {{- end -}}

        {{- if eq $kind "file" -}}
            {{- template "file" . -}}
        {{- end -}}

        {{- if eq $kind "link" -}}
            {{- template "link" . -}}
        {{- end -}}

        {{- if eq $kind "profile" -}}
            {{- template "profile" . -}}
        {{- end -}}

        {{- if eq $kind "hat" -}}
            {{- template "hat" . -}}
        {{- end -}}

        {{- "\n" -}}
        {{- $oldkind = $kind -}}
    {{- end -}}

{{- end -}}