#!/bin/sh
#
# update_notify script
# launched in case a SIP notify has been received, will force the check of upgrade status
# according to the URL specified
#
# Changelog:
#
#	- Wed Jan 05 2011 - Guillaume Catto <guillaume.catto@alcatel-lucent.com>
#	* Fix crms00284851: script creation
#
#	- Wed jan 11 2011 - Guillaume Catto <guillaume.catto@alcatel-lucent.com>
#	* Fix crms00288108: do not start this script if current running step is lower than 5
#
#	- Fri Feb 08 2013 - Ziming Xu <Ziming.b.Xu@alcatel-lucent.com>
#	* Fix crms00417047: confusion about the style of dmurl update
#
##################################
# Source external script         #
##################################
. /usr/lib/upgrade/rpmdbbackup-addon.sh

##################################
# Global variables               #
##################################
ADMCFG_UPDATE_ENABLE=$(CLISettings get CURRENT ADMCFG_UPDATE_ENABLE)
debug_output=/dev/null

# +++ crms00288108
startup_step=/tmp/step
# --- crms00288108

##################################
# Main                           #
##################################
# +++ crms00288108
current_step=$(cat ${startup_step})
: Check steps ${current_step}/5
[ ${current_step} -lt 5 ] && return 0
# --- crms00288108

if [[ $ADMCFG_UPDATE_ENABLE != "true" ]]; then
	logger -s -t upgrade -p local0.ERR "Update process is not enable"
	exit 0
fi

# in case a check is already running, save the URL
child_pid_status
[[ $RETVAL == 1 ]] && exit 0

# Before launching process verify that given parameter is an URL and that it is different from
# current setting's value
if [[ ! -z "$1" ]]; then
	get_setting_value ENETCFG_UPGRADE_FILE
# crms00417047 zimingxu+
	get_setting_value ENETCFG_DM
# crms00417047 zimingxu-
	get_setting_value ENETCFG_DM_PROTOCOL
# crms00417047 zimingxu+
	if [[ "$1" != "${ENETCFG_DM_PROTOCOL}://${ENETCFG_DM}${ENETCFG_UPGRADE_FILE}" ]]; then
# crms00417047 zimingxu-
		split_old_upgrade_url $1
	fi
fi

# Start of background process
($process_management > $debug_output 2>&1 &)
exit $?
