#!/bin/bash

update_kav_db() {
	PATH=/usr/sbin:/sbin:/usr/bin:/bin
	SDK_HOME=/opt/kav/sdk8l3
	export KL_PLUGINS_PATH="$SDK_HOME/lib"
	export LD_LIBRARY_PATH="$KL_PLUGINS_PATH:$LD_LIBRARY_PATH"

	$SDK_HOME/bin/keepup2date8 --download --licinfo --simplelic --version --xmlfile $SDK_HOME/bin/settings.xml
	RET=$?

	### Return codes are detailed in updatersdk.h
	case "$RET" in
		0)
			# 0 - Success
			service kavehost reload
			;;
		10|20)
			# 10 - All files are up-to-date
			# 20 - An operation did not complete because the current version of definitions is newer than the version in the source
			RET=0
			;;
	esac

	return $RET
}

output=$(update_kav_db 2>&1)
rc="$?"

if [ "$rc" -ne "0" ]; then
	echo "$output"
fi

exit "$rc"
