#!/bin/bash

_install() {
    cat >> /etc/rc.local.d/001-ops-firstrun.sh <<EOF
touch /var/lock/subsys/local

# Load kernel module
depmod -a

# Load sysctl.conf
sysctl -p

# disable memory compaction on page fault
echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag

# CpuPerfMode
bash /opt/op/changeCpuPerfMode.sh

sysctl -w kernel.nmi_panic_count_threshold=3
sysctl -w kernel.nmi_panic_count_interval=5
exit 0

EOF

    if [[ $(uname -r) =~ "2.6.32" ]];then
        echo -e "\n# gso enable\necho 1 > /proc/net/gso_size_enable" >> /etc/rc.local.d/001-ops-firstrun.sh
        # > 4.1.0-19 No Need microcode_ctl
        if [[ $Usage = "uhost" ]];then
            echo -e "\n# Load microcode\nmicrocode_ctl -u\nbash /opt/op/reload_microcode.sh" >> /etc/rc.local.d/001-ops-firstrun.sh
        fi
    fi

    chmod +x /etc/rc.local.d/001-ops-firstrun.sh
    bash /etc/rc.local.d/001-ops-firstrun.sh >/dev/null 2>&1
    return 0

}

_check() {
    _check="PASS"
    if [ ! -s "/etc/rc.local.d/001-ops-firstrun.sh" ];then
        _check="FAIL"
        PRINT_ERR "[ERROR] File 001-ops-firstrun.sh not found in /etc/rc.local.d/"
    fi
    grep -q "gso_size_enable" /etc/rc.local.d/001-ops-firstrun.sh
    if [[ $? -ne 0 && $(uname -r) =~ "2.6.32" ]];then
        _check="FAIL"
        PRINT_ERR "[ERROR] gso_size_enable Not Found In /etc/rc.local.d/001-ops-firstrun.sh"
    fi

}
