1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
|
(*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
*************************************************************************)
-- This is the PostInstall -script for .pkg installation
--
-- Currently this script does the following things:
-- 1) Uses fondu to extract and convert .dfont -fonts from Mac OS X system to .ttf -fonts for OpenOffice.org
(*==== (global variables as get-functions) ====*)
on getOOInstallPath()
return (((path to me) as string) & "Contents:")
end getOOInstallPath
on getOOResourcesPath()
return (((path to me) as string) & "Contents:Resources:")
end getOOResourcesPath
on getOOProgramPath()
return (getOOInstallPath() & "MacOS:")
end getOOProgramPath
-- OSXSystemFontPathList : {"/System/Library/Fonts/", "/Library/Fonts/"}
-- OSXUserFontPathList : {"~/Library/Fonts/"}
on getOSXSystemFontPathList()
return {(path to fonts folder from system domain) as string,
(path to fonts folder from local domain) as string}
end getOSXSystemFontPathList
on getOSXUserFontPathList()
return {(path to fonts folder from user domain) as string}
end getOSXUserFontPathList
on getOOSystemFontPath()
return (getOOInstallPath() & "share:fonts:truetype:")
end getOOSystemFontPath
on getOOUserSettingsPath()
return (((path to home folder) as string) & "Library:Application Support:OpenOffice.org:%USERDIRPRODUCTVERSION:")
end getOOUserSettingsPath
on getOOUserFontPath()
return (getOOUserSettingsPath() & "user:fonts:")
end getOOUserFontPath
on getOOCookieSystemFondu()
-- nosystemfondu : file does exist if user does not want to use fondu for system fonts
return "no_system_fondu"
end getOOCookieSystemFondu
on getOOCookieSystemFonduDone()
-- systemfondudone : file does exist if native fonts already extracted from system fonts
return "system_fondu_done"
end getOOCookieSystemFonduDone
on getOOCookieUserFondu()
-- nouserfondu : file does exist if user does not want to use fondu for user fonts
return "no_user_fondu"
end getOOCookieUserFondu
on getOOCookieUserFonduDone()
-- userfondudone : file does exist if native fonts already extracted from user fonts
return "user_fondu_done"
end getOOCookieUserFonduDone
--
-- the default handler: run
--
on run
-- Check for that OOo can be found
if (not isRealPath(getOOProgramPath())) then
logEvent("(scripts/PostInstall) ERROR: could not find OOo installation from " & POSIX path of getOOProgramPath())
return
end if
-- checks are ok, now we can start doing the real stuff
firstLaunch()
runSystemFondu()
runUserFondu()
return
end run
-------------------------------------------------------------
on runSystemFondu()
-- check if user does not want font conversion
if (isRealPath(getOOSystemFontPath() & getOOCookieSystemFondu())) then
return
end if
-- check if font conversion was already run
if (isRealPath(getOOSystemFontPath() & getOOCookieSystemFonduDone())) then
return
end if
logEvent("(scripts/PostInstall) Extracting system fonts...")
-- else try to create footprint
if (setCookie(getOOSystemFontPath(), getOOCookieSystemFonduDone())) then
-- call fondu for each font (i.e. without wildcard), so if it crashes only one font is missing
fonduConvertFonts(getOOSystemFontPath(), getOSXSystemFontPathList())
end if
logEvent("(scripts/PostInstall) Extracting system fonts completed.")
end runSystemFondu
on runUserFondu()
-- check if user does not want font conversion
if (isRealPath(getOOUserFontPath() & getOOCookieUserFondu())) then
return
end if
-- check if font conversion was already run
if (isRealPath(getOOUserFontPath() & getOOCookieUserFonduDone())) then
return
end if
logEvent("(scripts/PostInstall) Extracting user fonts...")
-- try to create footprint
if (setCookie(getOOUserFontPath(), getOOCookieUserFonduDone())) then
-- call fondu for each font (i.e. without wildcard), so if it crashes only one font is missing
fonduConvertFonts(getOOUserFontPath(), getOSXUserFontPathList())
end if
logEvent("(scripts/PostInstall) Extracting user fonts completed.")
end runUserFondu
on firstLaunch()
-- continue only if OOSysFontdir exists
if (not isRealPath(getOOSystemFontPath())) then
logEvent("(scripts/PostInstall) ERROR: could not find System font folder from " & POSIX path of getOOSystemFontPath())
return
end if
if (setCookie(getOOSystemFontPath(), getOOCookieSystemFondu() & ".in_progress")) then
-- Has user already decided that he does not want to extract system fonts ?
if (not isRealPath(getOOSystemFontPath() & getOOCookieSystemFondu())) then
-- Are system fonts already extracted ?
if (not isRealPath(getOOSystemFontPath() & getOOCookieSystemFonduDone())) then
-- ask if the user wants to use fondu to extract system fonts
set yesKey to getMessage("YES_KEY")
set noKey to getMessage("NO_KEY")
display dialog getMessage("OOO_EXTRACT_NATIVE_SYSFONTS") buttons {noKey, yesKey} default button yesKey
set theResult to the button returned of the result
if theResult is noKey then
-- not use fondu for system fonts extraction !
setCookie(getOOSystemFontPath(), getOOCookieSystemFondu())
logEvent("(scripts/PostInstall) Setting: no system fonts")
end if
end if
end if
end if
-- continue only if OOUserFontdir exists
if (not isRealPath(getOOUserFontPath())) then
logEvent("(scripts/PostInstall) ERROR: could not find User font folder from " & POSIX path of getOOUserFontPath())
return
end if
-- Has user already decided that he does not want to extract user fonts ?
if (not isRealPath(getOOUserFontPath() & getOOCookieUserFondu())) then
-- Are system fonts already extracted ?
if (not isRealPath(getOOUserFontPath() & getOOCookieUserFonduDone())) then
-- ask if the user wants to use fondu to extract user fonts
set yesKey to getMessage("YES_KEY")
set noKey to getMessage("NO_KEY")
display dialog getMessage("OOO_EXTRACT_NATIVE_USERFONTS") buttons {noKey, yesKey} default button yesKey
set theResult to the button returned of the result
if theResult is noKey then
-- not use fondu for user fonts extraction !
setCookie(getOOUserFontPath(), getOOCookieUserFondu())
logEvent("(scripts/PostInstall) Setting: no user fonts")
end if
end if
end if
end firstLaunch
on fonduConvertFonts(targetPath, sourcePathList)
-- define the location of fondu
set fondu to quoted form of (POSIX path of getOOProgramPath() & "fondu")
-- first go to the target directory
set fonduCmd to "cd " & (quoted form of POSIX path of targetPath) & "; "
repeat with q from 1 to number of items in sourcePathList
set aPath to POSIX path of (item q of sourcePathList)
set fonduCmd to fonduCmd & "for i in " & aPath & "*; do " & fondu & " -force \"$i\" >> /dev/null 2>&1; done; "
end repeat
try
-- ignore errors
-- with admin privileges does not work well on panther
do shell script "sh -c " & quoted form of fonduCmd
end try
logEvent("fonduCMD: " & fonduCmd)
end fonduConvertFonts
(* ===== (Helper functions) ======= *)
-- set a cookiefile. The content is empty.
on setCookie(aPath, cookieFile)
try
if (isRealPath(aPath)) then
set newFile to (aPath & cookieFile)
open for access file newFile
close access file newFile
return true
else
return false
end if
on error
return false
end try
end setCookie
-- get a localized string
on getMessage(aKey)
try
if (aKey is equal to "YES_KEY") then
return "Yes"
end if
if (aKey is equal to "NO_KEY") then
return "No"
end if
if (aKey is equal to "OOO_EXTRACT_NATIVE_SYSFONTS") then
return "Do you want OpenOffice.org to use the Apple system fonts?"
end if
if (aKey is equal to "OOO_EXTRACT_NATIVE_USERFONTS") then
return "Do you want OpenOffice.org to use the fonts you have installed on this system?"
end if
end try
end getMessage
-- function for checking if a path exists
on isRealPath(aPath)
try
alias aPath
return true
on error
-- error number -43 from aPath
-- display dialog "NotRP -- " & aPath
return false
end try
end isRealPath
-- function for logging script messages
on logEvent(themessage)
set theLine to (do shell script
"date +'%Y-%m-%d %H:%M:%S'" as string)
& " " & themessage
do shell script "echo " & quoted form of theLine &
" >> ~/Library/Logs/OpenOffice%USERDIRPRODUCTVERSION.log"
end logEvent
|