1 cdf0e10cSrcweir(*
2 *5b501c92SAndrew Rist
3 *5b501c92SAndrew Rist  Licensed to the Apache Software Foundation (ASF) under one
4 *5b501c92SAndrew Rist  or more contributor license agreements.  See the NOTICE file
5 *5b501c92SAndrew Rist  distributed with this work for additional information
6 *5b501c92SAndrew Rist  regarding copyright ownership.  The ASF licenses this file
7 *5b501c92SAndrew Rist  to you under the Apache License, Version 2.0 (the
8 *5b501c92SAndrew Rist  "License"); you may not use this file except in compliance
9 *5b501c92SAndrew Rist  with the License.  You may obtain a copy of the License at
10 *5b501c92SAndrew Rist
11 *5b501c92SAndrew Rist    http://www.apache.org/licenses/LICENSE-2.0
12 *5b501c92SAndrew Rist
13 *5b501c92SAndrew Rist  Unless required by applicable law or agreed to in writing,
14 *5b501c92SAndrew Rist  software distributed under the License is distributed on an
15 *5b501c92SAndrew Rist  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 *5b501c92SAndrew Rist  KIND, either express or implied.  See the License for the
17 *5b501c92SAndrew Rist  specific language governing permissions and limitations
18 *5b501c92SAndrew Rist  under the License.
19 *5b501c92SAndrew Rist
20 *5b501c92SAndrew Rist
21 *5b501c92SAndrew Rist
22 cdf0e10cSrcweirThis script is meant to
23 cdf0e10cSrcweir	1) Identify installed instances of the product
24 cdf0e10cSrcweir	2) check whether the user has write-access (and if not
25 cdf0e10cSrcweir	ask for authentification)
26 cdf0e10cSrcweir	3) install the shipped tarball
27 cdf0e10cSrcweir*)
28 cdf0e10cSrcweir
29 cdf0e10cSrcweir-- strings for localisations - to be meant to be replaced
30 cdf0e10cSrcweir-- by a makefile or similar
31 cdf0e10cSrcweirset OKLabel to "[OKLabel]"
32 cdf0e10cSrcweirset InstallLabel to "[InstallLabel]"
33 cdf0e10cSrcweirset AbortLabel to "[AbortLabel]"
34 cdf0e10cSrcweirset intro to "[IntroText1]
35 cdf0e10cSrcweir
36 cdf0e10cSrcweir[IntroText2]
37 cdf0e10cSrcweir
38 cdf0e10cSrcweir[IntroText3]"
39 cdf0e10cSrcweirset chooseMyOwn to "[ChooseMyOwnText]"
40 cdf0e10cSrcweirset listPrompt to "[ListPromptText]"
41 cdf0e10cSrcweirset chooseManual to "[ChooseManualText]"
42 cdf0e10cSrcweirset listOKLabel to "[ListOKLabelText]"
43 cdf0e10cSrcweirset listCancelLabel to "[ListCancelLabel]"
44 cdf0e10cSrcweirset appInvalid to "[AppInvalidText1]
45 cdf0e10cSrcweir
46 cdf0e10cSrcweir[AppInvalidText2]" -- string will begin with the chosen application's name
47 cdf0e10cSrcweirset startInstall to "[StartInstallText1]
48 cdf0e10cSrcweir
49 cdf0e10cSrcweir[StartInstallText2]"
50 cdf0e10cSrcweirset IdentifyQ to "[IdentifyQText]
51 cdf0e10cSrcweir
52 cdf0e10cSrcweir[IdentifyQText2]"
53 cdf0e10cSrcweirset IdentifyYES to "[IdentifyYES]"
54 cdf0e10cSrcweirset IdentifyNO to "[IdentifyNO]"
55 cdf0e10cSrcweirset installFailed to "[InstallFailedText]"
56 cdf0e10cSrcweirset installComplete to "[InstallCompleteTextPatch]"
57 cdf0e10cSrcweir
58 cdf0e10cSrcweirset sourcedir to (do shell script "dirname " & quoted form of POSIX path of (path to of me))
59 cdf0e10cSrcweir
60 cdf0e10cSrcweirdisplay dialog intro buttons {AbortLabel, InstallLabel} default button 2
61 cdf0e10cSrcweir
62 cdf0e10cSrcweirif (button returned of result) is AbortLabel then
63 cdf0e10cSrcweir	return 2
64 cdf0e10cSrcweirend if
65 cdf0e10cSrcweir
66 cdf0e10cSrcweirset the found_ooos_all to (do shell script "mdfind \"kMDItemContentType == 'com.apple.application-bundle' && kMDItemDisplayName == '[PRODUCTNAME]*' && kMDItemDisplayName != '[FULLAPPPRODUCTNAME].app'\"") & "
67 cdf0e10cSrcweir" & chooseMyOwn
68 cdf0e10cSrcweir
69 cdf0e10cSrcweirset found_ooos_all_paragraphs to paragraphs in found_ooos_all
70 cdf0e10cSrcweir
71 cdf0e10cSrcweirset found_ooos to {}
72 cdf0e10cSrcweirrepeat with currentApp in found_ooos_all_paragraphs
73 cdf0e10cSrcweir	if currentApp does not start with "/Volumes" then
74 cdf0e10cSrcweir		copy currentApp to the end of found_ooos
75 cdf0e10cSrcweir	end if
76 cdf0e10cSrcweirend repeat
77 cdf0e10cSrcweir
78 cdf0e10cSrcweir-- repeat with oneApp in found_ooos
79 cdf0e10cSrcweir--  display dialog oneApp
80 cdf0e10cSrcweir-- end repeat
81 cdf0e10cSrcweir
82 cdf0e10cSrcweir-- the choice returned is of type "list"
83 cdf0e10cSrcweir-- Show selection dialog only if more than one or no product was found
84 cdf0e10cSrcweir-- The first item is an empty string, if no app was found and no app started with "/Volumes"
85 cdf0e10cSrcweir-- The first item is chooseMyOwn, if no app was found and at least one app started with "/Volumes"
86 cdf0e10cSrcweirif (get first item of found_ooos as string) is "" then
87 cdf0e10cSrcweir  set the choice to (choose from list found_ooos default items (get second item of found_ooos) with prompt listPrompt OK button name listOKLabel cancel button name listCancelLabel)
88 cdf0e10cSrcweir  if choice is false then
89 cdf0e10cSrcweir	  -- do nothing, the user cancelled the installation
90 cdf0e10cSrcweir    	return 2 --aborted by user
91 cdf0e10cSrcweir  else if (choice as string) is chooseMyOwn then
92 cdf0e10cSrcweir	  -- yeah, one needs to use "choose file", otherwise
93 cdf0e10cSrcweir	  -- the user would not be able to select the .app
94 cdf0e10cSrcweir	  set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
95 cdf0e10cSrcweir  end if
96 cdf0e10cSrcweirelse if (get first item of found_ooos as string) is chooseMyOwn then
97 cdf0e10cSrcweir  set the choice to (choose from list found_ooos default items (get first item of found_ooos) with prompt listPrompt OK button name listOKLabel cancel button name listCancelLabel)
98 cdf0e10cSrcweir  if choice is false then
99 cdf0e10cSrcweir	  -- do nothing, the user cancelled the installation
100 cdf0e10cSrcweir    	return 2 --aborted by user
101 cdf0e10cSrcweir  else if (choice as string) is chooseMyOwn then
102 cdf0e10cSrcweir	  -- yeah, one needs to use "choose file", otherwise
103 cdf0e10cSrcweir	  -- the user would not be able to select the .app
104 cdf0e10cSrcweir	  set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
105 cdf0e10cSrcweir  end if
106 cdf0e10cSrcweirelse if (get second item of found_ooos as string) is chooseMyOwn then
107 cdf0e10cSrcweir  -- set choice to found installation
108 cdf0e10cSrcweir  -- set the choice to (get first paragraph of found_ooos)
109 cdf0e10cSrcweir  set the choice to (get first item of found_ooos)
110 cdf0e10cSrcweirelse
111 cdf0e10cSrcweir  set the choice to (choose from list found_ooos default items (get first item of found_ooos) with prompt listPrompt OK button name listOKLabel cancel button name listCancelLabel)
112 cdf0e10cSrcweir  if choice is false then
113 cdf0e10cSrcweir	  -- do nothing, the user cancelled the installation
114 cdf0e10cSrcweir    	return 2 --aborted by user
115 cdf0e10cSrcweir  else if (choice as string) is chooseMyOwn then
116 cdf0e10cSrcweir	  -- yeah, one needs to use "choose file", otherwise
117 cdf0e10cSrcweir	  -- the user would not be able to select the .app
118 cdf0e10cSrcweir	  set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
119 cdf0e10cSrcweir  end if
120 cdf0e10cSrcweirend if
121 cdf0e10cSrcweir
122 cdf0e10cSrcweir-- now only check whether the path is really from [PRODUCTNAME]
123 cdf0e10cSrcweirtry
124 cdf0e10cSrcweir	do shell script "grep '<string>[PRODUCTNAME] [PRODUCTVERSION]'   " & quoted form of (choice as string) & "/Contents/Info.plist"
125 cdf0e10cSrcweiron error
126 cdf0e10cSrcweir	display dialog (choice as string) & appInvalid buttons {InstallLabel} default button 1 with icon 0
127 cdf0e10cSrcweir	return 3 --wrong target-directory
128 cdf0e10cSrcweirend try
129 cdf0e10cSrcweir
130 cdf0e10cSrcweir(*
131 cdf0e10cSrcweirdisplay dialog startInstall buttons {AbortLabel, InstallLabel} default button 2
132 cdf0e10cSrcweir
133 cdf0e10cSrcweirif (button returned of result) is AbortLabel then
134 cdf0e10cSrcweir	return 2
135 cdf0e10cSrcweirend if
136 cdf0e10cSrcweir*)
137 cdf0e10cSrcweir
138 cdf0e10cSrcweirset tarCommand to "/usr/bin/tar -C " & quoted form of (choice as string) & " -xjf " & quoted form of sourcedir & "/tarball.tar.bz2"
139 cdf0e10cSrcweirtry
140 cdf0e10cSrcweir	do shell script tarCommand
141 cdf0e10cSrcweir
142 cdf0e10cSrcweiron error errMSG number errNUM
143 cdf0e10cSrcweir	display dialog IdentifyQ buttons {IdentifyYES, IdentifyNO} with icon 2
144 cdf0e10cSrcweir	if (button returned of result) is IdentifyYES then
145 cdf0e10cSrcweir		try
146 cdf0e10cSrcweir			do shell script tarCommand with administrator privileges
147 cdf0e10cSrcweir		on error errMSG number errNUM
148 cdf0e10cSrcweir			display dialog installFailed buttons {OKLabel} default button 1 with icon 0
149 cdf0e10cSrcweir			-- -60005 username/password wrong
150 cdf0e10cSrcweir			-- -128   aborted by user
151 cdf0e10cSrcweir			-- 2 error from tar - tarball not found (easy to test)
152 cdf0e10cSrcweir			return errNUM
153 cdf0e10cSrcweir		end try
154 cdf0e10cSrcweir	else
155 cdf0e10cSrcweir		return 2 -- aborted by user
156 cdf0e10cSrcweir	end if
157 cdf0e10cSrcweirend try
158 cdf0e10cSrcweir
159 cdf0e10cSrcweirdisplay dialog installComplete buttons {OKLabel} default button 1
160