Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
feat(MONTEREY): variable homebrew install location
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Jun 18, 2022
1 parent a68bba1 commit 966ce63
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
os: [10.15]
os: [10.15, 11, 12]
platform: [x86_64]
python-version: [3.8.10]
scenario: ["no_clamwatch", "clamwatch"]
Expand All @@ -172,6 +172,7 @@ jobs:
poetry run molecule test -s "${SCENARIO}"
env:
SCENARIO: ${{ matrix.scenario}}
PLATFORM: ${{ matrix.platform }}

- name: OSX Build -- Report Job Status (Success)
if: ${{ env.VERBOSE_NOTIFICATIONS == '1' }}
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Ansible role that installs ClamAV antivirus on OSX machines.
### Notes:
- See the [ClamAV Github Repository](https://github.com/Cisco-Talos/clamav) for further details about this tool.

### Catalina and Big Sur:
### Catalina and Later:

On OSX versions >= 10.15, there's a manual post installation step that should be done to maximize protection. (This is required to monitor the `Downloads` folder.)

Expand All @@ -28,6 +28,8 @@ Requirements
Role Variables
--------------

- `brew_prefix`
- Usually `/usr/local` or `/opt/homebrew` depending on your OSX version.
- `clamav_clamwatch`
- A boolean that indicates whether the ClamWatch daemon should be installed.
- `clamav_clamwatch_target_folder:`
Expand Down Expand Up @@ -74,6 +76,7 @@ Example Playbook
- role: elliotweiser.osx-command-line-tools
- role: geerlingguy.mac.homebrew
- role: osx_provisioner.clamav
brew_prefix: /usr/local
clamav_clamwatch: true
clamav_clamwatch_target_folder: "{{ lookup('env','HOME') }}/Downloads"
clamav_clamwatch_quarantine_folder: "{{ lookup('env','HOME') }}/Quarantine"
Expand Down
8 changes: 5 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
---
# defaults file for clamav

brew_prefix: "{{ (ansible_machine == 'arm64') | ternary('/opt/homebrew', '/usr/local') }}"

clamav_clamwatch: true

clamav_clamwatch_target_folder: "{{ lookup('env','HOME') }}/Downloads"
clamav_clamwatch_quarantine_folder: "{{ lookup('env','HOME') }}/Quarantine"
clamav_clamwatch_log_file: /var/log/clamav.clamwatch.log
clamav_clamwatch_stderr_log_file: /var/log/clamav.clamwatch.error.log

clamav_freshclam_config_file: /usr/local/etc/clamav/freshclam.conf
clamav_freshclam_config_file: "{{ brew_prefix }}/etc/clamav/freshclam.conf"
clamav_freshclam_log_file: /var/log/clamav.freshclam.log
clamav_freshclam_stderr_log_file: /var/log/clamav.freshclam.error.log

clamav_clamd_config_file: /usr/local/etc/clamav/clamd.conf
clamav_clamd_config_file: "{{ brew_prefix }}/etc/clamav/clamd.conf"
clamav_clamd_log_file: /var/log/clamav.clamd.log
clamav_clamd_stderr_log_file: /var/log/clamav.clamd.error.log

clamav_database_location: /usr/local/var/lib/clamav
clamav_database_location: "{{ brew_prefix }}/etc/local/var/lib/clamav"

clamav_homebrew_retries: 3
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

- name: Update Virus Definitions
become: true
ansible.builtin.command: /usr/local/bin/freshclam --config-file "{{ clamav_freshclam_config_file }}"
ansible.builtin.command: "{{ brew_prefix }}/bin/freshclam --config-file '{{ clamav_freshclam_config_file }}'"
changed_when: true
listen: "Update Virus Definitions"

Expand Down
13 changes: 10 additions & 3 deletions molecule/common/tasks/files.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
---
- name: Set CI Machine Type
set_fact:
ansible_machine: "{{ lookup('env','PLATFORM') }}"

- name: Load Default Var Content
include_vars: "../../../defaults/main.yml"

- name: Check clamd is installed
ansible.builtin.stat:
path: "/usr/local/sbin/clamd"
path: "{{ brew_prefix }}/sbin/clamd"
register: clamd_file

- name: Check freshclam is installed
ansible.builtin.stat:
path: "/usr/local/bin/freshclam"
path: "{{ brew_prefix }}/bin/freshclam"
register: freshclam_file

- name: Check clamwatch is installed
ansible.builtin.stat:
path: "/usr/local/bin/clamwatch"
path: "{{ brew_prefix }}/bin/clamwatch"
register: clamwatch_file
10 changes: 7 additions & 3 deletions molecule/common/tasks/processes.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
- name: Set CI Machine Type
set_fact:
ansible_machine: "{{ lookup('env','PLATFORM') }}"

- name: Load Default Var Content
include_vars: "../../../defaults/main.yml"

Expand All @@ -9,8 +13,8 @@

- name: Create Root Processes Match String
set_fact:
root_process_match_string1: '/usr/local/sbin/clamd --foreground -c {{ clamav_clamd_config_file }}'
root_process_match_string2: '/bin/bash /usr/local/bin/clamwatch {{ clamav_clamwatch_target_folder }} {{ clamav_clamwatch_quarantine_folder }} {{ clamav_clamwatch_log_file }}'
root_process_match_string1: '{{ brew_prefix }}/sbin/clamd --foreground -c {{ clamav_clamd_config_file }}'
root_process_match_string2: '/bin/bash {{ brew_prefix }}/bin/clamwatch {{ clamav_clamwatch_target_folder }} {{ clamav_clamwatch_quarantine_folder }} {{ clamav_clamwatch_log_file }}'

- name: Capture _clamav Processes
ansible.builtin.command: ps -u _clamav
Expand All @@ -19,4 +23,4 @@

- name: Create _clamav Processes Match String
set_fact:
_clamav_processes_match_string: '/usr/local/bin/freshclam --daemon --foreground --config-file {{ clamav_freshclam_config_file }}'
_clamav_processes_match_string: '{{ brew_prefix }}/bin/freshclam --daemon --foreground --config-file {{ clamav_freshclam_config_file }}'
6 changes: 3 additions & 3 deletions tasks/watcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@

- name: Install ClamWatch Script
become: true
ansible.builtin.copy:
src: clamwatch.sh
dest: /usr/local/bin/clamwatch
ansible.builtin.template:
src: clamwatch.sh.j2
dest: "{{ brew_prefix }}/bin/clamwatch"
mode: 0755
owner: root
group: wheel
Expand Down
2 changes: 1 addition & 1 deletion templates/clamav.clamd.plist.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string>clamav.clamd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/sbin/clamd</string>
<string>{{ brew_prefix }}/sbin/clamd</string>
<string>--foreground</string>
<string>-c</string>
<string>{{ clamav_clamd_config_file }}</string>
Expand Down
2 changes: 1 addition & 1 deletion templates/clamav.clamwatch.plist.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string>clamav.clamwatch</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/clamwatch</string>
<string>{{ brew_prefix }}/bin/clamwatch</string>
<string>{{ clamav_clamwatch_target_folder }}</string>
<string>{{ clamav_clamwatch_quarantine_folder }}</string>
<string>{{ clamav_clamwatch_log_file }}</string>
Expand Down
2 changes: 1 addition & 1 deletion templates/clamav.freshclam.plist.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<string>clamav.freshclam</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/freshclam</string>
<string>{{ brew_prefix }}/bin/freshclam</string>
<string>--daemon</string>
<string>--foreground</string>
<string>--config-file</string>
Expand Down
4 changes: 2 additions & 2 deletions files/clamwatch.sh → templates/clamwatch.sh.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# $2 - The quarantine folder to move items to
# $3 - The log file location

/usr/local/bin/fswatch "${1}" | while read -r FILE
{{ brew_prefix }}/bin/fswatch "${1}" | while read -r FILE
do
if [[ -f ${FILE} ]]; then
/usr/local/bin/clamdscan --no-summary --move="${2}" "${FILE}" >> "${3}"
{{ brew_prefix }}/bin/clamdscan --no-summary --move="${2}" "${FILE}" >> "${3}"
fi
done
2 changes: 1 addition & 1 deletion templates/freshclam.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ DatabaseMirror database.clamav.net

# Send the RELOAD command to clamd.
# Default: no
NotifyClamd /usr/local/etc/clamav/clamd.conf
NotifyClamd {{ brew_prefix }}/etc/clamav/clamd.conf

# Run command after successful database update.
# Default: disabled
Expand Down

0 comments on commit 966ce63

Please sign in to comment.