#!/bin/sh
#
# Copyright (c) 2025 Citrix Systems, Inc. All rights reserved.
# This software and documentation contain valuable trade
# secrets and proprietary property belonging to Citrix Systems, Inc.
# None of this software and documentation may be copied,
# duplicated or disclosed without the express
# written permission of Citrix Systems, Inc.
#
# 08/14/25
#
# This file contains shell script code to be copied to rc.local.
#

SCRIPTS_DIR=/var/tmp/Mellanox/scripts
PWR_CYCLE_MGR_FILE_NAME=mellanox_fw_update_pwr_cycle_mgr
PWR_CYCLE_MGR_FILE=${SCRIPTS_DIR}/${PWR_CYCLE_MGR_FILE_NAME}
LOG_FILE="/var/log/mellanoxFw.log"

#
# Prints message, and logs it to the log file.
#
log_msg()
{
        echo -e "$*"
        echo -e "$*" >> $LOG_FILE
}

#
# Make sure the power cycle manager script exists
#
if [ ! -e ${PWR_CYCLE_MGR_FILE} ] ||
   [ ! -f ${PWR_CYCLE_MGR_FILE} ] ||
   [ ! -s ${PWR_CYCLE_MGR_FILE} ]
then
	log_msg ">>> ${PWR_CYCLE_MGR_FILE} does not exist!"
	sleep 1
	exit 104
else
	cd ${SCRIPTS_DIR}
	sh ./${PWR_CYCLE_MGR_FILE_NAME}
fi

