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