#!/bin/bash
#
# &check_id;
#   Health check program for the Linux Health Checker
#
# TODO: specify copyright
#
# Author(s): &check_author;
#
# TODO: specify license. Note: the parts of this file that were generated
#       by lnxhc are not copyrighted and can be distributed under any license.
#

#
# Global variables
#

# Non-zero if health check program should output additional information
VERBOSE="$LNXHC_VERBOSE"

# Non-zero if health check program should output debugging information
DEBUG="$LNXHC_DEBUG"

# Health check ID
CHECK_ID="$LNXHC_CHECK_ID"

# Health check installation directory
CHECK_DIR="$LNXHC_CHECK_DIR"

# Path to the file used to report exceptions
EX_FILE="$LNXHC_EXCEPTION"

&bash_ex_def_list;&bash_param_def_list;&bash_si_def_list;

#
# Functions
#

#
# lnxhc_setup - validate input from framework
#
function lnxhc_setup()
{
	if [ -z "$DEBUG" -o -z "$CHECK_ID" -o -z "$CHECK_DIR" -o \
	     -z "$EX_FILE" ] ; then
		echo "&check_id;: This program cannot be called directly." >&2
		echo "Please use the 'lnxhc run' function to call this " \
		     "program." >&2
		exit 1
	fi
}

#
# lnxhc_exception - report exception
# @ex_id: ID of the exception to report
#
function lnxhc_exception()
{
	local EX_ID="$1"

	echo "$EX_ID" >> "$EX_FILE" || exit 1
}

#
# lnxhc_exception_var - report value of an exception template variable
# @var_id: ID of the exception template variable
# @value: value of the exception template variable
#
function lnxhc_exception_var()
{
	local VAR_ID="$1"
	local VALUE="$2"

	echo "$VAR_ID=\"$VALUE\"" >> "$EX_FILE" || exit 1
}


#
# Code entry
#

# Validate input from framework
lnxhc_setup

# TODO:
# 1. Check parameters for correct values (param_*).
# 2. Access sysinfo data (filenames available in sysinfo_*).
# 3. Perform analysis.
# 4. If an exception is found, write its ID and values for exception
#    template variables to file ex_file.
#
# See 'man lnxhc_check_program' for more information.
#

#
# Sample exception reporting. TODO: call this only if an exception
# was identified.
#
&bash_ex_report_list;
#
# Sample exception variable reporting. TODO: call this only if an
# exception was identified.
#
lnxhc_exception_var "var" "value"

exit 0
