#!/bin/bash

rpm_list() {
    local need_install_rpms
    if [[ $ARCH = 'x86_64' ]];then
        #local need_install_rpms=`/usr/bin/python $BASEDIR/utils/GetApolloConf.py "installrpms" "$OS".install`
        # 配置中心的这个配置超长文本，维护性太差
        need_install_rpms='mcelog deltarpm lsscsi wget fping curl sudo openssl openssl-devel iptables crash bc sysstat blktrace iftop iperf iptraf-ng net-snmp net-snmp-devel net-snmp-utils ruby ruby-devel rubygems ssmtp scapy python python-devel ntpdate gcc libxslt libxslt-devel java-1.6.0-openjdk vim-enhanced zookeeper-3.3.5-3.3.5-1.x86_64 tcpdump hwdata ulshell jq uroot'

        if [[ $OS = 'CentOS6' ]];then
            need_install_rpms="$need_install_rpms tunctl libevent-2.0.19-stable libpcap-1.4.0 python-pip"
        elif [[ $OS = 'CentOS7' ]];then
            need_install_rpms="$need_install_rpms net-tools iptables-services libevent-2.0.21-4.el7.x86_64 hdparm libcgroup-tools kernel-tools device-mapper-libs cyrus-sasl* gnutls-utils python2-pip"
        fi
    elif [[ $ARCH = 'aarch64' ]];then
        need_install_rpms='net-tools wget curl fping sudo openssl openssl-devel sysstat ntpdate vim-enhanced tcpdump iptables lldpd mstflint python2-pip jq'
    fi
    echo $need_install_rpms
}

_install() {
    yum clean all > /dev/null 2>&1
    yum makecache > /dev/null 2>&1
    
    yum -y -q remove 'lldpad' > /dev/null 2>&1
    yum -y -q install `rpm_list` > /dev/null 2>&1

}


_check() {
    _check="PASS"

    for pkg in `rpm_list`
    do
        if ! rpm --quiet -q "${pkg//\*/}" ;then
            _check="FAIL"
            PRINT_ERR "[ERROR] $pkg Not Installed."
        fi
    done
    if [[ $ARCH != 'x86_64' ]];then
        if rpm --quiet -q 'lldpad' ;then
            _check="FAIL"
            PRINT_ERR "[ERROR] lldpad Installed."
        fi
        if ! rpm --quiet -q "kernel-tools" ;then
            _check="FAIL"
            PRINT_ERR "[ERROR] kernel-tools not Installed."
        fi

        # tcpdump check
        #rpm -q tcpdump|grep -q ucloud
        #if [[ $? -ne 0 ]];then
        #    _check="FAIL"
        #    PRINT_ERR "[ERROR] Tcpdump Version Not Correct."
        #fi
    fi

}
