forked from antoniofaccioli/libreoffice-appimage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_libreoffice_appimage
executable file
·538 lines (493 loc) · 18 KB
/
make_libreoffice_appimage
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
#!/bin/bash
# Generate LibreOffice AppImage
# by Antonio Faccioli
# Added 'Usage' message and basic 'check' functions by Kurt Pfeifle
# Based on script by Simon Peter
# Released under the Mozilla Public License Version 2.0
# http://www.libreoffice.org/about-us/licenses/
set -x
argv0="${0}"
argv1="${1}"
argv2="${2}"
argv3="${3}"
argv4="${4}"
argv5="${5}"
argv6="${6}"
argv7="${7}"
everylang="af|am|ar|as|ast|be|bg|bn-IN|bn|bo|br|brx|bs|ca-valencia|ca|cs|cy|da|de|dgo|dz|el|en-GB|en-ZA|eo|es|et|eu|fa|fi|fr|ga|gd|gl|gu|gug|he|hi|hr|hsb|hu|id|is|it|ja|ka|kk|km|kmr|kn|ko|kok|ks|lb|lo|lt|lv|mai|mk|ml|mn|mni|mr|my|nb|ne|nl|nn|nr|nso|oc|om|or|pa-IN|pl|pt-BR|pt|qtz|ro|ru|rw|sa-IN|sat|sd|si|sid|sk|sl|sq|sr-Latn|sr|ss|st|sv|sw-TZ|ta|te|tg|th|tn|tr|ts|tt|ug|uk|uz|ve|vec|vi|xh|zh-CN|zh-TW|zu"
# Describe usage:
usage() {
echo ""
echo " Build an \"single-file\" AppImage executable for any (arbitrary) version of LibreOffice from The Document Foundation's official binary Debian package."
echo ""
echo " Usage: ${argv0} <version> <arch> <lang> <help-yesno> <zsync-yesno> <sign-yesno> <portable-yesno>"
echo ""
echo " where:"
echo " <version>: 'fresh': build from 'fresh' release channel (i.e. the latest official release)"
echo " 'still': build from 'still' release channel (i.e. the previous official release)"
echo " 'daily': build from 'daily' release channel (i.e. the current hot-of-the-stove development branch)"
echo " 'n.m.o.p': for example use '5.4.3.2'"
echo ""
echo " <arch>: 'x86': package 32-bit binaries"
echo " 'x86-64': package 64-bit binaries"
echo ""
echo " <lang>: 'standard': includes en-GB, it, ar, zh-CN, zh-TW, fr, de, ja, ko, pt, pt-BR, es, ru language-packs"
echo " 'full': includes all available language-packs (for some releases more than 113 different ones!)"
echo " 'N': no extra language-pack (LibreOffice comes with default 'en-US')"
echo " <custom>: includes one or more comma separated language-packs (for example 'de' or 'it,es')"
echo ""
echo " <help-yesno>: 'Y' or 'N' (Yes/No to include online help for each language pack installed for the previous '<lang>' parameter)"
echo " <custom>: includes help for one or more comma separated languages (for example 'de' or 'it,es')"
echo ""
echo " <zsync-yesno>: 'Y' or 'N' (Yes/No to include capability for updating the AppImage with the help of 'AppImageUpdate')"
echo ""
echo " <sign-yesno>: 'Y' or 'N' (Yes/No to include a GPG signature)"
echo ""
echo " <portable-yesno>: 'Y' or 'N' (Yes/No to include portable function)"
echo ""
echo " Example: \"${argv0} still x86-64 it N N N N\""
echo " Build LO AppImage package with Italian language-pack, without offline help, not auto-updateable, without signing the package, ."
echo ""
echo " Example: \"${argv0} daily x86-64 de Y Y N\""
echo " Build LO AppImage package (development version) with German language-pack, with (German) offline help, updateable via zsync, without signing the package."
echo ""
echo " Example: \"${argv0} 3.5.7.2 x86-64 es Y N N\""
echo " Build LO v3.5.7.2 AppImage package with Spanish language-pack, with (Spanish) offline help, not auto-updateable, without signing the package."
echo ""
}
check() { # This is not a complete, but only a limited sanity check of the inputs
case $argv1 in
fresh|still|daily|3.*|4.*|5.*|6.*)
# Do nothing, accepted!
echo -e "\nBuilding LibreOffice AppImage from \"${argv1}\" channel or release:"
;;
*)
echo -e "\n ==> Argument no.1 must be either 'fresh', 'still', 'daily' or a specific LibreOffice version number released by The Document Foundation. <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
;;
esac
case $argv2 in
x86|x86-64)
# Do nothing, accepted!
echo " -- for architecture \"${argv2}\";"
;;
*)
echo "==> Wrong or unsupported architecture ${argv2} in argument no.2 -- must be 'x86' or 'x86-64'. <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
;;
esac
case $argv3 in
standard|full)
echo " -- with localization language(es) \"${argv3}\";"
;;
N)
echo " -- without any extra localization language;"
;;
"$everylang")
echo " -- with localization language \"${argv3}\";"
;;
*)
if [ -z "$argv3" ]
then
echo "==> Wrong or unsupported language request '${argv3}' in argument no.3. <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
fi
for lang in ${argv3//,/ }
do
for available in ${everylang//|/ }
do
[ "$lang" = "$available" ] && continue 2
done
echo "==> Wrong or unsupported language request '${lang}' in argument no.3. <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
done
echo " -- with localization language(s) \"${argv3}\";"
;;
esac
case $argv4 in
Y|N)
# Do nothing, accepted!
echo " -- include offline help = \"${argv4}\";"
;;
*)
if [ -z "$argv4" ]
then
echo "==> Wrong or unsupported help language request '${argv4}' in argument no.4. <=="
echo "==> Must be either 'Y', 'N' or a comma separated list of languages to include <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
fi
for helplang in ${argv4//,/ }
do
for available in ${everylang//|/ }
do
[ "$helplang" = "$available" ] && continue 2
done
echo "==> Wrong or unsupported help language request '${helplang}' in argument no.4. <=="
echo "==> Must be either 'Y', 'N' or a comma separated list of languages to include <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
done
echo " -- include offline help language(s) \"${argv4}\";"
;;
esac
case $argv5 in
Y|N)
# Do nothing, accepted!
echo " -- include AppImage zsync updatability feature = \"${argv5}\";"
;;
*)
echo "==> Wrong argument ${argv5} at position no.5! (Must be either 'Y' or 'N' to include update functions or not... <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
;;
esac
case $argv6 in
Y|N)
# Do nothing, accepted!
echo " -- with signature for package = \"${argv6}\";"
;;
*)
echo "==> Wrong argument ${argv6} at position no. 6! (Must be either 'Y' or 'N' to include a signature or not... <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
;;
esac
case $argv7 in
Y|N)
# Do nothing, accepted!
echo " -- with portable for package = \"${argv7}\";"
;;
*)
echo "==> Wrong argument ${argv7} at position no. 7! (Must be either 'Y' or 'N' to include portable function or not... <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
;;
esac
}
# Check number of arguments:
case $# in
7)
check
;;
0|1|2|3|4|5|6|*)
echo "==> Wrong number of arguments! (Used: ${#}) <=="
echo "For correct usage of ${argv0} please see below:"
echo ""
usage
exit 0
;;
esac
declare -A master_builds
function todate() {
# change the date to Unix timestamp
local datestring="TZ=\"UTC\" ${1}"
date -d "$datestring" +%s
}
function newestmaster() {
# Compare the dates as timestamps to find the newest one
# Access associative array with a name reference
# Key is relative path to file, value is date
local -n ar=$1
local max=0
local filepath=""
for i in "${!ar[@]}" ; do
timestamp=$(todate "${ar[$i]}")
(("$timestamp" > max)) && max="$timestamp" && filepath="$i"
done
echo "$filepath"
}
function filtermasters() {
# Read a page listing the actually available builds
local current_masters=$(wget -q "https://dev-builds.libreoffice.org/daily/master/current.html" -O -)
# Put all the Linux build links into an array, but filter out any debug or rpm archives
mapfile -t master_links < <( grep -oP -e '<a href="\.\/Linux.*</a>' <<< "$current_masters" | grep -vE 'dbg|rpm\.tar\.gz' )
# Add relative file paths and dates into an associative array
for link in "${master_links[@]}"; do
key=$(grep -oP -e '(?<=<a href="\.\/)Linux.*(?=">)' <<< "$link")
value=$(grep -oP -e "(?<=<a href=\"\.\/${key}\">).*(?=<\/a>)" <<< "$link")
master_builds[$key]=$value
done
newestmaster master_builds
}
pathVersion=$1
arch="${2:-x86-64}"
language="${3:-N}"
optHelp="${4:-N}"
optSync="${5:-N}"
optSignature="${6:-N}"
optPortable="${7:-Y}"
linkZsync=""
gpgPass=""
if [[ $language == *"standard"* ]] ; then
languages=(en-GB it ar zh-CN zh-TW fr de ja ko pt pt-BR es ru)
elif [[ $language == *"full"* ]] ; then
languages=(${everylang//|/ })
elif [[ $language != "N" ]] ; then
languages=(${argv3//,/ })
# avoid long language lists in VERSION; and commas like in "fr,de"
# cause "LibreOffice-$VERSION.AppImage --appimage-mount" to fail
[ "${#languages[@]}" -le 4 ] && language="${language//,/_}" || language="custom"
else
languages=()
fi
if [[ $optHelp == *"Y"* ]] ; then
helplanguages=("${languages[@]}")
elif [[ $optHelp != "N" ]] ; then
helplanguages=(${argv4//,/ })
else
helplanguages=()
fi
if [[ $arch == *"x86-64"* ]] ; then
pathArch="x86_64"
appimageArch="x86_64"
elif [[ $arch == "x86" ]] ; then
pathArch="x86"
appimageArch="i686"
fi
if [[ $pathVersion == *"daily"* ]] ; then
APP=LibreOfficeDev
else
APP=LibreOffice
fi
case "$pathVersion" in
"3.3.0.4")
libreVersion="3.3.0"
;;
"3.3.1.2")
libreVersion="3.3.1"
;;
"3.3.2.2")
libreVersion="3.3.2"
;;
"3.3.3.1")
libreVersion="3.3.3"
;;
"3.3.4.1")
libreVersion="3.3.4"
;;
"3.4.0.1")
libreVersion="3.4.0rc1"
;;
"3.4.1.3")
libreVersion="3.4.1"
;;
"3.4.2.3")
libreVersion="3.4.2"
;;
"3.4.3.2")
libreVersion="3.4.3"
;;
"3.4.4.1")
libreVersion="3.4.4rc1"
;;
"3.4.5.2")
libreVersion="3.4.5rc2"
;;
"3.4.6.2")
libreVersion="3.4.6rc2"
;;
"3.5.0.3")
libreVersion="3.5.0rc3"
;;
"3.5.1.2")
libreVersion="3.5.1rc2"
;;
"3.5.2.2")
libreVersion="3.5.2rc2"
;;
"3.5.3.2")
libreVersion="3.5.3rc2"
;;
"3.5.4.2")
libreVersion="3.5.4rc2"
;;
"3.5.5.3")
libreVersion="3.5.5rc3"
;;
"3.5.6.2")
libreVersion="3.5.6rc2"
;;
"3.5.7.2")
libreVersion="3.5.7rc2"
;;
*)
libreVersion=$pathVersion
;;
esac
set +e
if [[ $pathVersion == *"fresh"* ]] ; then
nrVersion=$(curl "https://www.libreoffice.org/download/download" | grep -o -e "/stable/.*/" | cut -d "/" -f 3 | head -n 1)
path="https://download.documentfoundation.org/libreoffice/stable/${nrVersion}/deb/${pathArch}/"
package="LibreOffice_${nrVersion}_Linux_${arch}_deb.tar.gz"
elif [[ $pathVersion == *"still"* ]] ; then
nrVersion=$(curl "https://www.libreoffice.org/download/download" | grep -o -e "/stable/.*/" | cut -d "/" -f 3 | head -n 3 | tail -n 1)
path="https://download.documentfoundation.org/libreoffice/stable/${nrVersion}/deb/${pathArch}/"
package="LibreOffice_${nrVersion}_Linux_${arch}_deb.tar.gz"
elif [[ $pathVersion == *"daily"* ]] ; then
path="https://dev-builds.libreoffice.org/daily/master/"
package=$(filtermasters)
tmpVersion1="${package%_Linux_x86-64_deb.tar.gz}"
tmpVersion1="${tmpVersion1##*LibreOfficeDev_}"
tmpVersion2="${package%_[[:digit:]][[:digit:]].*}"
tmpVersion2="${tmpVersion2##*master~}"
nrVersion=$tmpVersion1"_"$tmpVersion2
else
if [[ $pathVersion == "3."* ]] ; then
nrVersion=$libreVersion
path="https://downloadarchive.documentfoundation.org/libreoffice/old/$pathVersion/deb/${pathArch}/"
package="LibO_${nrVersion}_Linux_${arch}_install-deb_en-US.tar.gz"
else
nrVersion=$libreVersion
path="https://downloadarchive.documentfoundation.org/libreoffice/old/${nrVersion}/deb/${pathArch}/"
package="LibreOffice_${nrVersion}_Linux_${arch}_deb.tar.gz"
fi
fi
LibODownloadLink=$path$package
if [[ $optHelp != "N" ]] ; then
if [[ $language != "N" ]] ; then
VERSION="${nrVersion}.$language.help"
else
VERSION="${nrVersion}.help"
fi
else
if [[ $language != "N" ]] ; then
VERSION="${nrVersion}.$language"
else
VERSION=$nrVersion
fi
fi
mkdir -p ./$APP/$APP.AppDir
cd ./$APP || exit
wget -c "$LibODownloadLink"
if [[ $language != "N" ]] ; then
if [[ $pathVersion == *"daily"* ]] ; then
langStart="${package%.tar.gz}_langpack_"
else
langStart="LibreOffice_${nrVersion}_Linux_${arch}_deb_langpack_"
fi
if [[ $language == *"standard"* || $language == *"full"* ]] ; then
for element in ${languages[*]}; do
langPackage="$langStart$element.tar.gz"
wget -c "$path$langPackage"
done
else
if [[ $pathVersion == "3."* ]] ; then
for element in ${languages[*]}; do
langPackage="LibO_${nrVersion}_Linux_${arch}_langpack-deb_${element}.tar.gz"
wget -c "$path$langPackage"
done
else
for element in ${languages[*]}; do
langPackage="$langStart${element}.tar.gz"
wget -c "$path$langPackage"
done
fi
fi
fi
if [[ $optHelp != "N" ]] ; then
if [[ $pathVersion == *"daily"* ]] ; then
helpStart="${package%.tar.gz}_helppack_"
else
helpStart="LibreOffice_${nrVersion}_Linux_${arch}_deb_helppack_"
fi
if [[ $language == *"standard"* || $language == *"full"* ]] ; then
for element in ${helplanguages[*]}; do
helpPackage="$helpStart$element.tar.gz"
wget -c "$path$helpPackage"
done
else
if [[ $pathVersion == "3."* ]] ; then
if [[ "${#helplanguages[@]}" != "0" ]] ; then
for element in ${helplanguages[*]}; do
helpPackage="LibO_${nrVersion}_Linux_${arch}_helppack-deb_${element}.tar.gz"
wget -c "$path$helpPackage"
done
else
helpPackage="LibO_${nrVersion}_Linux_${arch}_helppack-deb_en-US.tar.gz"
wget -c "$path$helpPackage"
fi
else
if [[ "${#helplanguages[@]}" != "0" ]] ; then
for element in ${helplanguages[*]}; do
helpPackage="$helpStart${element}.tar.gz"
wget -c "$path$helpPackage"
done
else
helpPackage="${helpStart}en-US.tar.gz"
wget -c "$path$helpPackage"
fi
fi
fi
fi
for i in *.tar.gz; do tar xfvz "$i"; done
cd $APP.AppDir/ || exit
find ../ -name "*.deb" -exec dpkg -x \{\} . \;
if [[ $optPortable != "N" ]] ; then
find . -type f -iname "bootstraprc" -exec sed -i "s|^UserInstallation=.*|UserInstallation=\$SYSUSERCONFIG/libreoffice/$nrVersion|g" {} +
fi
find . -name startcenter.desktop -exec cp \{\} . \;
if [[ $pathVersion == *"daily"* ]] ; then
sed -i -e 's|Name=.*|Name=LibreOfficeDev|g' startcenter.desktop
else
sed -i -e 's|Name=.*|Name=LibreOffice|g' startcenter.desktop
fi
find . -name "*startcenter.png" -path "*hicolor*48x48*" -exec cp \{\} . \;
BINARY=$(cat *.desktop | grep "Exec=" | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 1)
mkdir -p usr/bin/
cd usr/bin/ || exit
rm ./"$BINARY"
find ../../opt -name soffice -path "*program*" -exec ln -s \{\} ./"$BINARY" \;
cd ../../
wget -c https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-$appimageArch -O AppRun
chmod a+x AppRun
cd ..
URL="https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-${appimageArch}.AppImage"
wget -c "$URL" -O appimagetool
chmod a+x ./appimagetool
set +x
if [[ $optSync == "N" ]] ; then
VERSION=$VERSION ./appimagetool -v ./$APP.AppDir/
else
if [[ $language == "N" ]] ; then
if [[ $optHelp != "N" ]] ; then
VERSION="$pathVersion"."help" ./appimagetool -u "zsync|"$linkZsync$APP"-"$pathVersion".help.AppImage.zsync" -v ./$APP.AppDir/
else
VERSION="$pathVersion" ./appimagetool -u "zsync|"$linkZsync$APP"-"$pathVersion".AppImage.zsync" -v ./$APP.AppDir/
fi
else
if [[ $optHelp != "N" ]] ; then
VERSION="$pathVersion"."$language"."help" ./appimagetool -u "zsync|"$linkZsync$APP"-"$pathVersion"."$language".help.AppImage.zsync" -v ./$APP.AppDir/
else
VERSION="$pathVersion"."$language" ./appimagetool -u "zsync|"$linkZsync$APP"-"$pathVersion"."$language".AppImage.zsync" -v ./$APP.AppDir/
fi
fi
fi
set -x
if [[ $optSignature == "Y" ]] ; then
for i in $(find . -name "*.AppImage*" -print;); do gpg2 -b --batch --armor --passphrase "$gpgPass" "${i}"; done || true
fi
mkdir -p ../out/ || true
mv *.AppImage* ../out/