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