#!/bin/bash
source /OSM/script/os_load_base.sh

function PATCH_START()
{
    return 
}

function PATCH_END()
{
    #cli
    #back
    mkdir -p /ISM/cli_patch_bak_sph060/cmd_autogen
    cp /OSM/script/os_debug_mode_process_guest.sh /ISM/cli_patch_bak_sph060/
    cp -rf /ISM/cli/libcmdhandler.so /ISM/cli_patch_bak_sph060/
    cp -rf /ISM/cli/cmd_autogen/change.notification.syslog /ISM/cli_patch_bak_sph060/cmd_autogen/
    cp -rf /ISM/cli/cmd_autogen/show.notification.syslog /ISM/cli_patch_bak_sph060/cmd_autogen/
    cp -rf /ISM/cli/cmd_autogen/change.disk_reliability_policy.slow_disk_detect /ISM/cli_patch_bak_sph060/cmd_autogen/
    
    #install
    mkdir -p /ISM/cli_patch_sph060
    tar -zxvf /ISM/cli_sph060_DTS2024010914388.tar.gz -C /ISM/cli_patch_sph060/
    cp -f /ISM/cli_patch_sph060/os_debug_mode_process_guest.sh /OSM/script/
    cp -rf /ISM/cli_patch_sph060/cmd_autogen/* /ISM/cli/cmd_autogen/
    chmod 550 /OSM/script/os_debug_mode_process_guest.sh
    
    cp -f /ISM/cli_patch_sph060/os_debug_mode_process_moniter.sh /OSM/script/
    chmod 550 /OSM/script/os_debug_mode_process_moniter.sh

    install /ISM/cli_patch_sph060/libcmdhandler.so /ISM/cli/
    chown OceanStorMgrUser:mgrgroup /ISM/cli/libcmdhandler.so
    chmod 500 /ISM/cli/libcmdhandler.so
    
    killall -s 9 CLI_Server
    rm -rf /ISM/cli_patch_sph060

    return
}

function PATCH_ROLLSTART()
{
    #cli
    cp -rf /ISM/cli_patch_bak_sph060/os_debug_mode_process_guest.sh /OSM/script/
    chmod 550 /OSM/script/os_debug_mode_process_guest.sh

    install /ISM/cli_patch_bak_sph060/libcmdhandler.so /ISM/cli/
    chown OceanStorMgrUser:mgrgroup /ISM/cli/libcmdhandler.so
    chmod 500 /ISM/cli/libcmdhandler.so

    cp -rf /ISM/cli_patch_bak_sph060/cmd_autogen/* /ISM/cli/cmd_autogen/
    
    rm -rf /OSM/script/os_debug_mode_process_moniter.sh

    killall -s 9 CLI_Server
    rm -rf /ISM/cli_patch_bak_sph060

    return
}

function PATCH_ROLLEND()
{
    return
}

#start：打补丁前需要执行的操作，脚本的执行时间点在替换文件前
#end：打补丁后需要执行的操作，脚本的执行时间点在替换文件后
#rollstart：回滚补丁时需要执行的操作，脚本的执行时间点在文件被恢复之前。
#rollend：回滚补丁时需要执行的操作，脚本的执行时间点在文件被恢复之后。

L_CMD=$1
OS_echo "command is $L_CMD"
case $L_CMD in
        "start") 
                PATCH_START
                ;;
        "end") 
                PATCH_END
                ;;
        "rollstart") 
                PATCH_ROLLSTART
                ;;
        "rollend") 
                PATCH_ROLLEND
                ;;
        *)
                OS_echo  "unsupported option."
esac
exit 0

