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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
|
post_install() {
xdg-icon-resource forceupdate --theme hicolor &> /dev/null
#
# Copyright (c) New Cloud Technologies, Ltd., 2013-2021
#
# You can not use the contents of the file in any way without
# New Cloud Technologies, Ltd. written permission.
#
# To obtain such a permit, you should contact New Cloud Technologies, Ltd.
# at http://ncloudtech.com/contact.html
#
#
set -u
DISPLAY=''
echo "Running post install script..."
# This script may run not from the app's dist directory (this true in case of DEB package)
# The placeholder is overriden during the package configuration
SCRIPT_DIR="/usr/bin/myoffice-standard-home-edition"
source "${SCRIPT_DIR}/Common.2.3.0.sh"
# Initialize licensing - for linux create cache of HW ids, due to reading of them requires root access
createHardwareIdCache()
{
local boardSerial=$(cat /sys/devices/virtual/dmi/id/board_serial | tr -d '\n')
local productUuid=$(cat /sys/devices/virtual/dmi/id/product_uuid | tr -d '\n' | tr '[:lower:]' '[:upper:]')
local idFile="${RESOURCES_DIR}/"
mkdir -p "${RESOURCES_DIR}"
echo "${boardSerial} | ${productUuid}" > "${idFile}"
chmod go=r "${idFile}"
}
if [[ "" != "" ]]; then
createHardwareIdCache
fi
createAppEntryPoint()
{
sed -i "s|__INSTALL_PATH__|${SCRIPT_DIR}|g" "${SCRIPT_DIR}/$1.sh"
rm -f "/usr/bin/$1"
ln -s "${SCRIPT_DIR}/$1.sh" "/usr/bin/$1"
}
# Here we are using three different entry points instead one,
# because on some Linuxes file path is not passed correctly to entry script via double clicking on a file.
# Also it allows us to launch apps from terminal like myoffice-text, myoffice-spreadsheet, ...
for name in "${APPS[@]}"; do
createAppEntryPoint "${name}"
done
# Workaround for bug in xdg. See https://bugs.archlinux.org/task/33316 for details
mkdir -p /usr/share/desktop-directories/
registerAppMenu()
{
# Workaround for a bug in xdg. Names with spaces do not work properly
cp "${SCRIPT_DIR}/$1" "/tmp/$1"
xdg-desktop-menu install --mode system --novendor "/tmp/$1"
rm "/tmp/$1"
}
# register in desktop environment
for name in "${APPS[@]}"; do
registerAppMenu "${name}.desktop"
done
removeFromDefaults()
{
local defaults_file=$(readlink -f "$1")
if [ -w "${defaults_file}" ] ; then
local tmp_defaults_file=$(mktemp "/tmp/defaults-XXXXXX.list")
cp "${defaults_file}" "${tmp_defaults_file}"
for name in "${APPS[@]}"; do
sed -i "s/;*${name}.desktop//" "${tmp_defaults_file}"
done
sed -i "s/=;/=/" "${tmp_defaults_file}"
grep -v "=$" "${tmp_defaults_file}" > "${defaults_file}" 2> /dev/null
rm -f "${tmp_defaults_file}"
fi
}
IFW_MENU_DEST_DIR=$(probe_menu_installation_path)
# remove apps from defaults (fix for EDESK-465)
removeFromDefaults "${IFW_MENU_DEST_DIR}/defaults.list"
# Registering our own mime types
if [[ "${ENABLE_MIME_REGISTRATION}" != "0" ]]; then
xdg-mime install --mode system --novendor "${SCRIPT_DIR}/myoffice_mimes.xml" > /dev/null 2> /dev/null
fi
registerIcon()
{
# Workaround for an issue in the xdg-icon-resource utility
# For details see https://bugs.launchpad.net/ubuntu/+source/xdg-utils/+bug/1488787
cp "${SCRIPT_DIR}/icons/$3_$4.png" /tmp/icon-my-office.png
xdg-icon-resource install --noupdate --theme "$1" --mode system --novendor --context "$2" --size "$4" /tmp/icon-my-office.png "$5"
rm /tmp/icon-my-office.png
}
for size in "${IFW_ICON_SIZE[@]}"; do
for (( i=0; i<${#APP_ICON_SRC[*]}; i++ )); do
registerIcon hicolor apps "${APP_ICON_SRC[i]}" "${size}" "${APPS[i]}"
done
done
# Alt Linux has a bug related to some text-related document icons.
# Without this patch small icons are displayed correctly but large are displayed as unknown document.
if [[ "$IFW_LINUX_DISTRIBUTION" == "altlinux" ]]; then
IFW_STANDARD_MIMES_FILE=/usr/share/mime/packages/freedesktop.org.xml
if [ -f "${IFW_STANDARD_MIMES_FILE}" ]; then
sed -i 's|\(<mime-type type="text/plain">\)|\1\n <generic-icon name="text-plain"/>|g' ${IFW_STANDARD_MIMES_FILE}
sed -i 's|\(<mime-type type="text/csv">\)|\1\n <generic-icon name="text-csv"/>|g' ${IFW_STANDARD_MIMES_FILE}
sed -i 's|\(<mime-type type="text/tab-separated-values">\)|\1\n <generic-icon name="text-tab-separated-values"/>|g' ${IFW_STANDARD_MIMES_FILE}
fi
fi
if [[ "${INSTALL_SVG_ICONS}" == "0" ]]; then
IFW_ICON_THEME_NAME="hicolor"
for size in "${IFW_ICON_SIZE[@]}"; do
for (( i=0; i<${#MIME_ICON_SRC[*]}; i++ )); do
registerIcon "${IFW_ICON_THEME_NAME}" mimetypes "${MIME_ICON_SRC[i]}" "${size}" "${MIME_ICON_DEST[i]}"
done
done
fi
# TODO: register own mime types if Libre was not installed
if [[ ${UPDATE_MIME_DATABASE_WORKAROUND} -eq 0 ]]; then
update-mime-database /usr/share/mime
else
PKGSYSTEM_ENABLE_FSYNC=0 update-mime-database /usr/share/mime
fi
# The function returns a part of INI file as a bash script,
# which is later executed by 'eval'
prepareIniSection()
{
local s
s="${2/[/\\[}"
s="${s/]/\\]}"
s="${s//\//\\/}"
sed -n "/${s}/,/\[/p" "$1" | sed "/\[/d" | tr '[:lower:]' '[:upper:]'
}
mkdir -p "${BACKUP_DIR}/icons" || true
copyWithBackup()
{
local source=$1
local destination=$2
local theme=$3
# Do not overwrite existing backup
if [ ! -f "${BACKUP_DIR}/icons/${DEFAULT_ICON_PREFIX}/${theme}/${destination}" ]; then
# Check and backup
if [ -f "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" ]; then
local backupDestinationDir="${BACKUP_DIR}/icons/${DEFAULT_ICON_PREFIX}/${theme}/$(dirname ${destination})"
mkdir -p "${backupDestinationDir}"
if [ -L "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" ]; then
cp -L "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" "${backupDestinationDir}/" || true
else
mv "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" "${backupDestinationDir}/" || true
fi
md5sum "${source}" | cut -d ' ' -f 1 > "${BACKUP_DIR}/icons/${DEFAULT_ICON_PREFIX}/${theme}/${destination}.md5"
else
echo "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" >> "${MAINTENANCE_DIR}/icons.list"
fi
# Prefer symlink over copy
if [ -f "${DEFAULT_ICON_PREFIX}/hicolor/${destination}" ]; then
local targetHash=$(md5sum "${DEFAULT_ICON_PREFIX}/hicolor/${destination}" | cut -d ' ' -f 1)
local sourceHash=$(md5sum "${source}" | cut -d ' ' -f 1)
if [[ "${targetHash}" == "${sourceHash}" ]]; then
ln -sf "${DEFAULT_ICON_PREFIX}/hicolor/${destination}" "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" || true
else
cp --remove-destination -f "${source}" "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" || true
fi
else
cp --remove-destination -f "${source}" "${DEFAULT_ICON_PREFIX}/${theme}/${destination}" || true
fi
fi
}
# Nearly all Linux distributions override default icons for documents in some
# top level themes so 'hicolor' is almost never used
ICON_THEMES=$(ls -d "${DEFAULT_ICON_PREFIX}"/*/ | xargs -n 1 basename)
for IFW_ICON_THEME_NAME in ${ICON_THEMES}; do
INDEX_FILE="${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/index.theme"
if [ ! -e "${INDEX_FILE}" ]; then
continue
fi
for SECTION in $(grep -Po "^\[(\S+)\]$" "${INDEX_FILE}"); do
# The variables "SCALE", "CONTEXT", "TYPE", "SIZE" may be set in the section of "index.theme"
SCALE='1'
CONTEXT=''
TYPE=''
SIZE=''
# We execute prepared part of INI file, thus setting needed parameters
eval "$( prepareIniSection ${INDEX_FILE} ${SECTION} )" || continue
THEME_SECTION_PATH=$(echo "${SECTION}" | sed "s|\[||g" | sed "s|\]||g")
if [ ! -d "${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/${THEME_SECTION_PATH}/" ]; then
continue
fi
if [[ "${CONTEXT}" == "MIMETYPES" ]]; then
if [[ "${TYPE}" == "SCALABLE" ]]; then
for (( i=0; i<${#MIME_ICON_DEST[*]}; i++ )); do
ICON_FILE="${THEME_SECTION_PATH}/${MIME_ICON_DEST[i]}"
if [[ "${INSTALL_RASTER_ICONS_ONLY}" != "1" && "${INSTALL_SVG_ICONS}" == "1" ]]; then
copyWithBackup "${SCRIPT_DIR}/icons/${MIME_ICON_SRC[i]}.svg" "${ICON_FILE}.svg" "${IFW_ICON_THEME_NAME}"
fi
if [[ -e "${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/${ICON_FILE}.png" ]]; then
copyWithBackup "${SCRIPT_DIR}/icons/${MIME_ICON_SRC[i]}_256.png" "${ICON_FILE}.png" "${IFW_ICON_THEME_NAME}"
fi
done
else
for (( i=0; i<${#MIME_ICON_DEST[*]}; i++ )); do
ICON_FILE="${THEME_SECTION_PATH}/${MIME_ICON_DEST[i]}"
if [[ "${INSTALL_RASTER_ICONS_ONLY}" != "1" ]]; then
if [[ -e "${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/${ICON_FILE}.svg" ]]; then
copyWithBackup "${SCRIPT_DIR}/icons/${MIME_ICON_SRC[i]}.svg" "${ICON_FILE}.svg" "${IFW_ICON_THEME_NAME}"
fi
fi
if [[ "${IFW_ICON_THEME_NAME}" == "hicolor" ]]; then
# This theme is already installed
continue
fi
for size in "${IFW_ICON_SIZE[@]}"; do
if [[ "${size}" == $(echo "${SIZE}*${SCALE}" | bc) ]]; then
if [[ -e "${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/${ICON_FILE}.png" || "$IFW_LINUX_DISTRIBUTION" != "ubuntu" ]]; then
copyWithBackup "${SCRIPT_DIR}/icons/${MIME_ICON_SRC[i]}_${size}.png" "${ICON_FILE}.png" "${IFW_ICON_THEME_NAME}"
fi
fi
done
done
fi
elif [[ "${CONTEXT}" == "APPLICATIONS" ]]; then
if [[ "${TYPE}" == "SCALABLE" && "${IFW_ICON_THEME_NAME}" == "hicolor" && "${INSTALL_SVG_ICONS}" == "1" ]]; then
for (( i=0; i<${#APPS[*]}; i++ )); do
ICON_FILE="${THEME_SECTION_PATH}/${APPS[i]}"
copyWithBackup "${SCRIPT_DIR}/icons/${APP_ICON_SRC[i]}.svg" "${ICON_FILE}.svg" "${IFW_ICON_THEME_NAME}"
done
fi
fi
done
xdg-icon-resource forceupdate --theme "${IFW_ICON_THEME_NAME}" --mode system || true
gtk-update-icon-cache -ft "${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}" > /dev/null 2> /dev/null || true
done
# Fonts
IFW_FONTS_DEST_DIR="/usr/share/fonts/myoffice/"
mkdir -p "${IFW_FONTS_DEST_DIR}"
cp "${SCRIPT_DIR}/Fonts"/* ${IFW_FONTS_DEST_DIR}
fc-cache
# We need to turn on antialiasing in Astra Linux to make fonts rendering better in our app.
# It has been agreed with the developers of Astra. These changes are restored during the uninstallation.
backupFontConfig()
{
local fontConfigFolder="/etc/fonts/conf.avail"
if [ -f "${fontConfigFolder}/${1}" ]; then
mv "${fontConfigFolder}/${1}" "${fontConfigFolder}/${1}.backup"
fi
}
if [[ "$IFW_LINUX_DISTRIBUTION" == "astra" ]]; then
backupFontConfig "19-fly-no-antialiasing.conf" # Used in version 1.4
backupFontConfig "29-fly-rendering.conf" # Used in version 1.5
fi
# A workaround for xdg-open: FTP hyperlinks suport is missing in many distributions
addFtpToMime()
{
local mimeFile=${1}
local tmpFile=$(mktemp)
if [[ -e ${mimeFile} ]]; then
local ftpMimeApp=$(cat "${mimeFile}" | grep ftp=)
if [[ "${ftpMimeApp}" == '' ]]; then
FTP_LINE=$(cat "${mimeFile}" | grep http= | sed s/http/ftp/)
if [[ "${FTP_LINE}" != '' ]]; then
awk -v var="${FTP_LINE}" '/http=/{print var}1' "${mimeFile}" > "${tmpFile}"
cat "${tmpFile}" > "${mimeFile}"
rm -f "${tmpFile}"
fi
fi
fi
}
if [[ "${ENABLE_MIME_REGISTRATION}" != "0" ]]; then
addFtpToMime /usr/share/applications/mimeapps.list
addFtpToMime /usr/share/applications/mimeinfo.cache
fi
# Apps icons registered to hicolor theme, so need to refresh it
xdg-icon-resource forceupdate --theme hicolor --mode system
gtk-update-icon-cache -ft "${DEFAULT_ICON_PREFIX}/hicolor" > /dev/null 2> /dev/null || true
echo "Done."
update-desktop-database -q
}
post_upgrade() {
post_install
}
pre_remove() {
#
# Copyright (c) New Cloud Technologies, Ltd., 2013-2021
#
# You can not use the contents of the file in any way without
# New Cloud Technologies, Ltd. written permission.
#
# To obtain such a permit, you should contact New Cloud Technologies, Ltd.
# at http://ncloudtech.com/contact.html
#
#
set -u
DISPLAY=''
# This script may run not from the app's dist directory (this true in case of DEB package)
# The placeholder is overriden during the package configuration
SCRIPT_DIR="/usr/bin/myoffice-standard-home-edition"
CONFIG_DIR="New Cloud Technologies Ltd."
source "${SCRIPT_DIR}/Common.2.3.0.sh"
if [[ "${TAG}" == "upgrade" || "${TAG}" == "1" ]]; then
echo "Skipping uninstall step..."
exit 0
fi
IFW_MENU_DEST_DIR=$(probe_menu_installation_path)
# Unregister in desktop environment
for name in "${APPS[@]}"; do
xdg-desktop-menu uninstall --mode system --novendor "${SCRIPT_DIR}/${name}.desktop"
done
deleteAppEntryPoint()
{
if [ -h "/usr/bin/$1" ]; then
rm -f "/usr/bin/$1"
fi
}
for name in "${APPS[@]}"; do
deleteAppEntryPoint "${name}"
done
# Unistalling icons
for size in "${IFW_ICON_SIZE[@]}"; do
for name in "${APPS[@]}"; do
xdg-icon-resource uninstall --theme hicolor --mode system --size "${size}" --context apps --size "${size}" "${name}"
done
done
uninstallIconsForTheme()
{
for size in "${IFW_ICON_SIZE[@]}"; do
for name in "${MIME_ICON_DEST[@]}"; do
xdg-icon-resource uninstall --theme "${1}" --mode system --context mimetypes --size "${size}" "${name}"
done
done
}
if [[ "${INSTALL_SVG_ICONS}" == "0" ]]; then
uninstallIconsForTheme hicolor
fi
if [[ "${INSTALL_RASTER_ICONS_ONLY}" == "1" ]]; then
for IFW_ICON_THEME_NAME in ${ICON_THEMES}; do
INDEX_FILE="${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/index.theme"
if [ ! -e "${INDEX_FILE}" ]; then
continue
fi
if [[ "${IFW_ICON_THEME_NAME}" == "hicolor" ]]; then
# This theme is already uninstalled
continue
fi
uninstallIconsForTheme "${IFW_ICON_THEME_NAME}"
done
fi
restoreFileFromBackup()
{
local target=$1
if [ -f "${target}" ]; then
local backupHash=$(cat "${BACKUP_DIR}/icons/${target}.md5")
local targetHash=$(md5sum "${target}" | cut -d ' ' -f 1)
if [[ "${backupHash}" == "${targetHash}" ]]; then
cp --remove-destination -f "${BACKUP_DIR}/icons/${target}" "${target}" || true
fi
elif [[ -L "${target}" && ! -e "${target}" ]]; then
cp --remove-destination -f "${BACKUP_DIR}/icons/${target}" "${target}" || true
fi
}
findAndRestore()
{
if [ -f "$1" ]; then
if [[ "$1" == *.png || "$1" == *.svg ]]; then
restoreFileFromBackup "${1#'.'}"
fi
elif [ -d "$1" ]; then
for f in "$1"/*; do
findAndRestore "${f}"
done
fi
}
# Restoring overwritten icons
if [ -d "${BACKUP_DIR}/icons" ]; then
cd "${BACKUP_DIR}/icons/"
findAndRestore .
cd "${MAINTENANCE_DIR}"
rm -rf "${BACKUP_DIR}/icons"
fi
if [ -f "${MAINTENANCE_DIR}/icons.list" ]; then
for f in $(cat "${MAINTENANCE_DIR}/icons.list"); do
rm -f "${f}" || true
done
fi
# Restoring font config changes
restoreFontConfig()
{
local fontConfigFolder="/etc/fonts/conf.avail"
if [ -f "${fontConfigFolder}/${1}.backup" ]; then
mv "${fontConfigFolder}/${1}.backup" "${fontConfigFolder}/${1}"
fi
}
if [[ "$IFW_LINUX_DISTRIBUTION" == "astra" ]]; then
restoreFontConfig "19-fly-no-antialiasing.conf" # Used in version 1.4
restoreFontConfig "29-fly-rendering.conf" # Used in version 1.5
fi
updateCacheForTheme()
{
xdg-icon-resource forceupdate --theme "${1}" --mode system || true
gtk-update-icon-cache -ft "${DEFAULT_ICON_PREFIX}/${1}" > /dev/null 2> /dev/null || true
}
for IFW_ICON_THEME_NAME in ${ICON_THEMES}; do
INDEX_FILE="${DEFAULT_ICON_PREFIX}/${IFW_ICON_THEME_NAME}/index.theme"
if [ ! -e "${INDEX_FILE}" ]; then
continue
fi
updateCacheForTheme "${IFW_ICON_THEME_NAME}"
done
cd "${SCRIPT_DIR}"
rm -rf "${MAINTENANCE_DIR}" || true
echo "Done"
}
post_remove() {
xdg-icon-resource forceupdate --theme hicolor &> /dev/null
update-desktop-database -q
}
|