wok view get-LibreOffice/stuff/get-LibreOffice @ rev 24334

polkit: CVE-2021-4034
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 28 11:07:11 2022 +0000 (2022-01-28)
parents 57a7405e48e5
children ae58b675745d
line source
1 #!/bin/sh
2 # get-LibreOffice - create and install SliTaz package LibreOffice
3 # excluding KDE and GNOME integration and test suite.
4 #
5 # (C) 2020 SliTaz - GNU General Public License v3.
6 # Author : Ben Arnold <ben@seawolfsanctuary.com>
7 # via : get-OpenOffice3 (Eric Joseph-Alexandre <erjo@slitaz.org>)
8 # modified by Hans-Günter Theisgen on 2019-04-07
9 # modified by Hans-Günter Theisgen on 2020-03-17
10 # modified by Hans-Günter Theisgen on 2020-07-24
11 #
13 # === Initialisations ===
15 PKGS_DB="/var/lib/tazpkg" # packages database directory
16 PACKAGE="LibreOffice" # package to create and install
17 CATEGORY="office"
18 SHORT_DESC="Productivity suite."
19 WEB_SITE="https://www.libreoffice.org"
20 LICENCE="MPL v2.0"
22 DIR="stable"
23 SUFFIX="Linux_x86_rpm.tar.gz"
24 PREFIX="http://download.documentfoundation.org/libreoffice/$DIR"
26 DEPENDS="cups"
27 EXCLUDE="kde|gnome|test"
29 # Declare functions check_root, status, ...
30 . /lib/libtaz.sh
31 # and make commandline options (if any) available as variables
33 is_installed()
34 {
35 if [ -d $root$PKGS_DB/installed/$PACKAGE ]
36 then #package is deemed to be installed
37 return 0
38 else
39 return 1
40 fi
41 }
43 # Show available commandline options, if requested by --help
44 if [ "$help" = "yes" ]
45 then
46 echo "Available commandline options:
47 $0
48 --version=<version>
49 --root=<path_to_root>
50 --install=yes|no
51 --keep=no|yes
52 --srcdir=<directory_for_source_packages>
53 --tmpdir=<directory_to_build-package>"
54 exit
55 fi
57 # Check for system administrator privileges
58 check_root
60 title "Package $PACKAGE will be build as SliTaz package and installed"
62 # Fetch latest $DIR version, unless version is set by option --version
63 #[ -z "$version" ] && version="latest"
64 [ -z "$version" ] && version="6.2.8.2" &&
65 echo "Newer versions than 6.2.8.2 are not available in 32-bit flavour!"
67 # Fetch language pack according to $LANG, unless otherwise set by option --lang
68 [ -z "$lang" ] && lang="automatic"
70 # Install SliTaz package, unless inhibited by option --install=no
71 [ -z "$install" ] && install="yes"
73 # Delete SliTaz package file $PACKAGE-$VERSION.tazpkg after installation,
74 # unless option --keep=yes is given
75 [ -z "$keep" ] && keep="no"
77 # Directory for temporary files
78 [ -z "$tempdir" ] && TEMP_DIR="/tmp/get-$PACKAGE"
80 # Directory for source archives
81 [ -z "$srcdir" ] && SOURCE_DIR="/tmp/src-$PACKAGE"
83 # Logging file
84 LOG="/tmp/$(basename $0 .sh).log"
86 cat <<EOT
87 Options in use:
88 root : $root/
89 version : $version
90 lang : $lang
91 install package : $install
92 keep tazpkg : $keep
93 source directory: $SOURCE_DIR
94 build directory : $TEMP_DIR
95 logging file: $LOG
97 EOT
99 separator; newline
101 # === Remove package, if installed ===
102 if is_installed
103 then
104 echo "$PACKAGE is already installed."
105 [ -n "$root" ] && exit 0
106 echo -n "Would you like to remove and reinstall this package [y/N]? "
107 read answer
108 case "$answer" in
109 (y|Y)
110 action "Removing installed version..."
111 tazpkg remove $PACKAGE --root="$root/"
112 [ ! is_installed ] &&
113 die "Can't remove installed version. Exiting." ;;
114 (*)
115 exit 0 ;;
116 esac
117 fi
119 # === Fetch archive file, if not existing ===
121 if [ "$version" == "latest" ]
122 then
123 VERSIONS="$(wget -qO - $PREFIX/ | \
124 sed '/href=\"[0-9]/!d;s/.*href=\"//;s/[/\">].*//' | tac)"
125 if [ -z "$VERSIONS" ]
126 then
127 echo "Can't detect an appropriate version. The version numbering or URL may have changed. Exiting."
128 exit 1
129 fi
130 else
131 DIR="old"
132 PREFIX="http://downloadarchive.documentfoundation.org/libreoffice/$DIR"
133 VERSIONS="$version"
134 fi
136 for VERSION in $VERSIONS
137 do # foreach VERSION
139 VER="${VERSION/\-/}" # without hyphens
140 TARBALL="LibreOffice_${VER}_${SUFFIX}"
141 WGET_URL="$PREFIX/${VERSION}/rpm/x86/${TARBALL}"
143 # Set LANG_URL to fetch language package
144 if [ "$lang" = "automatic" ]
145 then # use language from $LANG of running process
146 for LOC in ${LANG/_/-} ${LANG%_*}
147 do
148 L_SUFFIX="Linux_x86_rpm_langpack_$LOC.tar.gz"
149 L_TARBALL="LibreOffice_${VER}_${L_SUFFIX}"
150 LANG_URL="$PREFIX/${VERSION}/rpm/x86/${L_TARBALL}"
151 busybox wget -s $LANG_URL 2> /dev/null || continue
152 echo "Added language pack for $LANG ($LOC)."
153 break
154 done
155 else
156 L_SUFFIX="Linux_x86_rpm_langpack_$lang.tar.gz"
157 L_TARBALL="LibreOffice_${VER}_${L_SUFFIX}"
158 LANG_URL="$PREFIX/${VERSION}/rpm/x86/${L_TARBALL}"
159 busybox wget -s $LANG_URL 2> /dev/null &&
160 echo "Added language pack for $lang."
161 fi
163 CUR_DIR=$(pwd)
164 mkdir -p $TEMP_DIR
165 cd $TEMP_DIR
167 if [ -f $SOURCE_DIR/$TARBALL ]
168 then
169 echo "Using existing archive file $TARBALL"
170 else
171 action "Fetching the archives..."
172 newline
173 # Check if $SOURCE_DIR exists
174 [ -d $SOURCE_DIR ] || mkdir -p $SOURCE_DIR
175 wget -c $WGET_URL -O $SOURCE_DIR/$TARBALL || continue
176 if [ -n $L_TARBALL ] # language pack required?
177 then
178 wget -c $LANG_URL -O $SOURCE_DIR/$L_TARBALL
179 fi
180 status
181 fi
183 break
185 done # foreach VERSION
187 if [ ! -f $SOURCE_DIR/$TARBALL ]
188 then
189 rm -rf $SOURCE_DIR
190 echo "Could not get $TARBALL. Exiting."
191 exit 1
192 fi
194 # === Extract files from archives ===
195 action "Extracting the archives..."
196 newline
197 mkdir -p $TEMP_DIR
198 for TB in $TARBALL $L_TARBALL
199 do
200 tar xvzf $SOURCE_DIR/$TB -C $TEMP_DIR > $LOG 2>&1 ||
201 (echo "Failed to extract $TB" ; exit 1)
202 done
204 # === Create SliTaz package ===
206 # Prepare metadata for SliTaz package
208 # Get version found in archive
209 # (often directory is still RC version when final is present)
210 VERSION_FROM_ARCHIVE=$(cd $TEMP_DIR;find . -type d 2> /dev/null \
211 | grep LibreOffice | head -n 1 | sed 's/_/ /g' | awk '{print $2}')
212 echo -n "(found v${VERSION_FROM_ARCHIVE})"
214 # Merge language pack into main package
215 if [ -n $L_TARBALL ] # language pack required?
216 then
217 TARBALL_NAME="${TARBALL/.tar.gz/}"
218 L_TARBALL_NAME="${L_TARBALL/.tar.gz/}"
219 mv -f $TEMP_DIR/${L_TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS/*.rpm \
220 $TEMP_DIR/${TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS/
221 fi
222 status
224 # Extracted archives can be removed
225 rm -rf $SOURCE_DIR
227 # Extract almost everything from RPMS directory
228 action "Extracting RPMs..."
229 newline
230 cd $TEMP_DIR/${TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS
231 for i in *.rpm
232 do
233 if (! echo $i | egrep -qi $EXCLUDE)
234 then
235 echo -n "."
236 (rpm2cpio $i | cpio -id >> $LOG 2>&1 ) && rm -f $i
237 fi
238 done
239 status
241 # Move files to package tree $PACKAGE-$VERSION/fs/
242 action "Preparing package..."
243 mkdir -p $PACKAGE-$VERSION/fs/usr/lib/libreoffice
244 mkdir -p $PACKAGE-$VERSION/fs/usr/share
246 # use mv instead of 'cp -a' to save space
247 mv opt/libreoffice* $PACKAGE-$VERSION/fs/usr/lib
248 mv usr/share/mime $PACKAGE-$VERSION/fs/usr/share
249 mv usr/share/icons $PACKAGE-$VERSION/fs/usr/share
250 mv usr/bin $PACKAGE-$VERSION/fs/usr
252 # relocalised libexec directory
253 bin=$PACKAGE-$VERSION/fs/usr/bin/libreoffice${VERSION:0:3}
254 if [ -L $bin ]
255 then
256 target=$(readlink $bin)
257 rm -f $bin
258 ln -s ${target/opt/usr\/lib\/libreoffice} $bin
259 else
260 sed -i 's#/opt/#/usr/lib/libreoffice/#' $bin
261 fi
263 # Create recipe for SliTaz package
264 cat > $PACKAGE-$VERSION/receipt <<EOT
265 # SliTaz package receipt.
267 PACKAGE="$PACKAGE"
268 VERSION="$VERSION"
269 CATEGORY="$CATEGORY"
270 TAGS="writer spreadsheet database"
271 SHORT_DESC="$SHORT_DESC"
272 LICENSE="$LICENCE"
273 WEB_SITE="$WEB_SITE"
274 DEPENDS="$DEPENDS"
276 post_install()
277 {
278 ln -sf /usr/lib/libreoffice?* \\
279 /usr/lib/libreoffice
280 path_libreoffice=\$(find /usr/lib/libreoffice -name libreoffice*.*)
282 # Remove links, if existing
283 rm -f /usr/share/applications/libreoffice-*
285 # Create links
286 cd /usr/share/applications
287 ln -sf \$path_libreoffice/share/xdg/base.desktop \\
288 libreoffice-base.desktop
289 ln -sf \$path_libreoffice/share/xdg/impress.desktop \\
290 libreoffice-impress.desktop
291 ln -sf \$path_libreoffice/share/xdg/writer.desktop \\
292 libreoffice-writer.desktop
293 ln -sf \$path_libreoffice/share/xdg/calc.desktop \\
294 libreoffice-calc.desktop
295 ln -sf \$path_libreoffice/share/xdg/math.desktop \\
296 libreoffice-math.desktop
297 ln -sf \$path_libreoffice/share/xdg/draw.desktop \\
298 libreoffice-draw.desktop
300 chmod +x \$path_libreoffice/share/xdg/*.desktop
302 # Fix menu entries
303 sed -i 's|^\\([Ee]xec=libreoffice\\)[0-9\\.]*|\\0|' \\
304 \$path_libreoffice/share/xdg/*.desktop
306 # If necessary, recreate links for soffice
307 rm -f /usr/bin/soffice
308 rm -f /usr/bin/libreoffice
309 ln -sf \$path_libreoffice/program/soffice /usr/bin/libreoffice
310 ln -sf \$path_libreoffice/program/soffice /usr/bin/soffice
311 }
313 post_remove()
314 {
315 rm -f /usr/share/applications/libreoffice-*
316 }
317 EOT
319 status
321 # Create the package
322 tazpkg pack $PACKAGE-$VERSION
324 # Remove package tree
325 rm -rf $PACKAGE-$VERSION
327 # === Install the SliTaz package ===
328 [ "$install" == "yes" ] &&
329 tazpkg install $PACKAGE-$VERSION.tazpkg --root="$root"
331 # === Cleanup ===
332 # Preserve package file, if requested
333 [ "$keep" == "yes" ] &&
334 ( mv $PACKAGE-$VERSION.tazpkg $CUR_DIR &&
335 echo Saved $PACKAGE-$VERSION.tazpkg to $CUR_DIR )
337 # Remove temporary build directory
338 cd $CUR_DIR
339 rm -rf $TEMP_DIR