update dev300-m57
[ooovba.git] / setup_native / scripts / osx_install_patch.applescript
blob33a9d4126339a2ae5b676a4c386f837db138d13a
1 (*
2 This script is meant to
3 1) Identify installed instances of the product
4 2) check whether the user has write-access (and if not
5 ask for authentification)
6 3) install the shipped tarball
7 *)
9 -- strings for localisations - to be meant to be replaced
10 -- by a makefile or similar
11 set OKLabel to "[OKLabel]"
12 set InstallLabel to "[InstallLabel]"
13 set AbortLabel to "[AbortLabel]"
14 set intro to "[IntroText1]
16 [IntroText2]
18 [IntroText3]"
19 set chooseMyOwn to "[ChooseMyOwnText]"
20 set listPrompt to "[ListPromptText]"
21 set chooseManual to "[ChooseManualText]"
22 set listOKLabel to "[ListOKLabelText]"
23 set listCancelLabel to "[ListCancelLabel]"
24 set appInvalid to "[AppInvalidText1]
26 [AppInvalidText2]" -- string will begin with the chosen application's name
27 set startInstall to "[StartInstallText1]
29 [StartInstallText2]"
30 set IdentifyQ to "[IdentifyQText]
32 [IdentifyQText2]"
33 set IdentifyYES to "[IdentifyYES]"
34 set IdentifyNO to "[IdentifyNO]"
35 set installFailed to "[InstallFailedText]"
36 set installComplete to "[InstallCompleteTextPatch]"
38 set sourcedir to (do shell script "dirname " & quoted form of POSIX path of (path to of me))
40 display dialog intro buttons {AbortLabel, InstallLabel} default button 2
42 if (button returned of result) is AbortLabel then
43 return 2
44 end if
46 set the found_ooos to (do shell script "mdfind \"kMDItemContentType == 'com.apple.application-bundle' && kMDItemDisplayName == '[PRODUCTNAME]*' && kMDItemDisplayName != '[FULLPRODUCTNAME].app'\"") & "
47 " & chooseMyOwn
49 -- the choice returned is of type "list"
50 -- Show selection dialog only if more than one or no product was found
51 if (get first paragraph of found_ooos) is "" then
52 set the choice to (choose from list of paragraphs in found_ooos default items (get last paragraph of found_ooos) with prompt listPrompt OK button name listOKLabel cancel button name listCancelLabel)
53 if choice is false then
54 -- do nothing, the user cancelled the installation
55 return 2 --aborted by user
56 else if (choice as string) is chooseMyOwn then
57 -- yeah, one needs to use "choose file", otherwise
58 -- the user would not be able to select the .app
59 set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
60 end if
61 else if (get second paragraph of found_ooos) is chooseMyOwn then
62 -- set choice to found installation
63 set the choice to (get first paragraph of found_ooos)
64 else
65 set the choice to (choose from list of paragraphs in found_ooos default items (get first paragraph of found_ooos) with prompt listPrompt OK button name listOKLabel cancel button name listCancelLabel)
66 if choice is false then
67 -- do nothing, the user cancelled the installation
68 return 2 --aborted by user
69 else if (choice as string) is chooseMyOwn then
70 -- yeah, one needs to use "choose file", otherwise
71 -- the user would not be able to select the .app
72 set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
73 end if
74 end if
76 -- now only check whether the path is really from [PRODUCTNAME]
77 try
78 do shell script "grep '<string>[PRODUCTNAME] [PRODUCTVERSION]' " & quoted form of (choice as string) & "/Contents/Info.plist"
79 on error
80 display dialog (choice as string) & appInvalid buttons {InstallLabel} default button 1 with icon 0
81 return 3 --wrong target-directory
82 end try
85 display dialog startInstall buttons {AbortLabel, InstallLabel} default button 2
87 if (button returned of result) is AbortLabel then
88 return 2
89 end if
92 set tarCommand to "/usr/bin/tar -C " & quoted form of (choice as string) & " -xjf " & quoted form of sourcedir & "/tarball.tar.bz2"
93 try
94 do shell script tarCommand
96 on error errMSG number errNUM
97 display dialog IdentifyQ buttons {IdentifyYES, IdentifyNO} with icon 2
98 if (button returned of result) is IdentifyYES then
99 try
100 do shell script tarCommand with administrator privileges
101 on error errMSG number errNUM
102 display dialog installFailed buttons {OKLabel} default button 1 with icon 0
103 -- -60005 username/password wrong
104 -- -128 aborted by user
105 -- 2 error from tar - tarball not found (easy to test)
106 return errNUM
107 end try
108 else
109 return 2 -- aborted by user
110 end if
111 end try
113 display dialog installComplete buttons {OKLabel} default button 1