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

Up collectd-bind (5.8.1), foomatic-db-engine (4.0.13), freeimage (3.1.8.0), perl-datetime-format-mail (0.403)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Apr 10 13:37:55 2019 +0200 (2019-04-10)
parents d11fd3e3b9d3
children 36cb14e87ba5
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) 2019 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 #
11 # === Initialisations ===
13 PKGS_DB="/var/lib/tazpkg" # packages database directory
14 PACKAGE="LibreOffice" # package to create and install
15 CATEGORY="office"
16 SHORT_DESC="Productivity suite."
17 WEB_SITE="https://www.libreoffice.org"
18 LICENCE="MPL v2.0"
20 DIR="stable"
21 SUFFIX="Linux_x86_rpm.tar.gz"
22 PREFIX="http://download.documentfoundation.org/libreoffice/$DIR"
24 DEPENDS="java6-jre cups"
25 EXCLUDE="kde|gnome|test"
27 # Declare functions check_root, status, ...
28 . /lib/libtaz.sh
29 # and make commandline options (if any) available as variables
31 is_installed()
32 {
33 if [ -d $root$PKGS_DB/installed/$PACKAGE ]
34 then #package is deemed to be installed
35 return 0
36 else
37 return 1
38 fi
39 }
41 # Show available commandline options, if requested by --help
42 if [ "$help" = "yes" ]
43 then
44 echo "Available commandline options:
45 $0
46 --version=<version>
47 --root=<path_to_root>
48 --install=yes|no
49 --keep=no|yes
50 --srcdir=<directory_for_source_packages>
51 --tmpdir=<directory_to_build-package>"
52 exit
53 fi
55 # Check for system administrator privileges
56 check_root
58 title "Package $PACKAGE will be build as SliTaz package and installed"
60 # Fetch latest $DIR version, unless version is set by option --version
61 [ -z "$version" ] && version="latest"
63 # Fetch language pack according to $LANG, unless otherwise set by option --lang
64 [ -z "$lang" ] && lang="automatic"
66 # Install SliTaz package, unless inhibited by option --install=no
67 [ -z "$install" ] && install="yes"
69 # Delete SliTaz package file $PACKAGE-$VERSION.tazpkg after installation,
70 # unless option --keep=yes is given
71 [ -z "$keep" ] && keep="no"
73 # Directory for temporary files
74 [ -z "$tempdir" ] && TEMP_DIR="/tmp/get-$PACKAGE"
76 # Directory for source archives
77 [ -z "$srcdir" ] && SOURCE_DIR="/tmp/src-$PACKAGE"
79 # Logging file
80 LOG="/tmp/$(basename $0 .sh).log"
82 cat <<EOT
83 Options in use:
84 root : $root/
85 version : $version
86 lang : $lang
87 install package : $install
88 keep tazpkg : $keep
89 source directory: $SOURCE_DIR
90 build directory : $TEMP_DIR
92 EOT
94 separator; newline
96 # === Remove package, if installed ===
97 if is_installed
98 then
99 echo "$PACKAGE is already installed."
100 [ -n "$root" ] && exit 0
101 echo -n "Would you like to remove and reinstall this package [y/N]? "
102 read answer
103 case "$answer" in
104 (y|Y)
105 action "Removing installed version..."
106 tazpkg remove $PACKAGE --root="$root/"
107 [ ! is_installed ] &&
108 die "Can't remove installed version. Exiting." ;;
109 (*)
110 exit 0 ;;
111 esac
112 fi
114 # === Fetch archive file, if not existing ===
116 if [ "$version" == "latest" ]
117 then
118 VERSION="$(basename $(wget -O - $PREFIX/ 2> /dev/null | \
119 sed '/href=\"[0-9]/!d;s/.*href=\"//;s/[/\">].*//' | tail -1))"
120 if [ -z "$VERSION" ]
121 then
122 echo "Can't detect an appropriate version. The version numbering or URL may have changed. Exiting."
123 exit 1
124 fi
125 else
126 VERSION="$version"
127 fi
129 VER="${VERSION/\-/}" # without hyphens
130 TARBALL="LibreOffice_${VER}_${SUFFIX}"
131 WGET_URL="$PREFIX/${VERSION}/rpm/x86/${TARBALL}"
133 # Set LANG_URL to fetch language package
134 if [ "$lang" = "automatic" ]
135 then # use language from $LANG of running process
136 for LOC in ${LANG/_/-} ${LANG%_*}
137 do
138 L_SUFFIX="Linux_x86_rpm_langpack_$LOC.tar.gz"
139 L_TARBALL="LibreOffice_${VER}_${L_SUFFIX}"
140 LANG_URL="$PREFIX/${VERSION}/rpm/x86/${L_TARBALL}"
141 busybox wget -s $LANG_URL 2> /dev/null || continue
142 echo "Added language pack for $LANG ($LOC)."
143 break
144 done
145 else
146 L_SUFFIX="Linux_x86_rpm_langpack_$lang.tar.gz"
147 L_TARBALL="LibreOffice_${VER}_${L_SUFFIX}"
148 LANG_URL="$PREFIX/${VERSION}/rpm/x86/${L_TARBALL}"
149 busybox wget -s $LANG_URL 2> /dev/null &&
150 echo "Added language pack for $lang."
151 fi
153 CUR_DIR=$(pwd)
154 mkdir -p $TEMP_DIR
155 cd $TEMP_DIR
157 if [ -f $SOURCE_DIR/$TARBALL ]
158 then
159 echo "Using existing archive file $TARBALL"
160 else
161 action "Fetching the archives..."
162 newline
163 # Check if $SOURCE_DIR exists
164 [ -d $SOURCE_DIR ] || mkdir -p $SOURCE_DIR
165 wget -c $WGET_URL -O $SOURCE_DIR/$TARBALL
166 if [ -n $L_TARBALL ] # language pack required?
167 then
168 wget -c $LANG_URL -O $SOURCE_DIR/$L_TARBALL
169 fi
170 status
171 fi
173 if [ ! -f $SOURCE_DIR/$TARBALL ]
174 then
175 rm -rf $SOURCE_DIR
176 echo "Could not get $TARBALL. Exiting."
177 exit 1
178 fi
180 # === Extract files from archives ===
181 action "Extracting the archives..."
182 newline
183 mkdir -p $TEMP_DIR
184 for TB in $TARBALL $L_TARBALL
185 do
186 tar xvzf $SOURCE_DIR/$TB -C $TEMP_DIR > $LOG 2>&1 ||
187 (echo "Failed to extract $TB" ; exit 1)
188 done
190 # === Create SliTaz package ===
192 # Prepare metadata for SliTaz package
194 # Get version found in archive
195 # (often directory is still RC version when final is present)
196 VERSION_FROM_ARCHIVE=$(cd $TEMP_DIR;find . -type d 2> /dev/null \
197 | grep LibreOffice | head -n 1 | sed 's/_/ /g' | awk '{print $2}')
198 echo -n "(found v${VERSION_FROM_ARCHIVE})"
200 # Merge language pack into main package
201 if [ -n $L_TARBALL ] # language pack required?
202 then
203 TARBALL_NAME="${TARBALL/.tar.gz/}"
204 L_TARBALL_NAME="${L_TARBALL/.tar.gz/}"
205 mv -f $TEMP_DIR/${L_TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS/*.rpm \
206 $TEMP_DIR/${TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS/
207 fi
208 status
210 # Extracted archives can be removed
211 rm -rf $SOURCE_DIR
213 # Extract almost everything from RPMS directory
214 action "Extracting RPMs..."
215 newline
216 cd $TEMP_DIR/${TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS
217 for i in *.rpm
218 do
219 if (! echo $i | egrep -qi $EXCLUDE)
220 then
221 echo -n "."
222 (rpm2cpio $i | cpio -id >> $LOG 2>&1 ) && rm -f $i
223 fi
224 done
225 status
227 # Move files to package tree $PACKAGE-$VERSION/fs/
228 action "Preparing package..."
229 mkdir -p $PACKAGE-$VERSION/fs/usr/lib/libreoffice
230 mkdir -p $PACKAGE-$VERSION/fs/usr/share
232 # use mv instead of 'cp -a' to save space
233 mv opt/libreoffice* $PACKAGE-$VERSION/fs/usr/lib
234 mv usr/share/mime $PACKAGE-$VERSION/fs/usr/share
235 mv usr/share/icons $PACKAGE-$VERSION/fs/usr/share
236 mv usr/bin $PACKAGE-$VERSION/fs/usr
238 # relocalised libexec directory
239 bin=$PACKAGE-$VERSION/fs/usr/bin/libreoffice${VERSION:0:3}
240 if [ -L $bin ]
241 then
242 target=$(readlink $bin)
243 rm -f $bin
244 ln -s ${target/opt/usr\/lib\/libreoffice} $bin
245 else
246 sed -i 's#/opt/#/usr/lib/libreoffice/#' $bin
247 fi
249 # Create recipe for SliTaz package
250 cat > $PACKAGE-$VERSION/receipt <<EOT
251 # SliTaz package receipt.
253 PACKAGE="$PACKAGE"
254 VERSION="$VERSION"
255 CATEGORY="$CATEGORY"
256 TAGS="writer spreadsheet database"
257 SHORT_DESC="$SHORT_DESC"
258 LICENSE="$LICENCE"
259 WEB_SITE="$WEB_SITE"
260 DEPENDS="$DEPENDS"
262 post_install()
263 {
264 ln -sf /usr/lib/libreoffice?* \
265 /usr/lib/libreoffice
266 path_libreoffice=\$(find /usr/lib/libreoffice -name libreoffice*.*)
268 # Remove links, if existing
269 rm -f /usr/share/applications/libreoffice-*
271 # Create links
272 cd /usr/share/applications
273 ln -sf \$path_libreoffice/share/xdg/base.desktop \
274 libreoffice-base.desktop
275 ln -sf \$path_libreoffice/share/xdg/impress.desktop \
276 libreoffice-impress.desktop
277 ln -sf \$path_libreoffice/share/xdg/writer.desktop \
278 libreoffice-writer.desktop
279 ln -sf \$path_libreoffice/share/xdg/calc.desktop \
280 libreoffice-calc.desktop
281 ln -sf \$path_libreoffice/share/xdg/math.desktop \
282 libreoffice-math.desktop
283 ln -sf \$path_libreoffice/share/xdg/draw.desktop \
284 libreoffice-draw.desktop
286 chmod +x \$path_libreoffice/share/xdg/*.desktop
288 # If necessary, recreate links for soffice
289 rm -f /usr/bin/soffice
290 rm -f /usr/bin/libreoffice
291 ln -sf \$path_libreoffice/program/soffice /usr/bin/libreoffice
292 ln -sf \$path_libreoffice/program/soffice /usr/bin/soffice
293 }
295 post_remove()
296 {
297 rm -f /usr/share/applications/libreoffice-*
298 }
299 EOT
301 status
303 # Create the package
304 tazpkg pack $PACKAGE-$VERSION
306 # Remove package tree
307 rm -rf $PACKAGE-$VERSION
309 # === Install the SliTaz package ===
310 [ "$install" == "yes" ] &&
311 tazpkg install $PACKAGE-$VERSION.tazpkg --root="$root"
313 # === Cleanup ===
314 # Preserve package file, if requested
315 [ "$keep" == "yes" ] && mv $PACKAGE-$VERSION.tazpkg $CUR_DIR
317 # Remove temporary build directory
318 cd $CUR_DIR
319 rm -rf $TEMP_DIR