forked from ScottEKendall/JAMF-Pro-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefault_post.sh
More file actions
401 lines (320 loc) · 10.4 KB
/
Default_post.sh
File metadata and controls
401 lines (320 loc) · 10.4 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/zsh
## last updated by: Scott Kendall
## last updated on: April 10, 2025
## Script version: 5.10.0
###############
# App variables
###############
# appType choices:
#
# app - Universal binary goes in /Applicaions folder
# apl - Application that goes into ~/Applications folder (perosnal applications)
# jav - Application will be installed in /Library/Java/JavaVirtualMachines
# loc - default location of /usr/local
# lib - default location of /usr/local/bin
# jpm - default location of /usr/local/ge
# cli - terminal CLI app that goes in custom location for binary files (ie. /usr/local/ge/bin)
# fnt - Fonts will be store in User's Library fonts folder
# sup - Application is in final location, only work on support files
# ext - Adobe After Effects plugin
# pkg - Install package (.pkg)
# prt - Printer PPD File
# cer - Install Certificates into /usr/local/ge/SSLcerts
# gem - Ruby Gems installed to /usr/local/ge
# dae - System LaunchDaemon /Library/LaunchDaemon
# jmf - Execute JAMF policy (by EventID)
# dmg - Copy the contents of a DMG into the /Applications folder
# chm - Insall chrome extensions into the user's chrome library
# dsk - Install file onto users Desktop
#
#
# Set the PATH to ensure a known good environment
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
LoggedInUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
UserDir=$(dscl . -read /Users/${LoggedInUser} NFSHomeDirectory | awk '{ print $2 }' )
appType="dsk"
appName="Join Raspberry Network.pdf"
runAfterDone="No"
FolderPath=""
CertPath="/Library/Frameworks/Python.framework/Versions/3.10/etc/openssl"
ExtensionsFolder="/Library/Application Support/Adobe/CEP/extensions"
# DMG Info
DMGName="ideaIC-2024.3.5-aarch64.dmg"
DMGVolumeName="IntelliJ IDEA CE"
typeset DefaultInstallFolder && DefaultInstallFolder=$(dirname ${0})
typeset CertPath && CertPath="/Library/Frameworks/Python.framework/Versions/3.10/etc/openssl"
typeset ExtensionsFolder && ExtensionsFolder="/Library/Application Support/Adobe/CEP/extensions"
typeset SettingsPath && SettingsPath="${UserDir}/Library/Android/sdk"
typeset unzipLocation && unzipLocation="${DefaultInstallFolder}"
typeset FontDir && FontDir="${UserDir}/Library/Fonts/"
####################
# "Global" variables
####################
platform=$(uname -p)
logDir="/Library/Application Support/GiantEagle/logs"
logStamp=$(echo $(date +%Y%m%d))
logFile="${logDir}/ApplicationInstall_${logStamp}_${appName} (${platform}).log"
typeset SourcePath && "${DefaultInstallFolder}/"
typeset DestPath
typeset ToolsHome && ToolsHome="/usr/local/ge"
typeset SupportFiles && "${ToolsHome}"
###########
# Functions
###########
function create_log_directory ()
{
# Ensure that the log directory and the log files exist. If they
# do not then create them and set the permissions.
#
# RETURN: None
# If the log directory doesnt exist - create it and set the permissions
[[ ! -d "${logDir}" ]] && /bin/mkdir -p "${logDir}"
/bin/chmod 755 "${logDir}"
# If the log file does not exist - create it and set the permissions
[[ ! -f "${logFile}" ]] && /usr/bin/touch "${logFile}"
/bin/chmod 644 "${logFile}"
}
function logMe ()
{
# Basic two pronged logging function that will log like this:
#
# 20231204 12:00:00: Some message here
#
# This function logs both to STDOUT/STDERR and a file
# The log file is set by the $LOG_FILE variable.
#
# RETURN: None
echo "$(/bin/date '+%Y-%m-%d %H:%M:%S'): ${1}" | tee -a "${logFile}"
}
function set_file_paths()
{
# Set the Destination folder based on what is being installed (Determined by 'AppType')
# Sets "DestPath" variable, must be declared outside of function
#
# RETURN: None
# See if the app is in the main folder or inside a platform folder
# and also see if it is in ZIP format or executable format.
if [[ -e "${DefaultInstallFolder}/bin.zip" ]]; then
# If the file is in the main folder and is in zip format..
SourcePath="${DefaultInstallFolder}/"
elif [[ -e "${DefaultInstallFolder}/${platform}/bin.zip" ]]; then
# If the file is in the platform folder and is in zip format..
SourcePath="${DefaultInstallFolder}/${platform}/"
elif [[ -e "${DefaultInstallFolder}/${appName}" ]]; then
# If the file is in the main folder and executable format...
SourcePath="${DefaultInstallFolder}/"
elif [[ -e "${DefaultInstallFolder}/${platform}/${appName}" ]]; then
# If the file is in the main folder and executable format...
SourcePath="${DefaultInstallFolder}/${platform}/"
fi
case "${appType}" in
"lib" )
DestPath="/usr/local/bin"
;;
"loc" )
DestPath="/usr/local"
;;
"prt" )
DestPath="//Library/Printers/PPDs/Contents/Resources"
;;
"cli" )
DestPath="${ToolsHome}/bin"
;;
"jpm" )
DestPath="${ToolsHome}"
;;
"cer" )
DestPath="${ToolsHome}/SSLcerts"
;;
"jav" )
DestPath="/Library/Java/JavaVirtualMachines"
;;
"gem" )
DestPath="/usr/local/ge/gems"
;;
"zip" )
DestPath="${unzipLocation}"
;;
"dae" )
DestPath="/Library/LaunchDaemons"
;;
"dsk" )
DestPath="${UserDir}\Desktop"
;;
"app" | "pkg" | "sup" | "jmf" | "dmg" )
DestPath="/Applications"
;;
"apl" )
DestPath="${UserDir}/Applications"
;;
"fnt" )
DestPath="${UserDir}/Library/Fonts"
;;
"ext" )
DestPath="${ExtensionsFolder}"
;;
esac
SupportFiles="${DestPath}"
}
function set_ownership ()
{
# Sets the Onwership & permisisons of the Destination file (Determined by 'AppType')
#
# RETURN: None
logMe "Set ownership permissions"
case ${appType} in
"lib" | "app" | "sup" | "cer" | "jav" | "dae" | "pkg" |"jmf" | "prt" | "dmg" )
[[ -e "${DestPath}/${appName}" ]] && chown -R root:wheel "${DestPath}/${appName}" > /dev/null
;;
"fnt" | "jpm"| "cli" | "loc" | "apl" | "gem" | "zip" )
[[ -e "${DestPath}/${appName}" ]] && chown -R ${LoggedInUser} "${DestPath}/${appName}" > /dev/null
;;
esac
chmod -R 755 "${DestPath}/${appName}" > /dev/null
}
function clear_quarantine_flag ()
{
# Clears the Appole Qaurantine flag and performs the gatekeeper scan
#
# RETURN: None
# Only clear the quaratine flag if they are of specific app types
if [[ "${appType}" == @("fnt|sup|cer|gem|dae") ]] || [[ ! -e "${DestPath}/${appName}" ]] ; then
logMe "INFO: No need to clear quarantine flag"
return 0
fi
logMe "Clearing the Quarantine flag"
xattr -d -r com.apple.quarantine "${DestPath}/${appName}" 2> /dev/null
# Perform the new Gatekeeper scan if on Sonoma or higher
logMe "Performing Gatekeeper Scan"
gktool scan "${DestPath}/${appName}"
}
function cleanup ()
{
for CleanUp_Path (
"${SourcePath}bin.zip"
"${SourcePath}sbin.zip"
"${SourcePath}include.zip"
"${SourcePath}lib.zip"
"${SourcePath}share.zip"
"${SourcePath}man.zip"
"${SourcePath}${appName}.zip"
"${SourcePath}${appName}"
"${DefaultInstallFolder}/arm"
"${DefaultInstallFolder}/i386"
"${ToolsHome}/__MACOSX"
"${DestPath}/__MACOSX"
"${SourcePath}__MACOSX"
"${SupportFiles}/__MACOSX"
) { [[ -e "${CleanUp_Path}" ]] && { rm -rf "${CleanUp_Path}" ; echo "Cleaning up: ${CleanUp_Path}" ; }}
}
function perform_install_action()
{
logMe "Install the application and support file(s) to ${DestPath}"
case "${appType}" in
"cer" )
logMe "Installing Certificate(s)"
ln -sf "${DestPath}/${appName}" "${CertPath}"
;;
"jmf" )
logMe "Executing JAMF policy: ${JAMFPolicy}"
jamf policy -event ${JAMFPolicy}
;;
"ext" )
logMe "Moving Adobe Extension to destination"
unzip -o "${SourcePath}${appName}" -d "${ExtensionsFolder}"
rm -r "${ExtensionsFolder}/__MACOSX"
;;
"fnt" )
logMe "Installing fonts"
unzip -o "${SourcePath}${appName}" -d "${DestPath}"
;;
"pkg" )
logMe "Running Package Installer"
installer -pkg "${SourcePath}${pkgName}" -target "${DestPath}"
;;
"prt" )
logMe "Installing Printer PPD File"
mv -f "${SourcePath}${appName}" "${DestPath}"
;;
"app" | "apl" )
if [[ -e "${SourcePath}/${appName}" ]]; then
logMe "Moving app to destination"
rm -r "${DestPath}/${appName}"
mv -f "${SourcePath}${appName}" "${DestPath}"
fi
;;
"dae" )
logMe "Installing BootStrap Daemon"
launchctl bootstrap system "${appName}"
;;
"zip" )
if [[ -f "${SourcePath}${appName}.zip" ]]; then
logMe "Unzipping files"
unzip -o "${SourcePath}${appName}" -d "${DestPath}"
fi
;;
"dmg" )
logMe "Mounting DMG ${DMGName}"
hdiutil attach "${DMGName}" -nobrowse -quiet
sleep 5
logMe "Copying ${DMGVolumeName}/${appName} to ${DestPath}"
cp -R "/Volumes/${DMGVolumeName}/${appName}" "${DestPath}"
logMe "Unmounting DMG ${DMGName}"
hdiutil detach "/Volumes/${DMGVolumeName}" -force -quiet
;;
"jav" )
logMe "Installing Java ${appName}"
unzip -o "${SourcePath}${appName}" -d "${DestPath}"
ln -sf "java" "${ToolsHome}/bin"
;;
"cli" | "lib" | "jpm" | "loc" | "gem" )
logMe "Installing binary files"
# If there is an "appName".zip then extract the .zip file otherwise move the binary to destination
if [[ -f "${SourcePath}bin.zip" ]]; then
unzip -o "${SourcePath}bin" -d "${DestPath}"
else
mv -f "${SourcePath}${appName}" "${DestPath}"
fi
logMe "Installing Extras content to: ${DestPath}"
# See if there are an extras that need to be installed as well
for ExtraItem in include lib libexec sbin share etc man Frameworks; do
[[ -e "${SourcePath}${ExtraItem}.zip" ]] && ExtrasPath="${SourcePath}" || ExtrasPath="${DefaultInstallFolder}"/
if [[ ! -e "${ExtrasPath}${ExtraItem}.zip" ]]; then
continue
fi
logMe "Installing ${ExtraItem} files"
unzip -o "${ExtrasPath}${ExtraItem}.zip" -d "${DestPath}"
done
chmod -R 755 "${DestPath}"
;;
esac
}
#############
#
# Main Script
#
#############
set_file_paths
create_log_directory
logMe "Installing for platform type: ${platform}"
logMe "Installation type: ${appType}"
logMe "Source Folder: ${SourcePath}"
logMe "Destination Folder: ${DestPath}"
#################################
#
# Pre-instalation actions go here
#
#################################
perform_install_action
set_ownership
clear_quarantine_flag
#########################################
#
# Do any application specific commands here
#
#########################################
# Clean up and exit
logMe "Cleanup and Exit"
cleanup
[[ $runAfterDone == "Yes" ]] && sudo /usr/bin/open "${DestPath}/${appName}"
exit 0