#!/bin/bash

if [[ $(uname -p) = 'arm' ]]; then
	curl -o GLPI-Agent.pkg https://ftp-glpi.oca.eu/GLPI-Agent/GLPI-Agent_macOS_arm64.pkg
else
	curl -o GLPI-Agent.pkg https://ftp-glpi.oca.eu/GLPI-Agent/GLPI-Agent_macOS_x86_64.pkg
fi
wait
installer -pkg GLPI-Agent.pkg -target /
wait
mkdir -p /Applications/GLPI-Agent/etc/conf.d/
wait
echo -e "httpd-trust = '127.0.0.1/32,192.54.174.76/32'\nserver = 'https://glpi.oca.eu/plugins/glpiinventory/'\ntasks = 'inventory,deploy'" > /Applications/GLPI-Agent/etc/conf.d/local.cfg
wait
/Applications/GLPI-Agent/bin/glpi-agent --daemon
wait
sleep 10
wait
curl http://localhost:62354/now