#!/bin/bash

_install() {
    yum clean all > /dev/null 2>&1
    yum makecache > /dev/null 2>&1
    if [[ $OS == "CentOS6" ]];then
        local need_install_rpms='net-tools ntp wget curl fping sudo openssl openssl-devel sysstat ntpdate vim tcpdump iptables iftop'
    elif [[ $OS == "CentOS7" ]];then
        local need_install_rpms='net-tools ntp wget curl fping sudo openssl openssl-devel sysstat ntpdate vim tcpdump iptables iptables-services iftop'
    else
        PRINT_ERR "Not support OS '$OS'"
        return 1
    fi

    yum -y -q install $need_install_rpms > /dev/null 2>&1
    return 0

}


_check() {
    _check="PASS"

    if [[ $OS == "CentOS6" ]];then
        local need_install_rpms='net-tools ntp wget curl fping sudo openssl openssl-devel sysstat ntpdate tcpdump iptables iftop vim-enhanced'
    elif [[ $OS == "CentOS7" ]];then
        local need_install_rpms='net-tools ntp wget curl fping sudo openssl openssl-devel sysstat ntpdate tcpdump iptables iptables-services iftop vim-enhanced'
    else
        PRINT_ERR "Not support OS '$OS'"
        return 1
    fi

    for pkg in $need_install_rpms
    do
        if ! rpm -q "$pkg" &>> /dev/null;then
            _check="FAIL"
            PRINT_ERR "[ERROR] $pkg Not Installed."
        fi
    done

    # tcpdump check
    if [[ `rpm -qa|grep tcpdump|grep -c ucloud` -eq 0 ]];then
        _check="FAIL"
        PRINT_ERR "[ERROR] Tcpdump Version Not Correct."
    fi
}
