#!/bin/bash 

Install_Agent_Alt() {
	delete_db=$1
	agent_package="colibri-agent"

	[ "${delete_db,,}" == 'true' ] && delete_db_env="REMOVE_COLIBRI_DB=1"

	query=$(rpm -qi "$agent_package" 2>/dev/null | grep "Install Date")
	if [ -z "$query" ]
	then
		Write_Log "The [$agent_package] package is not yet installed"
		Write_Log "Installing..."
		install_out=$(Run_Command "apt-get --yes install $agent_package")
		install_rc=$?
		if [ $install_rc -ne 0 ]
		then
			Write_Log "Installation $agent_package was failed: [$install_out]" "ERROR"
			return $install_rc
		fi
		return 0
	else
		Write_Log "The [$agent_package] package was installed before, reinstall.."
		if ! Run_Command "$delete_db_env apt-get --yes remove $agent_package"
		then
			return 1
		fi
		Install_Agent_Alt "$delete_db"
		return $?
	fi
}
