diff --git a/install_amavis.sh b/install_amavis.sh index 10759a9..4e5c99a 100755 --- a/install_amavis.sh +++ b/install_amavis.sh @@ -60,6 +60,35 @@ echo_skipped() { echo -e "\033[80G[ \033[33m\033[1mskipped\033[m ]" } +detect_os_1 () { + + if $(which lsb_release > /dev/null 2>&1) ; then + + os_dist="$(lsb_release -i | awk '{print tolower($3)}')" + os_version="$(lsb_release -r | awk '{print tolower($2)}')" + os_codename="$(lsb_release -c | awk '{print tolower($2)}')" + + if [[ "$os_dist" = "debian" ]]; then + if $(echo "$os_version" | grep -q '\.') ; then + os_version=$(echo "$os_version" | cut --delimiter='.' -f1) + fi + fi + + elif [[ -e "/etc/os-release" ]]; then + + . /etc/os-release + + os_dist=$ID + os_version=${VERSION_ID} + + fi + + # remove whitespace from os_dist and os_version + os_dist="${os_dist// /}" + os_version="${os_version// /}" + +} + # - Is this a systemd system? # - @@ -69,6 +98,13 @@ else systemd_exists=true fi +# - Set variable +# - os_dist +# - os_version +# - os_codename +# - +detect_os_1 + echo "" @@ -2752,10 +2788,8 @@ if $INSTALL_CLAMAV_UNOFFICIAL_SIGS ; then error "$(cat $tmp_err_msg)" fi - ## - For Debian Jessie (Debian 8) - ## - - echononl " At directory /etc/clamav-unofficial-sigs copy os.debian8.conf to os.conf" - cp /etc/clamav-unofficial-sigs/os.debian8.conf /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + echononl " Copy readme file 'INSTALL' into '/etc/clamav-unofficial-sigs/'.." + cp -a /tmp/clamav-unofficial-sigs/INSTALL /etc/clamav-unofficial-sigs/INSTALL > $tmp_err_msg 2>&1 if [[ $? -eq 0 ]] ; then echo_ok else @@ -2763,67 +2797,91 @@ if $INSTALL_CLAMAV_UNOFFICIAL_SIGS ; then error "$(cat $tmp_err_msg)" fi - ## - Edit /etc/clamav-unofficial-sigs/os.conf and make changes if needed - ## - - ## - Maybe the following changes are needed: - ## - clam_user="clamav" - ## - clam_group="clamav" - ## - - ## - clamd_pid="/var/run/clamav/clamd.pid" - ## - - ## - clamd_restart_opt="systemctl restart clamav-daemon" - ## - clamd_reload_opt="systemctl reload clamav-daemon" - ## - or if debian 7 - ## - clamd_restart_opt="service clamav-daemon restart" - ## - clamd_reload_opt="service clamav-daemon reload" - ## - - ## - clamd_socket="/var/run/clamav/clamd.ctl" - ## - - echononl " Adjust /etc/clamav-unofficial-sigs/os.conf" - installation_failed=false - perl -i -n -p -e "s#^([ ]*\ *)(clam_user=.*)#\#\#\1\2\nclam_user=\"clamav\"#" \ - /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 - if [[ "$?" -ne 0 ]] ; then - installation_failed=true - error "$(cat $tmp_err_msg)" - fi - perl -i -n -p -e "s#^([ ]*\ *)(clam_group=.*)#\#\#\1\2\nclam_group=\"clamav\"#" \ - /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 - if [[ "$?" -ne 0 ]] ; then - installation_failed=true - error "$(cat $tmp_err_msg)" - fi - perl -i -n -p -e "s#^([ ]*\ *)(clamd_pid=.*)#\#\#\1\2\nclamd_pid=\"/var/run/clamav/clamd.pid\"#" \ - /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 - if [[ "$?" -ne 0 ]] ; then - installation_failed=true - error "$(cat $tmp_err_msg)" - fi + + if [[ "${os_dist,,}" = "debian" ]] ; then + if [[ "$os_version" = "8" ]] || [[ "$os_version" = "9" ]] || [[ "$os_version" = "10" ]] ; then + ## - For Debian Jessie (Debian 8) // Stretch (Debian 9) // Buster (Debian 10) + ## - + echononl " At directory /etc/clamav-unofficial-sigs copy os.debian${os_version}.conf to os.conf" + cp /etc/clamav-unofficial-sigs/os.debian${os_version}.conf /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ $? -eq 0 ]] ; then + echo_ok + else + echo_failed + error "$(cat $tmp_err_msg)" + fi - if $systemd_exists ; then - perl -i -n -p -e "s#^([ ]*\#?\ *)(clamd_restart_opt=.*)#\#\#\1\2\nclamd_restart_opt=\"systemctl restart clamav-daemon\"\nclamd_reload_opt=\"systemctl reload clamav-daemon\"#" \ - /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 - if [[ "$?" -ne 0 ]] ; then - installation_failed=true - error "$(cat $tmp_err_msg)" - fi - else - perl -i -n -p -e "s#^([ ]*\#?\ *)(clamd_restart_opt=.*)#\#\#\1\2\nclamd_restart_opt=\"service clamav-daemon restart\"\nclamd_reload_opt=\"service clamav-daemon reload\"#" \ - /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 - if [[ "$?" -ne 0 ]] ; then - installation_failed=true - error "$(cat $tmp_err_msg)" - fi - fi - perl -i -n -p -e "s#^([ ]*\#?\ *)(clamd_socket=.*)#\#\#\1\2\nclamd_socket=\"/var/run/clamav/clamd.ctl\"#" \ - /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 - if [[ "$?" -ne 0 ]] ; then - installation_failed=true - error "$(cat $tmp_err_msg)" - fi - if ! $installation_failed ; then - echo_ok - fi + ## - Edit /etc/clamav-unofficial-sigs/os.conf and make changes if needed + ## - + ## - Maybe the following changes are needed: + ## - clam_user="clamav" + ## - clam_group="clamav" + ## - + ## - clamd_pid="/var/run/clamav/clamd.pid" + ## - + ## - clamd_restart_opt="systemctl restart clamav-daemon" + ## - clamd_reload_opt="systemctl reload clamav-daemon" + ## - or if debian 7 + ## - clamd_restart_opt="service clamav-daemon restart" + ## - clamd_reload_opt="service clamav-daemon reload" + ## - + ## - clamd_socket="/var/run/clamav/clamd.ctl" + ## - + echononl " Adjust /etc/clamav-unofficial-sigs/os.conf" + installation_failed=false + perl -i -n -p -e "s#^([ ]*\ *)(clam_user=.*)#\#\#\1\2\nclam_user=\"clamav\"#" \ + /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ "$?" -ne 0 ]] ; then + installation_failed=true + error "$(cat $tmp_err_msg)" + fi + perl -i -n -p -e "s#^([ ]*\ *)(clam_group=.*)#\#\#\1\2\nclam_group=\"clamav\"#" \ + /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ "$?" -ne 0 ]] ; then + installation_failed=true + error "$(cat $tmp_err_msg)" + fi + perl -i -n -p -e "s#^([ ]*\ *)(clamd_pid=.*)#\#\#\1\2\nclamd_pid=\"/var/run/clamav/clamd.pid\"#" \ + /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ "$?" -ne 0 ]] ; then + installation_failed=true + error "$(cat $tmp_err_msg)" + fi + + if $systemd_exists ; then + perl -i -n -p -e "s#^([ ]*\#?\ *)(clamd_restart_opt=.*)#\#\#\1\2\nclamd_restart_opt=\"systemctl restart clamav-daemon\"\nclamd_reload_opt=\"systemctl reload clamav-daemon\"#" \ + /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ "$?" -ne 0 ]] ; then + installation_failed=true + error "$(cat $tmp_err_msg)" + fi + else + perl -i -n -p -e "s#^([ ]*\#?\ *)(clamd_restart_opt=.*)#\#\#\1\2\nclamd_restart_opt=\"service clamav-daemon restart\"\nclamd_reload_opt=\"service clamav-daemon reload\"#" \ + /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ "$?" -ne 0 ]] ; then + installation_failed=true + error "$(cat $tmp_err_msg)" + fi + fi + perl -i -n -p -e "s#^([ ]*\#?\ *)(clamd_socket=.*)#\#\#\1\2\nclamd_socket=\"/var/run/clamav/clamd.ctl\"#" \ + /etc/clamav-unofficial-sigs/os.conf > $tmp_err_msg 2>&1 + if [[ "$?" -ne 0 ]] ; then + installation_failed=true + error "$(cat $tmp_err_msg)" + fi + if ! $installation_failed ; then + echo_ok + fi + else + error "Cannot create file 'os.conf' (No Debian Version detected). + See file /etc/clamav-unofficial-sigs/INSTALL to create it manually" + fi + + else + + error "Cannot create file 'os.conf' (No Linux Distribution detected) + See file /etc/clamav-unofficial-sigs/INSTALL to create it manually" + fi # if [[ "${os_dist,,}" = "debian" ]] echononl " Adjust /etc/clamav-unofficial-sigs/user.conf"