#!/bin/bash
lxc-ls --active -1 | grep Assistant || {
echo "`date` This script can be called only from the Primary Node (= Node on which Assistant is running)"
exit -1
}
aline=$(2>/dev/null /opt/inventory/inventory appliance_list --full  | xpath -e '//appliance[(hwTypeNumber="2")]/id|//appliance[(hwTypeNumber="2")]/label|//appliance[(hwTypeNumber="2")]/soco2Version' 2>/dev/null | sed -e "s/<\//§\n/g" | sed -e "s/.*>//g")
		arrIds="§"
		arrLbls="§"
		arrVers="§"
		index=0
		applcount=0
		while [ 1 ]; do
			anelem=`echo -en ${aline%%§*}`
			anelem=${anelem%+*}
			[ "x" = "x$anelem" ] && break
			aline=${aline#*§}
			case $index in
				0)
					arrIds="$arrIds${anelem}§"
					index=1
					;;
				1)
					arrLbls="$arrLbls${anelem}§"
					index=2
					;;
				2)
					if [[ $anelem =~ ^V ]]; then
						arrVers="$arrVers${anelem}§"
						index=0
						applcount=$(($applcount+1))
					else
						arrIds="${arrIds%§*§}§"
						arrLbls="${arrLbls%§*§}§"
						arrIds="$arrIds${anelem}§"
						index=1
					fi
					;;
			esac
		done
		>/dev/os4k_osa500.cache
		echo "APPLCOUNT=$applcount" >/dev/os4k_osa500.cache
		echo "ARR_IDs=(${arrIds//§/ })" >>/dev/os4k_osa500.cache
		echo "ARR_LBs=(${arrLbls//§/ })" >>/dev/os4k_osa500.cache
		echo "ARR_VERs=(${arrVers//§/ })" >>/dev/os4k_osa500.cache
		source /dev/os4k_osa500.cache

exit $applcount
