#!/bin/bash 

Init_Agent() {
	is_os_deployment=$1
	agent_root=$2
	agent_id=$3
	deployment_id=$4

	init_rc=0
	agent_service_file=/etc/systemd/system/colibri-agent.service
	if [ "$is_os_deployment" == True ]
	then
		Write_Log "Run Agent initialization for OS Deployment"
		Run_Command "$agent_root/service/Colibri.Agent.Service DeployOS --DeploymentId $deployment_id --ComputerId $agent_id"
		init_rc=$?
		Write_Log "Agent initialization completed with return code: [$init_rc]"
		Run_Command "systemctl restart colibri-agent.service"
	else
		Write_Log "Run Agent initialization for Agent push"
		backup_original_service=$(cat "$agent_service_file")
		sed -i "s/RunAsService/DeployAgent --DeploymentId $deployment_id --ComputerId $agent_id/" "$agent_service_file"
		Run_Command "systemctl daemon-reload"
		Run_Command "systemctl restart colibri-agent.service"
		sleep 10
		echo "$backup_original_service" > "$agent_service_file"
		Run_Command "systemctl daemon-reload"
	fi

	return $init_rc
}
