#!/bin/bash
#!/bin/sh

# 裸机-点播独占-汇聚 软中断设置
func_bdhj_setup_irq(){
    if [ $(cat  /etc/rc.local | grep -c sirq) -eq 0 ];then
        wget -O /usr/local/basic/sirq.sh http://tw15b0178.onething.net:9090/tool/bd_config/sirq.sh
        chmod +x /usr/local/basic/sirq.sh
        bash /usr/local/basic/sirq.sh
        sed -i  '/exit 0/d' /etc/rc.local
        echo '/usr/local/basic/sirq.sh' >> /etc/rc.local 
        echo 'exit 0' >> /etc/rc.local 
        if [ $(cat /usr/local/basic/sirq.sh | wc -l) -eq 0 ] || [ $(cat /etc/rc.local | grep -c sirq) -eq 0 ];then
            echo -e "##Result-: $(echo $rhostname) : fail,网卡软中断设置失败...\n"
        fi
    fi  
}

# 裸机-点播独占-汇聚 升级插件 
func_bdhj_setup_plus(){

    #ps axuf | grep  '/usr/local/xyvod/xyapp/xyipk/bin/xyipk' | grep -v grep | awk '{print$2}' | xargs kill -9


    # 升级dc插件
    dc_ver=$(xycall info  plugin-datacollect | grep -E "local_version" | grep -c '2.12.74')
    if [ ${dc_ver} -ne 1 ];then
        xycall installurl http://tw15b0178.onething.net:9090/tool/bd_config/plugin-datacollect_2.12.74_xybm.ipk
        ret=$?
        if [ ${ret} -ne 0 ];then
            echo -e "##Result-: $(echo $rhostname) : fail,plugin-datacollect版本更新失败,要求版本:2.12.74...\n"
        fi
    fi

    # 升级ne插件
    ne_ver=$(xycall info  plugin-nodeexporter | grep -E "local_version" | grep -c '1.6.5')
    if [ ${ne_ver} -ne 1 ];then
        xycall installurl http://tw15b0178.onething.net:9090/tool/bd_config/plugin-nodeexporter_1.6.5_xybm.ipk
        ret=$?
        if [ ${ret} -ne 0 ];then
            echo -e "##Result-: $(echo $rhostname) : fail,plugin-nodeexporter版本更新失败,要求版本:1.6.5...\n"
        fi
    fi

    # 升级netd插件
    netd_ver=$(xycall info  plugin-netd | grep -E "local_version" | grep -c '1.24.6')
    if [ ${netd_ver} -ne 1 ];then
        xycall installurl http://tw15b0178.onething.net:9090/tool/bd_config/plugin-netd_1.24.6_xybm.ipk
        ret=$?
        if [ ${ret} -ne 0 ];then
            echo -e "##Result-: $(echo $rhostname) : fail,plugin-netd版本更新失败,要求版本:1.24.6...\n"
        fi
    fi

    # 升级flume插件
    flume_ver=$(xycall info plugin-flume | grep -E "local_version" | grep -c '1.11.30')
    if [ ${flume_ver} -ne 1 ];then
        xycall installurl http://tw15b0178.onething.net:9090/tool/bd_config/plugin-flume_1.11.30_xybm.ipk
        ret=$?
        if [ ${ret} -ne 0 ];then
            echo -e "##Result-: $(echo $rhostname) : fail,plugin-flume版本更新失败,要求版本:1.11.30...\n"
        fi
    fi
}

# 裸机-点播独占-汇聚 关闭ipv6
func_bdhj_setup_ipv6(){
    ret=$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)
    if [ $ret -eq 0 ];then
        chattr  -i /etc/sysctl.conf
        echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
        sysctl -p     
        chattr  +i /etc/sysctl.conf
        ret1=$(cat /proc/sys/net/ipv6/conf/all/disable_ipv6)
        if [ $ret1 -eq 0 ];then
            echo -e "##Result-: $(echo $rhostname) : fail,禁用ipv6设置失败,请检查....\n"
        fi
    fi
}

# 执行函数
func_bdhj_setup_irq
func_bdhj_setup_plus
#func_bdhj_setup_ipv6
