_version = $1

echo
echo "************"
echo Getting update with version $_version
echo "************"
echo

_repo = (feature:repo-list | grep ru.entaxy.esb/update/$_version)
_repo_length = ($_repo length)
if { $_repo_length'' equals "0" } {
	echo "\>\> Installing Entaxy update $_version repository..."
	feature:repo-add mvn:ru.entaxy.esb/update/$_version/xml/update
	echo "\>\> ... installed"
} else {
	echo "\>\> Entaxy update $_version repository is already installed"
}

_versionFormatted = ($_version toString) replaceAll "-" "."

service = (service:get org.apache.karaf.features.FeaturesService)

_configFeature = ($service getFeature "entaxy-update-configuration" $_version)
_configFeatureId = $_configFeature getId
_state = ($service getState $_configFeatureId) toString

echo
if { NOT { $_state equals "Started" } } {
	echo "\>\> Installing Entaxy update $_version configuration..."
	feature:install -v -r "entaxy-update-configuration"/$_version
	echo "\>\> ... installed"
}

_state = ($service getState $_configFeatureId) toString

echo
if { $_state equals "Started" } {
	echo "Configuration loaded for version $_version"
} else {
	echo "Configuration load failed for version $_version"
}
echo