#!/bin/bash

# OEM bash from USEC by panda.xiong

BASH_CONFIG="$BASEDIR/configs/bash/bash"
MD5SUM_BASH="21971bca6c446944c9d2f308418d078f"

_install() {
    if [[ $ARCH == 'x86_64' ]];then
        local md5sum_bash_now=$(md5sum /bin/bash|awk '{print $1}')
        local md5sum_bash_new=$(md5sum $BASH_CONFIG|awk '{print $1}')

        if [[ $md5sum_bash_now != $MD5SUM_BASH && $md5sum_bash_new = $MD5SUM_BASH ]];then
            cp -f $BASH_CONFIG /bin/bash
            chmod a+x /bin/bash
        fi

        head /etc/profile |grep -q SSH_CONNECTION
        if [[ $? -ne 0 ]];then
            sed -i '1i# SSH_CONNECTION for sec' /etc/profile
            sed -i '2iif [[ ${#SSH_CONNECTION} -le 40 && -n ${LC_TELEPHONE} ]]; then SSH_CONNECTION=$LC_TELEPHONE-$SSH_CONNECTION; fi' /etc/profile
        fi
    fi

}

_check() {
    _check="PASS"
    if [[ $ARCH == 'x86_64' ]];then
        if [[ $(md5sum /bin/bash|awk '{print $1}') != $MD5SUM_BASH ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] Bash Md5sum Not Match With $MD5SUM_BASH."
        fi

        grep -q 'LC_TELEPHONE' /etc/profile
        if [[ $? -ne 0 ]];then
            _check="FAIL"
            PRINT_ERR "[ERROR] LC_TELEPHONE not in /etc/profile"
        fi
    fi
}
