#!/bin/bash

cp "$1/Contents/meshagent_osx64.msh" "/usr/local/mesh_services/GNL Solutions/gnlagent/GNL-Remote-Agent.msh"
cp "$1/Contents/meshagent_osx64.bin" "/usr/local/mesh_services/GNL Solutions/gnlagent/GNL-Remote-Agent"
cp "$1/Contents/meshagent_osx64_LaunchDaemon.plist" "/Library/LaunchDaemons/gnlagent.plist"
cp "$1/Contents/meshagent_osx64_LaunchAgent.plist" "/Library/LaunchAgents/gnlagent.plist"
rm "/usr/local/mesh_services/GNL Solutions/gnlagent/internal.txt"

chown root:wheel "/usr/local/mesh_services/GNL Solutions/gnlagent"
chown root:wheel "/usr/local/mesh_services/GNL Solutions/gnlagent/GNL-Remote-Agent"
chown root:wheel "/Library/LaunchDaemons/gnlagent.plist"
chown root:wheel "/Library/LaunchAgents/gnlagent.plist"

chmod 755 "/usr/local/mesh_services/GNL Solutions/gnlagent"
chmod 755 "/usr/local/mesh_services/GNL Solutions/gnlagent/GNL-Remote-Agent"

/bin/launchctl load "/Library/LaunchDaemons/gnlagent.plist"
