#!/usr/bin/env bash
set -e

usage() {
cat <<HELP
Usage:
  sone-av status
  sone-av scan <path>
  sone-av socket
HELP
}

case "${1:-}" in
  status)
    systemctl status clamav-freshclam --no-pager || true
    systemctl status clamav-daemon --no-pager || true
    ;;
  scan)
    if [ -z "${2:-}" ]; then
      usage
      exit 1
    fi

    if command -v clamdscan >/dev/null 2>&1; then
      clamdscan --fdpass "$2"
    else
      clamscan -r "$2"
    fi
    ;;
  socket)
    if [ -f /etc/sone/antivirus/clamav.env ]; then
      . /etc/sone/antivirus/clamav.env
    fi

    echo "${CLAMAV_LOCAL_SOCKET:-/run/clamav/clamd.ctl}"
    ;;
  *)
    usage
    exit 1
    ;;
esac
