-
Notifications
You must be signed in to change notification settings - Fork 0
/
libre-office-portable-downloader.bash
executable file
·111 lines (100 loc) · 4.11 KB
/
libre-office-portable-downloader.bash
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
#!/bin/bash
# This script downloads the latest version of LibreOffice in the folder
# where the script is located and extracts it to make a portable version.
# Ce script télécharge la dernière version de LibreOffice dans le dossier
# où le script est situé et l'extrait pour en faire une version portable.
#
# Copyright 2013 Victor Grousset <[email protected]>
# Copyright 2013 Alain Drillon <[email protected]>
# Copyright 2013 Julien Papasian
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
function main() {
setCurrentDirectoryAndDisplayScriptVersion
version=$(getLatestLibreOfficeVersion)
url=$(getLinkLatestLibreOfficeDEB $version)
wget "$url" --no-check-certificate -O "libreOffice"$version".tar.gz"
#nocheck to avoid some https errors(for this, full https security
#is not essential but you can remove the option is you want)
echo "Extracting from .tar.gz"
tar -xzf "libreOffice"$version".tar.gz" #&> /dev/null
extractDEB
echo "Extraction complete!"
cleaning
createLauncher
echo "Version: "$scriptVersion", by Victor Grousset ([email protected]) under GPLv3 Licence"
echo "With the help of Alain Drillon and Julien Papasian"
echo -e "To launch LibreOffice, go to the libreOffice"$version" directory and you will find \nthe launcher."
echo "Press the enter key to continue"
read #waits until enter pressed
}
function setCurrentDirectoryAndDisplayScriptVersion() {
scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$scriptDir" #Go to the script directory
scriptVersion="1.1.2"
echo "Script version: "$scriptVersion
}
function getLatestLibreOfficeVersion() {
#we download a page on the document foundation server were we can
#always find the latest version number of LibreOffice
wget "https://download.documentfoundation.org/libreoffice/stable/" --no-check-certificate -O ftpLibreOffice.temp &> /dev/null
#nocheck to avoid some https errors
#now we isolate the line containing the version number and extract it with sed and a regexp
lastVersionLibO=$(cat ftpLibreOffice.temp | grep '<tr><td valign="top"> </td><td><a href="' | tail -n 1 | sed 's/.*\([0-9]\.[0-9]\.[0-9]\).*/\1/')
rm ftpLibreOffice.temp
echo $lastVersionLibO
}
function getLinkLatestLibreOfficeDEB() {
lastVersionLibO=$1
getProcessorArchitecture
url="https://download.documentfoundation.org/libreoffice/stable/"$lastVersionLibO"/deb/"$archFolderName"/LibreOffice_"$lastVersionLibO"_Linux_"$archInFileName"_deb.tar.gz"
echo $url
}
function getProcessorArchitecture() {
arch=$(uname -m)
if [ $arch == "x86_64" ]
then
archFolderName="x86_64"
archInFileName="x86-64"
else
archFolderName="x86"
archInFileName="x86"
fi
}
function extractDEB() {
#first we go to the folder were the DEB files are
cd "LibreOffice_"?"."?"."?"."?"_Linux_"*"_deb"/DEBS
echo "Extracting from .deb"
for b in *.deb; do ## loop for all .DEB files found
ar p $b data.tar.gz | tar zx
done;
#now move LibreOffice folder to script folder
mv "opt/libreoffice"?"."* "$scriptDir""/libreOffice"$version
cd "$scriptDir"
}
function cleaning() {
rm -r "LibreOffice_"?"."?"."?"."?"_Linux_"*"_deb"
rm "libreOffice"?"."?"."?".tar.gz"
}
function createLauncher() {
local launcher="./libreOffice"$version"/LibreOffice Launcher"
echo '#!/bin/bash' >> "$launcher"
#the 2 following lines make sure that the relative path used by
#the launcher will work if you launch it from everywhere
echo 'scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"' >> "$launcher"
echo 'cd "$scriptDir"' >> "$launcher"
echo './program/soffice' >> "$launcher"
chmod +x "$launcher"
}
main