#!/bin/bash

_install() {
    if [[ $OS == "CentOS6" ]];then
        # Enable
        local softs="smartd mcelogd"
    
        for soft in $softs
        do
            service $soft start > /dev/null 2>&1
            chkconfig $soft on > /dev/null 2>&1
        done
    
        # Disable
        local DisableService='ipmi ipmi_port NetworkManager postfix lldpd'
        for soft in $DisableService
        do
            service $soft stop > /dev/null 2>&1
            chkconfig $soft off > /dev/null 2>&1
        done

    elif [[ $OS == "CentOS7" ]];then
        # Enable
        local softs="smartd mcelog"

        for soft in $softs
        do
            systemctl start $soft > /dev/null 2>&1
            systemctl enable $soft > /dev/null 2>&1
        done
        # Disable
        local DisableService='chronyd firewalld ipmi NetworkManager postfix avahi-daemon lldpd'
        for soft in $DisableService
        do
            systemctl disable $soft > /dev/null 2>&1
            systemctl stop $soft > /dev/null 2>&1
        done

    else
        PRINT_ERR "Not support OS '$OS'"
        return 1
    fi

    return 0

}

_check() {
    _check="PASS"
    if [[ $OS == "CentOS6" ]];then
        local softs="smartd mcelogd"
    
        for soft in $softs
            do
            if [[ $(chkconfig --list |grep $soft | grep -c :on) -eq 0 ]]; then
                _check="FAIL"
                PRINT_ERR "[ERROR] $soft Not Enabled In Chkconfig List"
            fi
            done
    
        local DisableService='ipmi ipmi_port NetworkManager postfix lldpd'
        for soft in $DisableService
        do
            if [[ $(chkconfig --list |grep $soft | grep -c :on) -ne 0 ]]; then
                _check="FAIL"
                PRINT_ERR "[ERROR] $soft Enabled In Chkconfig List"
            fi
        done

    elif [[ $OS == "CentOS7" ]];then
        if [[ $ARCH == 'x86_64' ]];then
            local softs="smartd mcelog"
        else
            local softs="smartd"
        fi

        for soft in $softs
        do
            systemctl is-enabled "$soft" >/dev/null 2>&1
            if [[ $? -ne 0 ]]; then
                _check="FAIL"
                PRINT_ERR "[ERROR] $soft Not Enabled In Chkconfig List"
            fi
        done

        local DisableService='chronyd firewalld ipmi NetworkManager postfix avahi-daemon lldpd'
        for soft in $DisableService
        do
            systemctl is-enabled "$soft" >/dev/null 2>&1
            if [[ $? -eq 0 ]]; then
                _check="FAIL"
                PRINT_ERR "[ERROR] $soft Enabled In systemd"
            fi
        done
    else
        PRINT_ERR "Not support OS '$OS'"
        return 1
    fi


}
