From 8e6858778bcf717d5cea8d2dc17a28c4aad4efb9 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 31 Jul 2023 19:11:02 -0700 Subject: [PATCH] ventura mesh fix --- agent/embed_darwin.go | 24 +++++++ agent/embed_stub.go | 17 +++++ agent/scripts/macos_fix_mesh_install.sh | 90 +++++++++++++++++++++++++ agent/svc.go | 4 ++ main.go | 2 + 5 files changed, 137 insertions(+) create mode 100644 agent/embed_darwin.go create mode 100644 agent/embed_stub.go create mode 100644 agent/scripts/macos_fix_mesh_install.sh diff --git a/agent/embed_darwin.go b/agent/embed_darwin.go new file mode 100644 index 0000000..6a42a6d --- /dev/null +++ b/agent/embed_darwin.go @@ -0,0 +1,24 @@ +//go:build darwin +// +build darwin + +/* +Copyright 2023 Amidaware Inc. + +Licensed under the Tactical RMM License Version 1.0 (the “License”). +You may only use the Licensed Software in accordance with the License. +A copy of the License is available at: + +https://license.tacticalrmm.com + +*/ + +package agent + +import _ "embed" + +//go:embed scripts/macos_fix_mesh_install.sh +var ventura_mesh_fix string + +func (a *Agent) FixVenturaMesh() { + a.RunScript(ventura_mesh_fix, "foo", []string{}, 45, false, []string{}) +} diff --git a/agent/embed_stub.go b/agent/embed_stub.go new file mode 100644 index 0000000..68f799f --- /dev/null +++ b/agent/embed_stub.go @@ -0,0 +1,17 @@ +//go:build !darwin +// +build !darwin + +/* +Copyright 2023 Amidaware Inc. + +Licensed under the Tactical RMM License Version 1.0 (the “License”). +You may only use the Licensed Software in accordance with the License. +A copy of the License is available at: + +https://license.tacticalrmm.com + +*/ + +package agent + +func (a *Agent) FixVenturaMesh() {} diff --git a/agent/scripts/macos_fix_mesh_install.sh b/agent/scripts/macos_fix_mesh_install.sh new file mode 100644 index 0000000..b6e9c0b --- /dev/null +++ b/agent/scripts/macos_fix_mesh_install.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +# source: https://github.com/amidaware/community-scripts/blob/main/scripts_staging/macos_fix_mesh_install.sh +# author: https://github.com/NiceGuyIT + +# This script fixes MeshAgent issue #161: MacOS Ventura - Not starting meshagent on boot (Maybe Solved) +# https://github.com/Ylianst/MeshAgent/issues/161 +# +# The following actions are taken: +# 1) Add the eXecute bit for directory traversal for the installation directory. This allows regular users +# access to run the binary inside the directory, fixing the "meshagent" LaunchAgent integration with the +# user. +# 2) Rename the LaunchAgent "meshagent.plist" to prevent conflicts with the LaunchDaemon "meshagent.plist". +# This may not be needed but is done for good measure. +# 3) Rename the service Label inside the plist. Using "defaults" causes the plist to be rewritten in plist +# format, not ascii. +# +# Here's the original plist from my install. +# +# +# +# +# Label +# meshagent +# ProgramArguments +# +# /opt/tacticalmesh/meshagent +# -kvm1 +# +# +# WorkingDirectory +# /opt/tacticalmesh +# +# RunAtLoad +# +# LimitLoadToSessionType +# +# LoginWindow +# +# KeepAlive +# +# Crashed +# +# +# +# + + +mesh_install_dir="/opt/tacticalmesh/" +mesh_agent_plist_old="/Library/LaunchAgents/meshagent.plist" +mesh_agent_plist="/Library/LaunchAgents/meshagent-agent.plist" +mesh_daemon_plist="/Library/LaunchDaemons/meshagent.plist" + +if [ ! -f "${mesh_daemon_plist}" ] +then + echo "meshagent LaunchDaemon does not exist to cause the duplicate service name issue. Exiting." + exit 0 +fi + +if /usr/bin/stat -f "%Sp" "${mesh_install_dir}" | grep -v 'x$' >/dev/null +then + echo "Fixing permissions on meshagent installation directory: ${mesh_install_dir}" + chmod o+X "${mesh_install_dir}" +else + echo "No action taken. Permissions on meshagent installation directory have already been fixed." +fi +echo + +if [ -f "${mesh_agent_plist_old}" ] +then + echo "Renaming agent plist: ${mesh_agent_plist_old}" + mv "${mesh_agent_plist_old}" "${mesh_agent_plist}" +else + echo "No action taken. meshagent.plist was already renamed: ${mesh_agent_plist}" +fi +echo + +# New file has to exist before renaming the label. +if [ -f "${mesh_agent_plist}" ] +then + label=$(defaults read "${mesh_agent_plist}" Label) + if [ "${label}" != "meshagent-agent" ] + then + echo "Renaming meshagent label in plist: ${mesh_agent_plist}" + echo "Warning: This will convert the plist from a text file to a binary plist file." + defaults write "${mesh_agent_plist}" Label "meshagent-agent" + else + echo "No action taken. meshagent label was already renamed: ${label}" + fi +fi diff --git a/agent/svc.go b/agent/svc.go index 9e7f9c0..eacc8c0 100644 --- a/agent/svc.go +++ b/agent/svc.go @@ -80,6 +80,10 @@ func (a *Agent) AgentSvc(nc *nats.Conn) { a.SendSoftware() } + if runtime.GOOS == "darwin" { + go a.FixVenturaMesh() + } + checkInHelloTicker := time.NewTicker(time.Duration(conf.Hello) * time.Second) checkInAgentInfoTicker := time.NewTicker(time.Duration(conf.AgentInfo) * time.Second) checkInWinSvcTicker := time.NewTicker(time.Duration(conf.WinSvc) * time.Second) diff --git a/main.go b/main.go index 7c3d651..d882274 100644 --- a/main.go +++ b/main.go @@ -119,6 +119,8 @@ func main() { a.RunMigrations() case "recovermesh": a.RecoverMesh() + case "macventurafix": + a.FixVenturaMesh() case "taskrunner": if len(os.Args) < 5 || *taskPK == 0 { return