#!/bin/bash
# Copyright (c) Huawei Technologies Co., Ltd. 2019-2020. All rights reserved.
# Description: up start restart wall msg
# Author: chengjike

BASIC_LIB_DIR="/UltraPath_NVMe/install/linuxTools/globalLib"
CHECK_LIBFILE="${BASIC_LIB_DIR}/check_lib.sh"
OS_LIBFILE=${OS_LIBFILE="${BASIC_LIB_DIR}/os_lib.sh"}
if [ -f "${CHECK_LIBFILE}" ] && [ -f "${OS_LIBFILE}" ]
then
    . "${CHECK_LIBFILE}"
    . "${OS_LIBFILE}"
else
    echo -e "ERROR: not found the lib[${CHECK_LIBFILE}] or [${OS_LIBFILE}]."
    exit 1
fi

WARN_MSG_FILE="/opt/UltraPath_NVMe/wall_msg"

function create_wall_msg()
{
    os_check_sanboot
    if [ $? -ne 0 ]; then
        echo "this is a message send by ultrapath-nvme, for avoiding duplicated disks caused data corruption, it is strongly recommended to restart your system or active ultrapath-nvme manually." > ${WARN_MSG_FILE}
        echo "To active ultrapath-nvme, first run \"service ultrapath-nvme stop\" or \"/etc/init.d/ultrapath-nvme stop\" to stop service, then run \"service ultrapath-nvme start\" or \"/etc/init.d/ultrapath-nvme start\" to start service." >> ${WARN_MSG_FILE}  
    else
        echo "this is a message send by ultrapath-nvme, for avoiding duplicated disks caused data corruption, it is strongly recommended to restart your system." > ${WARN_MSG_FILE}
    fi
 
    echo "To disable this warning message, please run \"stop_up_restart_warn_plus\" by a root user." >> ${WARN_MSG_FILE}
    chmod 600 ${WARN_MSG_FILE}
    basic_trace_operate "SUCCESS" "1396799567" "start wall msg" "start restart wall message" "ʾϢ"
}

#main start
create_wall_msg
sleep 900
while [ "" = "" ]
do
    wall < ${WARN_MSG_FILE}        
    sleep 900       
done

rm -rf ${WARN_MSG_FILE}
