-
Notifications
You must be signed in to change notification settings - Fork 30
/
Update_Core_Apps.sh
2261 lines (1742 loc) · 74.4 KB
/
Update_Core_Apps.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
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
## Script name: Update_Core_Apps.sh
## Script author: Mike Morales
## Last updated: 2015-03-04
## Last rev notes:
## Updated to account for Oracle Java's new .app installer. Should correctly install the pkg inside the .app bundle if present.
## It should be backward compatiblle with older OS X versions that would still pull down pre 1.8 versions of Java
##
## NOTES:
## This script will only work with Intel Macs.
## If necessary, the script dynamically builds a Safari User Agent string
## based on the client system to use when checking against some pages.
## EDITABLE VARIABLES BELOW
## Path to cocoaDialog and jamfHelper (Edit path to cocoaDialog to match your environment)
cdPath="/Library/Application Support/JAMF/bin/cocoaDialog.app/Contents/MacOS/cocoaDialog"
jhPath="/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
## The following variable can be hardcoded into the script to set whether new installs should take place
## on Macs that may not have the specified app or plug-in, or if we should only be updating an existing
## installation. Set the variable to "Yes" if you would like new installs to occur. Comment out the entire line
## or set the string to blank ("") if you would like to skip new installations.
##
## Note that the one exception is Office 2011 updates, because these are only updaters for an
## existing installation, and not full installs.
installNew="Yes"
## The common title bar string to use in all cocoaDialog messages (Primarily applies when SelfService is set)
MsgTitle="IT - Application Updater"
## END - EDITABLE VARIABLES
## Do not edit the script below this line unless changing any of the cocoaDialog message strings
function showHelp ()
{
## This function gets called if no paramater is passed to the script. It outputs a brief 'help' page to stdout.
## The help printout will show up in the policy log.
## Set up Terminal formatting variables
header=$(tput sgr 0 1)$(tput bold)$(tput setaf 25)
normal=$(tput sgr0)
tabs -25
echo "
Update_Core_Apps.sh - usage
${header}App or Plug-In To Update
${normal}For this script to function, parameter 4 (\$4) must be passed to the script.
The following items can be updated or installed new by passing a valid parameter to it.
The table below shows the application or plug-in and corresponding valid strings
(All strings are case insensitive):
${header}App or Plug-In Name Accepted strings
${normal}Java 7/8 \"Java\", \"Oracle Java\"
Flash Player \"Flash\", \"FlashPlayer\", \"Flash Player\", \"Adobe Flash\", \"AdobeFlash\"
Silverlight \"Silverlight\", \"SL\"
Flip Player \"FlipPlayer\", \"Flip Player\", \"WMV Player\", \"Flip4Mac Player\", \"Flip4MacPlayer\"
Firefox \"Firefox\", \"FF\"
Firefox ESR \"FirefoxESR\", \"FFESR\"
VLC \"VLC\", \"VLC Media Player\"
Adobe Reader \"Reader\", \"Adobe Reader\", \"AdobeReader\"
Dropbox \"Dropbox\", \"Drop box\"
Cyberduck \"Cyberduck\", \"Cyber duck\"
The following can only be UPDATED with this script using the below parameter strings:
Office 2011 \"MSO\", \"Office\", \"Office 2011\", \"Office2011\",\"MS Office\", \"MSOffice\"
Microsoft Lync \"Lync\", \"MSLync\", \"MS Lync\", \"Microsoft Lync\"
${header}'Silent' and 'Self Service' modes
${normal}This script is run in a silent mode in its default state. Silent mode will auto update the specified app or plug-in (assuming an update is available) and report on the results.
The script can also be run in a Self Service mode by passing any value to parameter 5 (\$5).
Self Service mode will show dialogs and progress bars to the current user as it downloads and installs the current version of the application or Plug-In.${normal}
" | fold -s -w 100
tabs -8
}
## Get the assigned app or plug-in name from parameter 4
## Exit the script with an error if its blank
if [ "$appName" == "" ] && [ "$4" != "" ]; then
appName="$4"
else
echo "No application or plug-in name was assigned to parameter 4. Printing help page..."
showHelp
exit 1
fi
## Determine if this script should be used in a Self Service mode.
## Usage: If $5 is set to any value in the script parameter, then we set a new "SelfService" variable and
## use Self Service dialogs and prompts throughout the process when required.
## If $5 is not assigned, we assume the script is to be run in "Silent" mode
## Note: to use the script explicitly in Silent Mode, do not assign parameter 5.
if [ "$5" != "" ]; then
SelfService="Yes"
echo -e "\n[Mode]: Self Service"
else
echo -e "\n[Mode]: Silent"
fi
## Get the logged in user's name
loggedInUser=$( ls -l /dev/console | awk '{print $3}' )
## Sanity check for the existence of cocoaDialog. Only checks when SelfService flag is set.
if [ "$SelfService" ]; then
if [ ! -f "$cdPath" ]; then
echo "cocoaDialog was not found on this Mac and the SelfService flag was set. We can't continue..."
"$jhPath" -windowType utility -title "IT" -heading "A problem occurred" -alignHeading center \
-description "A necessary component was not found on this Mac. Please allow up to 24 hours for the situation to correct itself and try again." \
-button1 "OK" -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertCautionIcon.icns"
exit 1
fi
fi
## Create the necessary folder structure for downloads
if [ ! -d "/Library/Application Support/ITUpdater/Downloads/" ]; then
mkdir -p "/Library/Application Support/ITUpdater/Downloads/"
fi
## List of base check URLs
javaCheckURL="http://java.com/en/download/"
flashCheckURL="http://fpdownload2.macromedia.com/get/flashplayer/update/current/xml/version_en_mac_pl.xml"
firefoxCheckURL="http://download-origin.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest/mac/en-US/"
firefoxESRCheckURL="http://download-origin.cdn.mozilla.net/pub/mozilla.org/firefox/releases/latest-esr/mac/en-US/"
## flipPlayerCheckURL="http://www.telestream.net/flip-player/download.htm?keepThis=true&TB_iframe=true&height=420&width=520" ## Deprecated
flipPlayerCheckURL="http://www.telestream.net/flip4mac/overview.htm"
silLightCheckURL="http://www.microsoft.com/getsilverlight/locale/en-us/html/Microsoft%20Silverlight%20Release%20History.htm"
VLCCheckURL="http://update.videolan.org/vlc/sparkle/vlc-intel64.xml"
adbeRdrCheckURL="http://get.adobe.com/reader/"
MSOfficeCheckURL="http://www.microsoft.com/mac/autoupdate/0409MSOf14.xml"
lyncUpdCheckURL="http://www.microsoft.com/mac/autoupdate/0409UCCP14.xml"
dropboxCheckURL="https://www.dropbox.com/download?plat=mac&full=1"
cyberduckCheckURL="http://version.cyberduck.ch/changelog.rss"
## Case statement to set proper URLs, application/plug-in paths and function calls
shopt -s nocasematch
case "$appName" in
Java|"Oracle Java")
properName="Oracle Java" ## Edit this to change the name that appears in dialogs
installerString="java"
type="Plug-In"
installType="PKG"
fileType="dmg"
URL="${javaCheckURL}"
appPath="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin"
runFunc="getJavaVersion"
curlFlag="-L"
versProcessor="cut -d. -f1,2,3"
UAReq="Yes"
CFVers="CFBundleVersion"
iconType="--icon"
iconFile="package" ;;
FlashPlayer|Flash|"Flash Player")
properName="Flash Player" ## Edit this to change the name that appears in dialogs
installerString="flash"
type="Plug-In"
installType="PKG"
fileType="dmg"
URL="${flashCheckURL}"
appPath="/Library/Internet Plug-Ins/Flash Player.plugin"
runFunc="getFlashVersion"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon"
iconFile="package" ;;
Silverlight|SL)
properName="Silverlight" ## Edit this to change the name that appears in dialogs
installerString="silverlight"
type="Plug-In"
installType="PKG"
fileType="dmg"
URL="${silLightCheckURL}"
appPath="/Library/Internet Plug-Ins/Silverlight.plugin"
runFunc="getSilverlightVersion"
UAReq="Yes"
CFVers="CFBundleShortVersionString"
iconType="--icon"
iconFile="package" ;;
FlipPlayer|"Flip Player"|"WMV Player"|"Flip4Mac Player"|Flip4MacPlayer)
properName="Flip Player" ## Edit this to change the name that appears in dialogs
installerString="flip player"
type="application"
installType="APP"
fileType="dmg"
URL="${flipPlayerCheckURL}"
appPath="/Applications/Flip Player.app"
runFunc="getFlipPlayerVersion"
versProcessor="cut -d. -f1,2,3"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon-file"
iconFile="/System/Library/CoreServices/DiskImageMounter.app/Contents/Resources/diskcopy-doc.icns" ;;
Firefox|FF)
properName="Firefox" ## Edit this to change the name that appears in dialogs
installerString="firefox"
type="browser"
installType="APP"
fileType="dmg"
URL="${firefoxCheckURL}"
appPath="/Applications/Firefox.app"
runFunc="getFirefoxVersion"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon-file"
iconFile="/System/Library/CoreServices/DiskImageMounter.app/Contents/Resources/diskcopy-doc.icns" ;;
FirefoxESR|FFESR)
properName="Firefox ESR" ## Edit this to change the name that appears in dialogs
installerString="firefox"
type="browser"
installType="APP"
fileType="dmg"
URL="${firefoxESRCheckURL}"
appPath="/Applications/Firefox.app"
runFunc="getFirefoxVersion"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon-file"
iconFile="/System/Library/CoreServices/DiskImageMounter.app/Contents/Resources/diskcopy-doc.icns" ;;
VLC|"VLC Media Player")
properName="VLC" ## Edit this to change the name that appears in dialogs
installerString="vlc"
type="application"
installType="APP"
fileType="dmg"
URL="${VLCCheckURL}"
appPath="/Applications/VLC.app"
runFunc="getVLCVersion"
curlFlag="-L"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon-file"
iconFile="/System/Library/CoreServices/DiskImageMounter.app/Contents/Resources/diskcopy-doc.icns" ;;
Reader|"Adobe Reader"|AdobeReader)
properName="Adobe Reader" ## Edit this to change the name that appears in dialogs
installerString="adbe"
type="application"
installType="PKG"
fileType="dmg"
URL="${adbeRdrCheckURL}"
appPath="/Applications/Adobe Reader.app"
runFunc="getRdrVersion"
UAReq="Yes"
CFVers="CFBundleShortVersionString"
iconType="--icon"
iconFile="package" ;;
MSO|Office|"Office 2011"|Office2011|"MS Office"|MSOffice)
properName="Office 2011" ## Edit this to change the name that appears in dialogs
installerString="office 2011"
type="suite"
installType="PKG"
fileType="dmg"
URL="${MSOfficeCheckURL}"
appPath="/Applications/Microsoft Office 2011/Office/Microsoft Database Daemon.app"
runFunc="getOfficeVersion"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon"
iconFile="package" ;;
Lync|MSLync|"MS Lync"|"Microsoft Lync")
properName="Microsoft Lync"
installerString="lync"
type="application"
installType="PKG"
fileType="dmg"
URL="${lyncUpdCheckURL}"
appPath="/Applications/Microsoft Lync.app"
runFunc="getLyncVersion"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon"
iconFile="package" ;;
Dropbox|"Drop box")
properName="Dropbox"
installerString="dropbox"
type="application"
installType="APP"
fileType="dmg"
URL="${dropboxCheckURL}"
appPath="/Applications/Dropbox.app"
runFunc="getDropboxVersion"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon-file"
iconFile="/System/Library/CoreServices/DiskImageMounter.app/Contents/Resources/diskcopy-doc.icns" ;;
Cyberduck|"Cyber duck")
properName="Cyberduck"
installerString="cyberduck"
type="application"
installType="APP"
fileType="tar.gz"
URL="${cyberduckCheckURL}"
appPath="/Applications/Cyberduck.app"
runFunc="getCyberduckVersion"
curlFlag="-L"
UAReq="No"
CFVers="CFBundleShortVersionString"
iconType="--icon-file"
iconFile="/System/Library/CoreServices/Archive Utility.app/Contents/Resources/bah-tar.icns" ;;
*)
echo -e "The application, suite or plug-in specified ( ${appName} ) has no reference in this script.\nPlease check your entry and try again."
exit 1
esac
shopt -u nocasematch
firstChar=${properName:0:1}
case "$firstChar" in
A|E|I|O|U)
art="An" ;;
*)
art="A" ;;
esac
function cleanUpAction_Success ()
{
## Description: This function runs on a successful installation of the app or package.
## It will display a successful message to the user and clean up the downloaded files and other items as necessary.
## Now close the progress bar (if necessary)
exec 20>&-
rm -f /tmp/hpipe
if [[ "$updateMode" == "update" ]]; then
headText="The ${properName} update was successful"
mainText="The update for ${properName} was installed successfully. The version installed is now ${updatedVers}."
elif [[ "$updateMode" == "new" ]]; then
headText="The ${properName} installation was successful"
mainText="The installation of ${properName} was successful. The version installed was ${updatedVers}."
fi
## Set up different messaging if we just installed an Office update and at least one of the apps was running
MSOAppsOpen=$(ps axc | awk -F'[0-9] ' '/Microsoft Word|Microsoft Excel|Microsoft PowerPoint|Microsoft Outlook|My Day|Microsoft Office Reminders/{print $NF}')
if [[ "${properName}" == "Office 2011" ]]; then
if [[ "$SelfService" ]] && [[ ! -z "$MSOAppsOpen" ]]; then
headText="The ${properName} update was successful"
mainText="The update for ${properName} was installed successfully. The version installed is now ${updatedVers}.
The following applications were open during the installation. You should quit and relaunch these apps at your earliest convenience to begin using the new version:
$MSOAppsOpen"
else
if [[ "$SelfService" ]] && [[ -z "$MSOAppsOpen" ]]; then
headText="Your ${properName} ${type} was just updated"
mainText="${properName} on your Mac was just updated to version ${updatedVers}."
fi
fi
fi
rm -Rf /Library/Application\ Support/ITUpdater/Downloads/*
rm -f "/Library/Application Support/ITUpdater/NoQuit.xml" 2>/dev/null
## If there is a renamed application bundle, delete it now that the new version is installed
if [ -d "${appPath}_old" ]; then
## Delete the older renamed application
rm -Rfd "${appPath}_old"
fi
## First message
if [ "$SelfService" ]; then
## Show the successful install message to the end user
"$cdPath" msgbox --title "${MsgTitle}" --text "$headText" --informative-text "$mainText" \
--button1 " OK " --width 400 --posY top --icon info --quiet
exit $exit_status
fi
## If SelfService was not set but the app was running during installation,
## send up a message alerting user to relaunch it.
## Not dependent on cocoaDialog being installed. Will use jamfHelper if necessary.
if [[ ! "$SelfService" ]] && [[ "$appRunning" ]]; then
wasOpenMsg="${properName} was just updated to version ${currVers}. The application was running during the upgrade. Please close ${properName} and relaunch it to start using the new version."
if [ -e "$cdPath" ]; then
"$cdPath" msgbox --title "${MsgTitle}" --text "${properName} was updated" \
--informative-text "$wasOpenMsg" --button1 " OK " \
--width 400 --posY top --icon info --quiet
exit $exit_status
else
"$jhPath" -windowType utility -title "${MsgTitle}" -description "$wasOpenMsg" -button1 "OK" -defaultButton 1 -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns"
exit $exit_status
fi
else
if [[ ! "$SelfService" ]]; then
if [[ "${properName}" == "Office 2011" ]] && [[ ! -z "$MSOAppsOpen" ]]; then
if [ -e "$cdPath" ]; then
"$cdPath" msgbox --title "${MsgTitle}" --text "${headText}" \
--informative-text "${mainText}" --button1 " OK " --width 400 \
--posY top --icon info --quiet
exit $exit_status
else
"$jhPath" -windowType utility -title "${MsgTitle}" -heading "${headText}" -description "${mainText}" -button1 "OK" -defaultButton 1 -icon "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ToolbarInfo.icns"
exit $exit_status
fi
else
exit $exit_status
fi
fi
fi
}
function cleanUpAction_Failure ()
{
## Description: This function runs on a failed installation of the app or package.
## It will display a failure message to the user (if SelfService is set) and clean up the downloaded files and other items as necessary.
## Now close the progress bar (if necessary)
exec 20>&-
rm -f /tmp/hpipe
if [[ "$exit_status" == "1" ]]; then
mainTextFail="The installation of ${properName} has failed. Your original application was left in place.
You can try running the policy again later. If you continue to encounter problems, contact the Help Desk for assistance and mention error code $exit_status"
elif [[ "$exit_status" == "2" ]]; then
mainTextFail="An installable package couldn't be found in the disk image. It may have been corrupted, or there was a problem with the script that needs to be corrected.
You can try running the policy again later. If you continue to encounter problems, contact the Help Desk for assistance and mention error code $exit_status"
elif [[ "$exit_status" == "3" ]]; then
mainTextFail="The disk image could not be mounted to install the update. It may have been corrupted during the download.
You can try running the policy again later. If you continue to encounter problems, contact the Help Desk for assistance and mention error code $exit_status."
fi
if [[ "${properName}" == "Office 2011" ]]; then
## If there are Office 2011 update(s), delete contents of Downloads directory and xml file
echo "Deleting downloaded disk image(s) and xml file..."
rm -Rfd "/Library/Application Support/ITUpdater/Downloads/*"
rm -f "/Library/Application Support/ITUpdater/NoQuit.xml"
else
## Delete the downloaded disk image from /Library/Application Support/ITUpdater/Downloads/
echo "Deleting downloaded disk image..."
rm -f "/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}"
fi
## If we previously renamed the target application,
## reset the name and make it visible again
if [[ -d "${appPath}_old" ]]; then
mv "${appPath}_old" "${appPath}"
chflags nohidden "${appPath}"
fi
if [ "$SelfService" ]; then
"$cdPath" msgbox --title "${MsgTitle}" --text "Installation failed" --informative-text "$mainTextFail" \
--button1 " OK " --width 400 --posY top --icon caution --quiet
fi
## Uncomment the below line to have the script exit without sending out an error email
exit $exit_status
}
function getNewVers ()
{
## Description: This function is called at the end of an installation to check the new version number
## to ensure it is what we expect. The function will call another function based on success or failure results.
let StepNum=$StepNum+1
if [ "$updateMode" == "update" ]; then
echo "[Stage ${StepNum}]: ${properName} update installation was successful. Checking new version for confirmation..."
elif [ "$updateMode" == "new" ]; then
echo "[Stage ${StepNum}]: ${properName} installation was successful. Checking installed version for confirmation..."
fi
## Get the new version number from disk to ensure it matches the expected current version
updatedVers=$( /usr/bin/defaults read "${appPath}/Contents/Info.plist" ${CFVers} )
## If the assigned application has a versProcessor var assigned, run it to generate a modified version string
if [ ! -z "$versProcessor" ]; then
updatedVers=$( eval echo "$updatedVers" | $versProcessor )
fi
if [[ "${updatedVers}" == "${currVers}" ]]; then
echo "[Final Result]: Confirmed the new version of ${properName} on disk is now ${currVers}..."
exit_status=0
cleanUpAction_Success
else
echo "[Final Result]: New version and latest version do not match. Installation may have failed..."
exit_status=1
cleanUpAction_Failure
fi
}
function untarUpdate ()
{
## Description: This function is called when the downloaded file is in tar.gz format.
## The tar.gz file's total line count is calculated and used for extraction progress
echo "[Stage ${StepNum}]: Extracting archive for ${properName}..."
## Generate the proper path for extraction based on full application path
untarLoc=$( echo "$appPath" | awk -F'/' 'sub(FS $NF,x)' )
extractionFile="/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}"
if [ "$SelfService" ]; then
## Check to see if the application is running
AppProc=$( ps axc | grep -i "${properName}" )
if [[ "$AppProc" != "" ]]; then
appOpenText="Please quit ${properName}, then click Continue to proceed with the installation."
echo "0 ${properName} is running..." >&20
quitAppMsg=$( "$cdPath" msgbox --title "$MsgTitle" --text "${properName} is running" \
--informative-text "$appOpenText" --button1 " Continue " --button2 " Cancel " \
--width 400 --icon caution --posY center )
if [[ "$quitAppMsg" == "1" ]]; then
untarUpdate
else
echo "100 Installation has been cancelled..." >&20
hdiutil detach -force "${updateVolName}"
sleep 0.5
rm -f "/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}"
exit 0
fi
else
## If an existing version of the target app is in the /Applications/ path,
## rename and hide it before copying in the new version
if [ -d "${appPath}" ]; then
echo "0 Removing any previous version..." >&20
echo " Renaming previous installation"
mv "${appPath}" "${appPath}_old" 2> /dev/null
chflags hidden "${appPath}_old" 2> /dev/null
fi
sleep 1
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Copying ${updateAPPName} to /Applications/"
## Count the total lines in the extraction
echo "0 Please wait. Calculating installation..." >&20
noLines=$( tar tzvf "$extractionFile" 2>&1 | wc -l | sed 's/^ *//' )
linect=0
while read line; do
pct=$(expr $linect \* 100 / $noLines)
echo "$pct ${pct}% - Please wait. Installing ${properName}..." >&20
linect=$((linect+1))
done < <( tar -xvf "$extractionFile" -C "${untarLoc}/" 2>&1 )
## Check to make sure the copy was successful
if [[ ! -d "${appPath}" ]]; then
echo " ${properName} app could not be copied to the Applications folder"
exit_status=1
cleanUpAction_Failure
fi
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Adjusting permissions on ${appPath}"
chown -R ${loggedInUser}:staff "${appPath}"
chmod -R 755 "${appPath}"
if [[ $(xattr -l "${appPath}" | grep "com.apple.quarantine") ]]; then
echo " Removing quarantine flag on ${appPath}"
xattr -d com.apple.quarantine "${appPath}"
fi
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Install done. Cleaning up..."
## Something goes here
sleep 0.5
## Run the function to get the new version number
getNewVers
fi
fi
## If SelfService mode is not set, check to see if the target application is open
## Set a flag for later if the app is currently open
## Check to see if the application is running
AppProc=$( ps axc | grep -i "${properName}" )
if [[ ! "$SelfService" ]]; then
if [[ "$AppProc" != "" ]]; then
appRunning="yes"
fi
## Silent mode operation
## Extract the file into its final destination
tar -xvf "$extractionFile" -C "${untarLoc}/"
sleep 0.5
## Check to make sure the copy was successful
if [[ ! -d "${appPath}" ]]; then
echo " ${properName} app could not be copied to the Applications folder"
exit_status=1
cleanUpAction_Failure
fi
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Adjusting permissions on ${appPath}"
chown -R ${loggedInUser}:staff "${appPath}"
chmod -R 755 "${appPath}"
if [[ $(xattr -l "${appPath}" | grep "com.apple.quarantine") ]]; then
echo " Removing quarantine flag on ${appPath}"
xattr -d com.apple.quarantine "${appPath}"
fi
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Install done. Cleaning up..."
## Something goes here
sleep 0.5
## Run the function to get the new version number
getNewVers
fi
}
function copyAPPUpdate2 ()
{
## Description: This function is called when the specified app is in an app bundle format.
## It gets called from copyAPPUpdate1 and determines if the application is running if the SelfService flag is set.
## If SelfService is set and the app is running, it prompts the user to quit the app before proceeding, or allows the user to cancel the operation.
## Check to see if the application is running
AppProc=$( ps axc | grep -i "${properName}" )
if [[ "$SelfService" ]]; then
if [[ "$AppProc" != "" ]]; then
appOpenText="Please quit ${properName}, then click Continue to proceed with the installation."
echo "0 ${properName} is running..." >&20
quitAppMsg=$( "$cdPath" msgbox --title "$MsgTitle" --text "${properName} is running" \
--informative-text "$appOpenText" --button1 " Continue " --button2 " Cancel " \
--width 400 --icon caution --posY center )
if [[ "$quitAppMsg" == "1" ]]; then
copyAPPUpdate2
else
echo "100 Installation has been cancelled..." >&20
hdiutil detach -force "${updateVolName}"
sleep 0.5
rm -f "/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}"
exit 0
fi
else
## If an existing version of the target app is in the /Applications/ path,
## rename and hide it before copying in the new version
if [ -d "${appPath}" ]; then
echo "0 Removing any previous version..." >&20
echo " Renaming previous installation"
mv "${appPath}" "${appPath}_old" 2> /dev/null
chflags hidden "${appPath}_old" 2> /dev/null
fi
sleep 1
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Copying ${updateAPPName} to /Applications/"
## Copy the application to the /Applications/ folder, calculate progress and feed it back to cocoaDialog
while read line; do
if [[ $(echo "$line" | grep "^copying") ]]; then
dlSize=$(du -sk "/Applications/${updateAPPName}" | awk '{print $1}' 2>/dev/null)
if [ "$dlSize" != "" ]; then
let pct=$(expr ${dlSize} \* 100 / ${origSize})
echo "$pct ${pct}% - Please wait. Installing ${properName}..." >&20
fi
fi
done < <(ditto -V "${updateVolName}/${updateAPPName}" "/Applications/${updateAPPName}" 2>&1)
sleep 1
if [[ ! -d "${appPath}" ]]; then
echo "${properName} app could not be copied to the Applications folder"
exit_status=1
cleanUpAction_Failure
fi
let StepNum=$StepNum+1
echo "20 Fixing permissions on the application..." >&20
sleep 0.5
echo "[Stage ${StepNum}]: Adjusting permissions on ${appPath}, and removing quarantine flag"
echo "40 Fixing permissions on the application..." >&20
chown -R ${loggedInUser}:staff "${appPath}"
chmod -R 755 "${appPath}"
if [[ $(xattr -l "${appPath}" | grep "com.apple.quarantine") ]]; then
echo " Removing quarantine flag on ${appPath}"
xattr -d com.apple.quarantine "${appPath}"
fi
sleep 0.5
echo "60 Checking application..." >&20
sleep 0.5
echo "80 Installation complete. Please wait..." >&20
sleep 0.5
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Install done. Cleaning up..."
echo "90 Cleaning up..." >&20
echo " Unmounting volume..."
hdiutil detach -force "${updateVolName}"
sleep 0.5
echo "100 Checking new version for ${prpperName}..." >&20
## Run the function to get the new version number
getNewVers
fi
fi
## If SelfService mode is not set, check to see if the target application is open
## Set a flag for later if the app is currently open
if [[ ! "$SelfService" ]]; then
if [[ "$AppProc" != "" ]]; then
appRunning="yes"
fi
## Copy the application from the mounted disk image to /Applications silently.
## Note: This will overwrite the application in place, even while running.
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Copying ${updateAPPName} to /Applications/..."
cp -R "${updateVolName}/${updateAPPName}" "/Applications/"
## Check to make sure the copy was successful
if [[ ! -d "${appPath}" ]]; then
echo " ${properName} app could not be copied to the Applications folder"
exit_status=1
cleanUpAction_Failure
fi
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Adjusting permissions on ${appPath}"
chown -R ${loggedInUser}:staff "${appPath}"
chmod -R 755 "${appPath}"
if [[ $(xattr -l "${appPath}" | grep "com.apple.quarantine") ]]; then
echo " Removing quarantine flag on ${appPath}"
xattr -d com.apple.quarantine "${appPath}"
fi
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Install done. Cleaning up..."
echo " Unmounting volume..."
hdiutil detach -force "${updateVolName}"
sleep 0.5
## Run the function to get the new version number
getNewVers
fi
}
function copyAPPUpdate1 ()
{
## Description: This function is called when the specified app is in an app bundle format.
## It first mounts the disk image, gets the application size, and then calls function copyAPPUpdate2.
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Silently mounting the ${properName} disk image..."
if [ "$SelfService" ]; then
echo "0 Accessing downloaded file..." >&20
fi
## Mount the disk image and capture the mounted volume's name
if [[ "${properName}" == "Flip Player" ]]; then
updateVolName=$( echo "Y" | /usr/bin/hdiutil attach "/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}" -nobrowse -noverify -noautoopen 2>&1 | awk -F'[\t]' '/\/Volumes/{ print $NF }' )
else
updateVolName=$( /usr/bin/hdiutil attach "/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}" -nobrowse -noverify -noautoopen 2>&1 | awk -F'[\t]' '/\/Volumes/{ print $NF }' )
fi
if [ "$?" == "0" ]; then
## Get the package name in the mounted disk image
updateAPPName=$( ls "$updateVolName" | grep ".app$" | grep -i "${installerString}" )
if [ "$updateAPPName" ]; then
echo " A matching app bundle was found on the mounted volume - ${updateAPPName}"
if [ "$SelfService" ]; then
echo "0 Checking application..." >&20
origSize=$(du -sk "${updateVolName}/${updateAPPName}" | awk '{print $1}')
echo "0 Checking to see if ${properName} is running..." >&20
copyAPPUpdate2
else
copyAPPUpdate2
fi
else
echo " Mounting of the disk image failed. Exit"
## We need to put some dialog here
exit 1
fi
else
echo " Couldn't locate an app bundle on the mounted volume. Exiting..."
## We need to put some dialog here
exit 1
fi
}
function installPKGUpdate ()
{
## Description: This function is called when the specified app is in a package install format and SelfService is not set.
## It first mounts the disk image, gets the volume name, then proceeds with the installation.
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Silently mounting the ${properName} disk image..."
updateVolName=$( /usr/bin/hdiutil attach "/Library/Application Support/ITUpdater/Downloads/${properName}_${currVers}.${fileType}" -nobrowse -noverify -noautoopen 2>&1 | awk -F'[\t]' '/\/Volumes/{ print $NF }' )
if [[ "$?" == "0" ]]; then
## Get the package name in the mounted disk image
if [[ "${properName}" == "Oracle Java" ]]; then
updatePKGName=$( ls "$updateVolName" | egrep ".pkg$|.mpkg$|.app" | grep -i "${installerString}" )
if [[ "${updatePKGName##*.}" == "app" ]]; then
updatePKGName="${updatePKGName}/Contents/Resources/JavaAppletPlugin.pkg"
fi
else
updatePKGName=$( ls "$updateVolName" | egrep ".pkg$|.mpkg$" | grep -i "${installerString}" )
fi
if [[ ! -z "${updatePKGName}" ]]; then
echo " A package was located in the mounted volume. Getting package details..."
sleep 1
echo "Installing the ${properName} pkg update..."
## If the update if for Office 2011, run a separate install loop that uses the NoQuit.xml
## Check for the successful upgrade line to set the installation status
if [[ "${properName}" == "Office 2011" ]]; then
installStatus=1
while read line; do
if [[ $( echo "$line" | egrep "The upgrade was successful|The install was successful" ) ]]; then
installStatus=0
fi
done < <(/usr/sbin/installer -pkg "${updateVolName}/${updatePKGName}" -tgt / -allowUntrusted -applyChoiceChangesXML "/Library/Application Support/ITUpdater/NoQuit.xml" -verboseR 2>&1)
else
## Install the pkg while reading output from installer
## Check for the successful upgrade line to set the installation status
installStatus=1
while read line; do
if [[ $( echo "$line" | egrep "The upgrade was successful|The install was successful" ) ]]; then
installStatus=0
fi
done < <(/usr/sbin/installer -pkg "${updateVolName}/${updatePKGName}" -tgt / -allowUntrusted -verboseR 2>&1)
fi
## Pause 1 second to allow installation to finish out
sleep 1
## Unmount the volume (use -force flag in case of locked files)
hdiutil detach "${updateVolName}" -force
## Now check the installation results
if [[ "$installStatus" == "0" ]]; then
## Get the new version number
getNewVers
else
## If we didn't get a status 0 returned from the installation, exit with an error code
echo "Installation exited with an error code. Install failed..."
exit_status=1
cleanUpAction_Failure
fi
else
echo "Could not locate the package in the mounted volume. There was a problem."
exit_status=2
cleanUpAction_Failure
fi
else
echo "Mounting of the disk image failed. Exit"
exit_status=3
cleanUpAction_Failure
fi
}
function installMSOUpdatesSS ()
{
## Description: This function is called when the application to be updated is Office 2011
## and the update requires both SP1 and the latest update, and the SelfService flag is set..
## This function loops through the installs, displaying status of each one.
## Create array with the DMG names
while read item; do
MSODMGs+=("$item")
done < <(ls "/Library/Application Support/ITUpdater/Downloads/" | grep ".${fileType}$")
for DMG in "${MSODMGs[@]}"; do
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Silently mounting the ${DMG} disk image..."
echo "0 Accessing downloaded file..." >&20
updateVolName=$( /usr/bin/hdiutil attach "/Library/Application Support/ITUpdater/Downloads/$DMG" -nobrowse -noverify -noautoopen 2>&1 | awk -F'[\t]' '/\/Volumes/{ print $NF }' )
if [[ "$?" == "0" ]]; then
## Get the package name in the mounted disk image
updatePKGName=$( ls "$updateVolName" | egrep ".pkg$|.mpkg" | grep -i "${installerString}" )
if [[ ! -z "${updatePKGName}" ]]; then
echo " A package was located in the mounted volume. Getting package details..."
sleep 1
echo "0 Preparing for installation..." >&20
let StepNum=$StepNum+1
echo "[Stage ${StepNum}]: Installing the ${properName} pkg update..."
sleep 1
## Install the pkg while reading output from installer
## Check for the successful upgrade line to set the installation status
installStatus=1
while read line; do
## Get updated percentage from current installation and send to progressbar
thePct=$( echo "$line" | awk -F"%" '/%/{ print $2 }' | cut -d. -f1 | sed '/^$/d' )
echo "$thePct ${thePct}% - Installing \"${updatePKGName}\"" >&20
if [[ $( echo "$line" | egrep "The upgrade was successful|The install was successful" ) ]]; then
installStatus=0
fi
done < <(/usr/sbin/installer -pkg "${updateVolName}/${updatePKGName}" -tgt / -allowUntrusted -applyChoiceChangesXML "/Library/Application Support/ITUpdater/NoQuit.xml" -verboseR 2>&1)
## Pause 1 second to allow installation to finish out
sleep 1
## Unmount the volume (use -force flag in case of locked files)
hdiutil detach "${updateVolName}" -force
else
echo " Mounting of the disk image failed. Exit"
## We need to put some dialog here
exit_status=3
cleanUpAction_Failure
fi
fi
done
sleep 1
## Now close the progress bar
exec 20>&-
rm -f /tmp/hpipe
## Now check the installation results
if [[ "$installStatus" == "0" ]]; then
## Get the new version number
getNewVers
else
## If we didn't get a status 0 returned from the installation, exit with an error code
echo "Installation exited with an error code. Install failed..."
exit_status=1
cleanUpAction_Failure
fi
}
function installMSOUpdates ()
{