#!/usr/bin/bash

function echoAndRun(){
    hline
    echo
    echo "[root@dcu ~]# "$1;
    eval $1 ;
    echo;
}

# 日志函数
function log() {
    [ $QUIET_MODE -eq 0 ] && echo "$@"
}

function hline() {
    printf "%0.s=" {1..60}
    echo
}


## 标准化提示信息格式
function head_normal() {
    echo -e "\n############$1############"
}

## 必要依赖检查及安装
function pkg_check() {
    local pkgs_debian=(dmidecode lshw pciutils numactl-devel ipmitool locate)
    local pkgs_centos=(dmidecode lshw pciutils numactl-dev ipmitool mlocate)
    local cmd=(dmidecode lshw lspci numactl ipmitool locate)

    for ((i=0; i<${#cmd[@]}; i++)); do
        if ! command -v ${cmd[i]} &>/dev/null; then
            if command -v apt-get &>/dev/null; then
                echo "没有${cmd[i]} 命令，请先安装${pkgs_debian[i]}"
                exit 0
                # apt-get install -y ${pkgs_debian[i]}
            elif command -v yum &>/dev/null; then
                echo "没有${cmd[i]} 命令，请先安装${pkgs_centos[i]}"
                # yum install -y ${pkgs_centos[i]}
                exit 0
            fi
        fi
    done
}
