#!/bin/bash
#
# Copyright (C) MOXA Inc. All rights reserved.
# This software is distributed under the terms of the MOXA SOFTWARE NOTICE.
# See the file MOXA-SOFTWARE-NOTICE for details.
#
# Authors:
# 	2021	Wes Huang	<Wes.Huang@moxa.com>

export GENERAL_VARIABLES="/lib/moxa-system-manager/general_variables"
export GENERAL_FUNCTIONS="/lib/moxa-system-manager/general_functions"
if [ -f "${GENERAL_VARIABLES}" ]; then
	source "${GENERAL_VARIABLES}"
fi
if [ -f "${GENERAL_FUNCTIONS}" ]; then
	source "${GENERAL_FUNCTIONS}"
fi

INIT_HOOKS_DIR="/lib/moxa-system-manager/init-hooks.d/"

main() {
	local hook
	local ret_val

	_log_msg "debug" "${0}, ${FUNCNAME[0]}"
	_log_msg "debug" "INIT_HOOKS_DIR=${INIT_HOOKS_DIR}"

	for hook in "${INIT_HOOKS_DIR}"/*; do
		_log_msg "debug" "hook=${hook}"
		if [ -f "${hook}" ]; then
			${hook}
			ret_val="${?}"
			if [ "${ret_val}" != "0" ]; then
				_log_msg "warn" "${hook} is FAILD"
			fi
		else
			_log_msg "warn" "${hook} is not exist."
		fi
	done
}

main

exit 0
