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
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]
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]
30 set IdentifyQ
to "[IdentifyQText]
33 set IdentifyYES
to "[IdentifyYES]"
34 set IdentifyNO
to "[IdentifyNO]"
35 set installFailed
to "[InstallFailedText]"
36 set installComplete
to "[InstallCompleteText]
38 [InstallCompleteText2]"
40 set sourcedir
to (do shell
script "dirname " & quoted form
of POSIX
path of (
path to of me))
42 display dialog intro
buttons {AbortLabel, InstallLabel}
default button 2
44 if (
button returned
of result)
is AbortLabel
then
48 set the found_ooos
to (do shell
script "mdfind \"kMDItemContentType == 'com.apple.application-bundle' && kMDItemDisplayName == '[PRODUCTNAME]*' && kMDItemDisplayName != '[FULLPRODUCTNAME].app'\"") &
"
51 -- the choice returned is of type "list"
52 -- Show selection dialog only if more than one or no product was found
53 if (
get first paragraph
of found_ooos)
is "" then
54 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)
55 if choice
is false then
56 -- do nothing, the user cancelled the installation
57 return 2 --aborted by user
58 else if (choice
as string)
is chooseMyOwn
then
59 -- yeah, one needs to use "choose file", otherwise
60 -- the user would not be able to select the .app
61 set the choice
to POSIX
path of (
choose file with prompt chooseManual
of type
"com.apple.application-bundle" without showing package
contents and invisibles)
63 else if (
get second paragraph
of found_ooos)
is chooseMyOwn
then
64 -- set choice to found installation
65 set the choice
to (
get first paragraph
of found_ooos)
67 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)
68 if choice
is false then
69 -- do nothing, the user cancelled the installation
70 return 2 --aborted by user
71 else if (choice
as string)
is chooseMyOwn
then
72 -- yeah, one needs to use "choose file", otherwise
73 -- the user would not be able to select the .app
74 set the choice
to POSIX
path of (
choose file with prompt chooseManual
of type
"com.apple.application-bundle" without showing package
contents and invisibles)
78 -- now only check whether the path is really from [PRODUCTNAME]
80 do shell
script "grep '<string>[PRODUCTNAME] [PRODUCTVERSION]' " & quoted form
of (choice
as string) &
"/Contents/Info.plist"
82 display dialog (choice
as string) & appInvalid
buttons {InstallLabel}
default button 1 with icon 0
83 return 3 --wrong target-directory
87 display dialog startInstall buttons {AbortLabel, InstallLabel} default button 2
89 if (button returned of result) is AbortLabel then
94 set tarCommand
to "/usr/bin/tar -C " & quoted form
of (choice
as string) &
" -xjf " & quoted form
of sourcedir &
"/tarball.tar.bz2"
96 do shell
script tarCommand
98 on error errMSG
number errNUM
99 display dialog IdentifyQ
buttons {IdentifyYES, IdentifyNO}
with icon 2
100 if (
button returned
of result)
is IdentifyYES
then
102 do shell
script tarCommand
with administrator privileges
103 on error errMSG
number errNUM
104 display dialog installFailed
buttons {OKLabel}
default button 1 with icon 0
105 -- -60005 username/password wrong
106 -- -128 aborted by user
107 -- 2 error from tar - tarball not found (easy to test)
111 return 2 -- aborted by user
115 display dialog installComplete
buttons {OKLabel}
default button 1