|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# source: https://github.com/amidaware/community-scripts/blob/main/scripts_staging/macos_fix_mesh_install.sh |
| 4 | +# author: https://github.com/NiceGuyIT |
| 5 | + |
| 6 | +# This script fixes MeshAgent issue #161: MacOS Ventura - Not starting meshagent on boot (Maybe Solved) |
| 7 | +# https://github.com/Ylianst/MeshAgent/issues/161 |
| 8 | +# |
| 9 | +# The following actions are taken: |
| 10 | +# 1) Add the eXecute bit for directory traversal for the installation directory. This allows regular users |
| 11 | +# access to run the binary inside the directory, fixing the "meshagent" LaunchAgent integration with the |
| 12 | +# user. |
| 13 | +# 2) Rename the LaunchAgent "meshagent.plist" to prevent conflicts with the LaunchDaemon "meshagent.plist". |
| 14 | +# This may not be needed but is done for good measure. |
| 15 | +# 3) Rename the service Label inside the plist. Using "defaults" causes the plist to be rewritten in plist |
| 16 | +# format, not ascii. |
| 17 | +# |
| 18 | +# Here's the original plist from my install. |
| 19 | +# <?xml version="1.0" encoding="UTF-8"?> |
| 20 | +# <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 21 | +# <plist version="1.0"> |
| 22 | +# <dict> |
| 23 | +# <key>Label</key> |
| 24 | +# <string>meshagent</string> |
| 25 | +# <key>ProgramArguments</key> |
| 26 | +# <array> |
| 27 | +# <string>/opt/tacticalmesh/meshagent</string> |
| 28 | +# <string>-kvm1</string> |
| 29 | +# </array> |
| 30 | +# |
| 31 | +# <key>WorkingDirectory</key> |
| 32 | +# <string>/opt/tacticalmesh</string> |
| 33 | +# |
| 34 | +# <key>RunAtLoad</key> |
| 35 | +# <true/> |
| 36 | +# <key>LimitLoadToSessionType</key> |
| 37 | +# <array> |
| 38 | +# <string>LoginWindow</string> |
| 39 | +# </array> |
| 40 | +# <key>KeepAlive</key> |
| 41 | +# <dict> |
| 42 | +# <key>Crashed</key> |
| 43 | +# <true/> |
| 44 | +# </dict> |
| 45 | +# </dict> |
| 46 | +# </plist> |
| 47 | + |
| 48 | + |
| 49 | +mesh_install_dir="/opt/tacticalmesh/" |
| 50 | +mesh_agent_plist_old="/Library/LaunchAgents/meshagent.plist" |
| 51 | +mesh_agent_plist="/Library/LaunchAgents/meshagent-agent.plist" |
| 52 | +mesh_daemon_plist="/Library/LaunchDaemons/meshagent.plist" |
| 53 | + |
| 54 | +if [ ! -f "${mesh_daemon_plist}" ] |
| 55 | +then |
| 56 | + echo "meshagent LaunchDaemon does not exist to cause the duplicate service name issue. Exiting." |
| 57 | + exit 0 |
| 58 | +fi |
| 59 | + |
| 60 | +if /usr/bin/stat -f "%Sp" "${mesh_install_dir}" | grep -v 'x$' >/dev/null |
| 61 | +then |
| 62 | + echo "Fixing permissions on meshagent installation directory: ${mesh_install_dir}" |
| 63 | + chmod o+X "${mesh_install_dir}" |
| 64 | +else |
| 65 | + echo "No action taken. Permissions on meshagent installation directory have already been fixed." |
| 66 | +fi |
| 67 | +echo |
| 68 | + |
| 69 | +if [ -f "${mesh_agent_plist_old}" ] |
| 70 | +then |
| 71 | + echo "Renaming agent plist: ${mesh_agent_plist_old}" |
| 72 | + mv "${mesh_agent_plist_old}" "${mesh_agent_plist}" |
| 73 | +else |
| 74 | + echo "No action taken. meshagent.plist was already renamed: ${mesh_agent_plist}" |
| 75 | +fi |
| 76 | +echo |
| 77 | + |
| 78 | +# New file has to exist before renaming the label. |
| 79 | +if [ -f "${mesh_agent_plist}" ] |
| 80 | +then |
| 81 | + label=$(defaults read "${mesh_agent_plist}" Label) |
| 82 | + if [ "${label}" != "meshagent-agent" ] |
| 83 | + then |
| 84 | + echo "Renaming meshagent label in plist: ${mesh_agent_plist}" |
| 85 | + echo "Warning: This will convert the plist from a text file to a binary plist file." |
| 86 | + defaults write "${mesh_agent_plist}" Label "meshagent-agent" |
| 87 | + else |
| 88 | + echo "No action taken. meshagent label was already renamed: ${label}" |
| 89 | + fi |
| 90 | +fi |
0 commit comments