-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathRemove App From Unapproved Locations.sh
123 lines (91 loc) · 3.67 KB
/
Remove App From Unapproved Locations.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/sh
####################################################################################################
#
# Remove App From Unapproved Locations
#
# Purpose: Apps installed in non-standard paths will NOT be updated by Jamf Pro Patch Policies.
# This script will remove an app with a given Bundle ID from all unapproved locations.
#
# Jamf Pro Script Parameter 4: Bundle ID (i.e., "us.zoom.xos")
# Jamf Pro Script Parameter 5: Authorized Path (i.e., "/Applications/zoom.us.app")
#
####################################################################################################
#
# HISTORY
#
# Version 1.0.0, 12-May-2020, Dan K. Snelson
# Original version
# Inspired by donmontalvo: https://www.jamf.com/jamf-nation/discussions/35674/
#
####################################################################################################
####################################################################################################
#
# Define the Variables
#
####################################################################################################
# Bundle ID (exit if blank)
bundleID="${4}"
# Check for a specified value for Bundle ID (Parameter 4)
if [ "${bundleID}" = "" ]; then
# Parameter 4 is blank; exit with error
echo "Parameter 4 is blank; exit with error."
exit 1
fi
# Authorized Path (exit if blank)
authorizedPath="${5}"
# Check for a specified value for Authorized Path (Parameter 5)
if [ "${authorizedPath}" = "" ]; then
# Parameter 5 is blank; exit with error
echo "Parameter 5 is blank; exit with error."
exit 1
fi
searchResults="/private/var/tmp/${bundleID}-searchResults.txt"
####################################################################################################
#
# Define the Functions
#
####################################################################################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Validate App Installation
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
validateAppInstallation() {
echo "Validate App Installation ..."
appInstalledTest=$( /usr/bin/mdfind kMDItemCFBundleIdentifier="${bundleID}" )
if [ -z ${appInstalledTest} ]; then
echo "${bundleID} NOT installed; exit"
exit 0
else
echo "${bundleID} installed; proceeding ..."
fi
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Detect Unapproved App Locations
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
detectUnapprovedAppLocations() {
echo "Detect Unapproved App Locations ..."
/usr/bin/mdfind kMDItemCFBundleIdentifier="${bundleID}" | /usr/bin/grep -vw "\b${authorizedPath}\b" > "${searchResults}"
echo "Unapproved App Locations: `/bin/cat ${searchResults}`"
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Remove App From Unapproved Locations
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
removeAppFromUnpprovedLocations() {
echo "Remove app from unapproved locations ..."
/usr/bin/xargs -I{} /bin/rm -R {} < "${searchResults}"
}
####################################################################################################
#
# Program
#
####################################################################################################
echo " "
echo "###"
echo "# Remove App From Unapproved Locations"
echo "###"
echo " "
validateAppInstallation
detectUnapprovedAppLocations
removeAppFromUnpprovedLocations
echo "Removed `/bin/cat ${searchResults}`"
/bin/rm "${searchResults}"
exit 0