#!/bin/bash

source /OSM/script/os_load_base.sh

function PATCH_START()
{
    return 
}
function PATCH_END()
{
    #通过ELF格式区分二进制文件与压缩文件，回显/OSM/bin/upgrade_atom: ELF 64-bit LSB executable, x86-64,
    local red=$(file /OSM/bin/omm_upd_agent.bin | awk '{print $2}')	
    if [ "$red" != "ELF" ]; then
        chmod 770 /OSM/bin/omm_upd_agent.bin
        mv /OSM/bin/omm_upd_agent.bin /OSM/bin/omm_upd_agent.bin.tgz
        tar -xzf /OSM/bin/omm_upd_agent.bin.tgz -C /OSM/bin
        chmod 770 /OSM/bin/omm_upd_agent.bin
        rm -f /OSM/bin/omm_upd_agent.bin.tgz
        OS_echo "UPGRADE_SH: finish to decompress and replace omm_upd_agent.bin"
    else
        OS_echo "UPGRADE_SH: no need to decompress and replace omm_upd_agent.bin"
    fi
	
    return
}
function PATCH_ROLLSTART()
{
    return
}
function PATCH_ROLLEND()
{
    #通过ELF格式区分二进制文件与压缩文件，回显/OSM/bin/upgrade_atom: ELF 64-bit LSB executable, x86-64,
    local red=$(file /OSM/bin/omm_upd_agent.bin | awk '{print $2}')	
    if [ "$red" != "ELF" ]; then
        chmod 770 /OSM/bin/omm_upd_agent.bin
        mv /OSM/bin/omm_upd_agent.bin /OSM/bin/omm_upd_agent.bin.tgz
        tar -xzf /OSM/bin/omm_upd_agent.bin.tgz -C /OSM/bin
        chmod 770 /OSM/bin/omm_upd_agent.bin
        rm -f /OSM/bin/omm_upd_agent.bin.tgz
        OS_echo "UPGRADE_SH: finish to decompress and replace omm_upd_agent.bin"
    else
        OS_echo "UPGRADE_SH: no need to decompress and replace omm_upd_agent.bin"
    fi
	
    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

