Branch libreoffice-5-0-4
[LibreOffice.git] / setup_native / scripts / osx_install_languagepack.applescript
blobcbd7743b242f45905e3706869feadc6cdb8d8f9c
1 (*
3 This file is part of the LibreOffice project.
5 This Source Code Form is subject to the terms of the Mozilla Public
6 License, v. 2.0. If a copy of the MPL was not distributed with this
7 file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 This file incorporates work covered by the following license notice:
11 Licensed to the Apache Software Foundation (ASF) under one or more
12 contributor license agreements. See the NOTICE file distributed
13 with this work for additional information regarding copyright
14 ownership. The ASF licenses this file to you under the Apache
15 License, Version 2.0 (the "License"); you may not use this file
16 except in compliance with the License. You may obtain a copy of
17 the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 This script is meant to
20 1) Identify installed instances of the product
21 2) check whether the user has write-access (and if not
22 ask for authentification)
23 3) install the shipped tarball
26 -- strings for localisations - to be meant to be replaced
27 -- by a makefile or similar
28 set OKLabel to "[OKLabel]"
29 set InstallLabel to "[InstallLabel]"
30 set AbortLabel to "[AbortLabel]"
31 set intro to "[IntroText1]
33 [IntroText2]
35 [IntroText3]"
36 set chooseMyOwn to "[ChooseMyOwnText]"
37 set listPrompt to "[ListPromptText]"
38 set chooseManual to "[ChooseManualText]"
39 set listOKLabel to "[ListOKLabelText]"
40 set listCancelLabel to "[ListCancelLabel]"
41 set appInvalid to "[AppInvalidText1]
43 [AppInvalidText2]" -- string will begin with the chosen application's name
44 set startInstall to "[StartInstallText1]
46 [StartInstallText2]"
47 set IdentifyQ to "[IdentifyQText]
49 [IdentifyQText2]"
50 set IdentifyYES to "[IdentifyYES]"
51 set IdentifyNO to "[IdentifyNO]"
52 set installFailed to "[InstallFailedText]"
53 set installComplete to "[InstallCompleteText]
55 [InstallCompleteText2]"
57 set sourcedir to (do shell script "dirname " & quoted form of POSIX path of (path to of me))
59 activate
60 display dialog intro buttons {AbortLabel, InstallLabel} default button 2
62 if (button returned of result) is AbortLabel then
63 return 2
64 end if
66 set found_ooos_all to ""
67 -- command might return an error if spotlight is disabled completely
68 try
69 set found_ooos_all to (do shell script "mdfind \"kMDItemContentType == 'com.apple.application-bundle' && kMDItemDisplayName == '[PRODUCTNAME]*' && kMDItemDisplayName != '[FULLAPPPRODUCTNAME].app'\"")
70 end try
71 set found_ooos_all to found_ooos_all & "
72 " & chooseMyOwn
74 set found_ooos_all_paragraphs to paragraphs in found_ooos_all
76 set found_ooos to {}
77 repeat with currentApp in found_ooos_all_paragraphs
78 if currentApp does not start with "/Volumes" then
79 copy currentApp to the end of found_ooos
80 end if
81 end repeat
83 -- repeat with oneApp in found_ooos
84 -- display dialog oneApp
85 -- end repeat
87 -- the choice returned is of type "list"
88 -- Show selection dialog only if more than one or no product was found
89 -- The first item is an empty string, if no app was found and no app started with "/Volumes"
90 -- The first item is chooseMyOwn, if no app was found and at least one app started with "/Volumes"
91 if (get first item of found_ooos as string) is "" then
92 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)
93 if choice is false then
94 -- do nothing, the user cancelled the installation
95 return 2 --aborted by user
96 else if (choice as string) is chooseMyOwn then
97 -- yeah, one needs to use "choose file", otherwise
98 -- the user would not be able to select the .app
99 set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
100 end if
101 else if (get first item of found_ooos as string) is chooseMyOwn then
102 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)
103 if choice is false then
104 -- do nothing, the user cancelled the installation
105 return 2 --aborted by user
106 else if (choice as string) is chooseMyOwn then
107 -- yeah, one needs to use "choose file", otherwise
108 -- the user would not be able to select the .app
109 set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
110 end if
111 else if (get second item of found_ooos as string) is chooseMyOwn then
112 -- set choice to found installation
113 -- set the choice to (get first paragraph of found_ooos)
114 set the choice to (get first item of found_ooos)
115 else
116 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)
117 if choice is false then
118 -- do nothing, the user cancelled the installation
119 return 2 --aborted by user
120 else if (choice as string) is chooseMyOwn then
121 -- yeah, one needs to use "choose file", otherwise
122 -- the user would not be able to select the .app
123 set the choice to POSIX path of (choose file with prompt chooseManual of type "com.apple.application-bundle" without showing package contents and invisibles)
124 end if
125 end if
127 -- now only check whether the path is really from [PRODUCTNAME]
129 do shell script "grep '<string>[PRODUCTNAME] [PRODUCTVERSION]' " & quoted form of (choice as string) & "/Contents/Info.plist"
130 on error
131 display dialog (choice as string) & appInvalid buttons {InstallLabel} default button 1 with icon 0
132 return 3 --wrong target-directory
133 end try
136 display dialog startInstall buttons {AbortLabel, InstallLabel} default button 2
138 if (button returned of result) is AbortLabel then
139 return 2
140 end if
143 -- touch extensions folder to have LO register bundled dictionaries
144 set tarCommand to "/usr/bin/tar -C " & quoted form of (choice as string) & " -xjf " & quoted form of sourcedir & "/tarball.tar.bz2 && touch " & quoted form of (choice as string) & "/Contents/Resources/extensions"
146 do shell script tarCommand
148 on error errMSG number errNUM
149 display dialog IdentifyQ buttons {IdentifyYES, IdentifyNO} with icon 2
150 if (button returned of result) is IdentifyYES then
152 do shell script tarCommand with administrator privileges
153 on error errMSG number errNUM
154 display dialog installFailed buttons {OKLabel} default button 1 with icon 0
155 -- -60005 username/password wrong
156 -- -128 aborted by user
157 -- 2 error from tar - tarball not found (easy to test)
158 return errNUM
159 end try
160 else
161 return 2 -- aborted by user
162 end if
163 end try
165 display dialog installComplete buttons {OKLabel} default button 1