#本文件是一个开关，用于生成标志文件fdsa_sysdisk_switch
#该标志文件会在系统盘自愈的时候被检测(FDSA_RebootForSysdisk)
#如果该文件不存在，视为关，则系统盘修复直接上报告警，不设置网络引导标记
#如果该文件存在，视为开，则系统盘修复时设置网络引导标记



while getopts :h options
do
    case "$options" in
        h)
            echo "set_fdsa_sysdisk_switch.sh [-h] [on|off|show] :input 'on' to turn on fdsa_sysdisk_switch(if the system disk is faulty, FDSA will not reboot node.) or input 'off' to turn off fdsa_sysdisk_switch(if the system disk is faulty, FDSA will reboot node.) or input 'show' to show fdsa_sysdisk_switch"
            exit 1
            ;;
        \?)
            echo "usage: set_fdsa_sysdisk_switch.sh : input 'on' or 'off' or 'show' to turn on/off fdsa_sysdisk_switch or show fdsa_sysdisk_switch"
            exit 1
            ;;
    esac
done

TARGET_FILE_NAME=/OSM/coffer_log/log/heal/data/fdsa_sysdisk_switch
if [ ! -n "$1" ];then
    echo "need on parameter, 'on' or 'off' or 'show'."
    exit 1
fi
if [ "$1" == "on" ]
    then
    touch $TARGET_FILE_NAME
    fsync $TARGET_FILE_NAME
    echo "set switch on"
    exit 0
fi
if [ "$1" == "off" ]
    then
    rm -rf $TARGET_FILE_NAME
    echo "set switch off"
    exit 0
fi
if [ "$1" == "show" ]
    then
	if [ ! -f "$TARGET_FILE_NAME" ]; then
		echo "fdsa sysdisk switch is off"
	else
		echo "fdsa sysdisk switch is on"
    fi
	exit 0
fi
echo "invalid parameter, only 'on'\'off'\'show' is valid input"
exit 1