diff --git a/clamdscan/CMakeLists.txt b/clamdscan/CMakeLists.txt index f300024431..134b5b3b3e 100644 --- a/clamdscan/CMakeLists.txt +++ b/clamdscan/CMakeLists.txt @@ -47,3 +47,24 @@ if(WIN32) else() install(TARGETS clamdscan DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs) endif() + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamdscan@.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.service @ONLY) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamdscan@.timer.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.timer @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.service + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.service + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.timer + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.timer + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) +endif() diff --git a/clamdscan/clamav-clamdscan@.service.in b/clamdscan/clamav-clamdscan@.service.in new file mode 100644 index 0000000000..01dc2a87ab --- /dev/null +++ b/clamdscan/clamav-clamdscan@.service.in @@ -0,0 +1,8 @@ +[Unit] +Description=ClamAV clamdscan %f +Documentation=man:clamdscan(1) man:clamdscan.conf(5) https://docs.clamav.net/ + +[Service] +Nice=19 +IOSchedulingClass=idle +ExecStart=@prefix@/bin/clamdscan --infected --multiscan --fdpass %f diff --git a/clamdscan/clamav-clamdscan@.timer.in b/clamdscan/clamav-clamdscan@.timer.in new file mode 100644 index 0000000000..381fd93314 --- /dev/null +++ b/clamdscan/clamav-clamdscan@.timer.in @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly ClamAV clamdscan %f + +[Timer] +OnCalendar=weekly +AccuracySec=1h +RandomizedDelaySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/clamscan/CMakeLists.txt b/clamscan/CMakeLists.txt index ab0863544c..82e1dd1ca7 100644 --- a/clamscan/CMakeLists.txt +++ b/clamscan/CMakeLists.txt @@ -46,3 +46,24 @@ if(WIN32) else() install(TARGETS clamscan DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs) endif() + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamscan@.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.service @ONLY) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamscan@.timer.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.timer @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.service + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.service + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.timer + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.timer + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) +endif() diff --git a/clamscan/clamav-clamscan@.service.in b/clamscan/clamav-clamscan@.service.in new file mode 100644 index 0000000000..2960611508 --- /dev/null +++ b/clamscan/clamav-clamscan@.service.in @@ -0,0 +1,8 @@ +[Unit] +Description=ClamAV clamscan %f +Documentation=man:clamscan(1) man:clamscan.conf(5) https://docs.clamav.net/ + +[Service] +Nice=19 +IOSchedulingClass=idle +ExecStart=@prefix@/bin/clamscan --recursive=yes --infected --suppress-ok-results %f diff --git a/clamscan/clamav-clamscan@.timer.in b/clamscan/clamav-clamscan@.timer.in new file mode 100644 index 0000000000..d74c432ce8 --- /dev/null +++ b/clamscan/clamav-clamscan@.timer.in @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly ClamAV clamscan %f + +[Timer] +OnCalendar=weekly +AccuracySec=1h +RandomizedDelaySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/cmake/FindSYSTEMD.cmake b/cmake/FindSYSTEMD.cmake index 5c02947be6..0680fb1223 100644 --- a/cmake/FindSYSTEMD.cmake +++ b/cmake/FindSYSTEMD.cmake @@ -110,16 +110,29 @@ pkg_check_modules(SYSTEMD_PROGRAM QUIET systemd) if (SYSTEMD_PROGRAM_FOUND) if ("${SYSTEMD_UNIT_DIR}" STREQUAL "") - # Use pkg-config to look up the systemd unit install directory + # Use pkg-config to look up the systemd system unit install directory execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=systemdsystemunitdir systemd OUTPUT_VARIABLE SYSTEMD_UNIT_DIR) string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNIT_DIR "${SYSTEMD_UNIT_DIR}") endif() - message(STATUS "systemd services install dir: ${SYSTEMD_UNIT_DIR}") + message(STATUS "systemd system services install dir: ${SYSTEMD_UNIT_DIR}") + + if ("${SYSTEMD_USER_UNIT_DIR}" STREQUAL "") + # Use pkg-config to look up the systemd user unit install directory + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} + --variable=systemduserunitdir systemd + OUTPUT_VARIABLE SYSTEMD_USER_UNIT_DIR) + string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_USER_UNIT_DIR "${SYSTEMD_USER_UNIT_DIR}") + endif() + + message(STATUS "systemd user services install dir: ${SYSTEMD_USER_UNIT_DIR}") else() if (SYSTEMD_UNIT_DIR) message (FATAL_ERROR "SYSTEMD_UNIT_DIR was defined but pkg-config was not able to find systemd!") endif() + if (SYSTEMD_USER_UNIT_DIR) + message (FATAL_ERROR "SYSTEMD_USER_UNIT_DIR was defined but pkg-config was not able to find systemd!") + endif() endif()