-
Notifications
You must be signed in to change notification settings - Fork 8
/
update_nomad.sh
66 lines (57 loc) · 2.74 KB
/
update_nomad.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
###
#
# Name: nomad_update.sh
# Description: This script checks that NoMAD.app is installed, then does the following:
# 1- Checks for OS version to run correct launchctl method.
# 2- Unloads the NoMAD LaunchAgent in the user context.
# 3- Runs a .pkg installer of the new NoMAD version on secondary/helper policy
# with custom trigger 'update_nomad'.
# 4- Loads the NoMAD LaunchAgent in the user context to relaunch app.
# Note: Largely cobbled together from Elliot Jordan's scripts and jamfnation posts.
# Author: Emily Kausalik (drkausalik@gmail.com)
# Created: 2016-12-12
# Last Modified: 2016-12-12
#
###
# Make sure app exists.
echo "Making sure NoMAD is installed..."
if [[ ! -d "/Applications/NoMAD.app" ]]; then
echo "[ERROR] /Applications/NoMAD.app does not exist."
exit 1002
fi
# Get current user and OS information.
CURRENT_USER=$(/usr/bin/stat -f%Su /dev/console)
USER_ID=$(id -u "$CURRENT_USER")
OS_MAJOR=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $1}')
OS_MINOR=$(/usr/bin/sw_vers -productVersion | awk -F . '{print $2}')
# Closing NoMAD using launchctl.
echo "Closing NoMAD..."
if [[ "$OS_MAJOR" -eq 10 && "$OS_MINOR" -le 9 ]]; then
LOGINWINDOW_PID=$(pgrep -x -u "$USER_ID" loginwindow)
/bin/launchctl bsexec "$LOGINWINDOW_PID" /bin/launchctl unload /Users/"$CURRENT_USER"/Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
elif [[ "$OS_MAJOR" -eq 10 && "$OS_MINOR" -gt 9 ]]; then
/bin/launchctl asuser "$USER_ID" /bin/launchctl unload /Users/"$CURRENT_USER"/Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
else
echo "[ERROR] macOS $OS_MAJOR.$OS_MINOR is not supported."
exit 1004
fi
# Really make sure NoMAD is closed.
killall NoMAD
# Making sure application is closed
osascript -e "tell application \"NoMAD\" to quit" # potentially redundant, but meant to prevent duplicate processes from running
# Installing newest version of NoMAD
echo "Installing newest version of NoMAD..."
jamf policy -trigger update_nomad # change this to whatever custom trigger you use for the installer policy
# Launching NoMAD using launchctl.
echo "Launching NoMAD..."
if [[ "$OS_MAJOR" -eq 10 && "$OS_MINOR" -le 9 ]]; then
LOGINWINDOW_PID=$(pgrep -x -u "$USER_ID" loginwindow)
/bin/launchctl bsexec "$LOGINWINDOW_PID" /bin/launchctl load /Users/"$CURRENT_USER"/Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
elif [[ "$OS_MAJOR" -eq 10 && "$OS_MINOR" -gt 9 ]]; then
/bin/launchctl asuser "$USER_ID" /bin/launchctl load /Users/"$CURRENT_USER"/Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
else
echo "[ERROR] macOS $OS_MAJOR.$OS_MINOR is not supported."
exit 1004
fi
exit 0