72 lines
2.1 KiB
Python
72 lines
2.1 KiB
Python
"""ClamAV related tools."""
|
|
|
|
from .. import package
|
|
from .. import utils
|
|
from .. import system
|
|
|
|
from . import base
|
|
|
|
|
|
class Clamav(base.Installer):
|
|
|
|
"""ClamAV installer."""
|
|
|
|
appname = "clamav"
|
|
daemon_name = "clamav-daemon"
|
|
packages = {
|
|
"deb": ["clamav-daemon"],
|
|
"rpm": [
|
|
"clamav", "clamav-update", "clamav-server", "clamav-server-systemd"
|
|
],
|
|
}
|
|
|
|
def get_daemon_name(self):
|
|
"""Return appropriate daemon name."""
|
|
if package.backend.FORMAT == "rpm":
|
|
return "clamd@amavisd"
|
|
return "clamav-daemon"
|
|
|
|
@property
|
|
def config_dir(self):
|
|
"""Return appropriate config dir."""
|
|
if package.backend.FORMAT == "rpm":
|
|
return "/etc"
|
|
return ""
|
|
|
|
def get_config_files(self):
|
|
"""Return appropriate config files."""
|
|
if package.backend.FORMAT == "rpm":
|
|
return ["sysconfig/clamd.amavisd", "tmpfiles.d/clamd.amavisd.conf"]
|
|
return []
|
|
|
|
def post_run(self):
|
|
"""Additional tasks."""
|
|
if package.backend.FORMAT == "deb":
|
|
user = self.config.get(self.appname, "user")
|
|
system.add_user_to_group(
|
|
user, self.config.get("amavis", "user")
|
|
)
|
|
pattern = (
|
|
"s/^AllowSupplementaryGroups false/"
|
|
"AllowSupplementaryGroups true/")
|
|
utils.exec_cmd(
|
|
"perl -pi -e '{}' /etc/clamav/clamd.conf".format(pattern))
|
|
else:
|
|
user = "clamupdate"
|
|
utils.exec_cmd(
|
|
"perl -pi -e 's/^Example/#Example/' /etc/freshclam.conf")
|
|
utils.exec_cmd(
|
|
"""cat <<EOM >> /usr/lib/systemd/system/clamd@.service
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOM
|
|
""")
|
|
|
|
if utils.dist_name == "ubuntu":
|
|
# Stop freshclam daemon to allow manual download
|
|
utils.exec_cmd("service clamav-freshclam stop")
|
|
utils.exec_cmd("freshclam", sudo_user=user)
|
|
utils.exec_cmd("service clamav-freshclam start")
|
|
else:
|
|
utils.exec_cmd("freshclam", sudo_user=user)
|