#!/bin/bash
source /OSM/script/os_load_base.sh
SYSDISK_TIMESTAMP=/OSM/coffer_data/fdsa/sysdiskcheck_timestamp_sph60
DIRECTORY_SYSDISK_TIMESTAMP=/OSM/coffer_data/fdsa
PATH_SYSDISK_CHECK=/OSM/fdsa/plugins/common/fdsa_check_sysdisk.sh

PATCH_START()
{
    OS_echo " V5R7C61SPH60 start."
    if [ ! -f "${SYSDISK_TIMESTAMP}" ];then
        if [ ! -d "${DIRECTORY_SYSDISK_TIMESTAMP}" ];then
            OS_echo " V5R7C61SPH60 ${DIRECTORY_SYSDISK_TIMESTAMP} check not exist,then create."
            mkdir -p ${DIRECTORY_SYSDISK_TIMESTAMP}
        fi
        touch ${SYSDISK_TIMESTAMP}
        timestamp=$(date +%s)
        echo $timestamp > ${SYSDISK_TIMESTAMP}
        OS_echo " V5R7C61SPH60 create ${SYSDISK_TIMESTAMP} and write time $timestamp."
    fi
	OS_echo " V5R7C61SPH60 end."
    return
}

PATCH_END()
{
    chmod 550 ${PATH_SYSDISK_CHECK}
    return 0
}

PATCH_ROLLBACK()
{
    return 0
}

PATCH_ROLLEND()
{
    OS_echo " V5R7C61SPH60 PATCH_ROLLEND start."
    chmod 550 ${PATH_SYSDISK_CHECK}
	if [ -d "${DIRECTORY_SYSDISK_TIMESTAMP}" ];then
        OS_echo " V5R7C73SPH120 delete ${DIRECTORY_SYSDISK_TIMESTAMP}."
        rm -rf ${DIRECTORY_SYSDISK_TIMESTAMP}
    fi
	OS_echo " V5R7C61SPH60 PATCH_ROLLEND end."
    return 0
}

#--------------------------------- main ----------------------

#根据命令执行脚本
L_CMD=$1
case $L_CMD in
    "start") PATCH_START
               ;;
    "end") PATCH_END
               ;;
    "rollstart") PATCH_ROLLBACK
               ;;
    "rollend") PATCH_ROLLEND
               ;;
    *)
    echo "unsupported option."
esac
exit 0