#!/bin/bash

if [[ $(uname -p) = 'arm' ]]; then
	curl -o /private/tmp/GLPI-Agent.pkg https://ftp-glpi.oca.eu/glpi-agent/sources/macos/arm64/package.pkg
else
	curl -o /private/tmp/GLPI-Agent.pkg https://ftp-glpi.oca.eu/glpi-agent/sources/macos/x64/package.pkg
fi
wait
installer -pkg /private/tmp/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