#!/bin/bash
# 检查当前执行用户
ope_flag=$1
checkID()
{
    idInfo="$(id)"
    for f_idInfo in "${idInfo[@]}"
    do
        if [[ "${f_idInfo}" =~ "uid" ]]
        then
            if [[ "${f_idInfo}" =~ "root" ]]
            then
                return 0
            else
               logger  -p local0.error "user: `who -m | cut -d\( -f2 |cut -d\) -f1`, execute ${BASH_SOURCE} failed: The script must run with root user."
               exit 1
            fi
        else
            continue
        fi
    done
    logger  -p local0.error "user: `who -m | cut -d\( -f2 |cut -d\) -f1`, execute ${BASH_SOURCE} failed: The script must run with root user."
    exit 1
}
anti_reinforce()
{
    if [[ "${ope_flag}" == disable  || "${ope_flag}" == enable  ]];then
        systemctl "${ope_flag}" ossipmc
        if [[ $? != 0 ]];then
            logger  -p local0.error "excute forbid ossipmc "${ope_flag}" failed."
            exit 1
        else
            logger  -p local0.info "excute forbid ossipmc "${ope_flag}" success."
            exit 0
        fi
    else
        logger  -p local0.error "Invalid parameter."
        exit 1
    fi
}

checkID

anti_reinforce || exit 1

# 执行完成后删除各节点的提权包
su - ossadm -c "rm -rf /home/ossadm/forbid_chkconfig_pkg.tar"

