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