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

updated xtrkcad and xtrkcad-dev (4.0.3a1 -> 5.1.2a)
author Hans-G?nter Theisgen
date Thu Nov 14 11:00:47 2019 +0100 (2019-11-14)
parents e12ece9707c2
children 57a7405e48e5
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 VERSIONS="$(wget -qO - $PREFIX/ | \
119 sed '/href=\"[0-9]/!d;s/.*href=\"//;s/[/\">].*//' | tac)"
120 if [ -z "$VERSIONS" ]
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 VERSIONS="$version"
127 fi
129 for VERSION in $VERSIONS; do # foreach VERSION
131 VER="${VERSION/\-/}" # without hyphens
132 TARBALL="LibreOffice_${VER}_${SUFFIX}"
133 WGET_URL="$PREFIX/${VERSION}/rpm/x86/${TARBALL}"
135 # Set LANG_URL to fetch language package
136 if [ "$lang" = "automatic" ]
137 then # use language from $LANG of running process
138 for LOC in ${LANG/_/-} ${LANG%_*}
139 do
140 L_SUFFIX="Linux_x86_rpm_langpack_$LOC.tar.gz"
141 L_TARBALL="LibreOffice_${VER}_${L_SUFFIX}"
142 LANG_URL="$PREFIX/${VERSION}/rpm/x86/${L_TARBALL}"
143 busybox wget -s $LANG_URL 2> /dev/null || continue
144 echo "Added language pack for $LANG ($LOC)."
145 break
146 done
147 else
148 L_SUFFIX="Linux_x86_rpm_langpack_$lang.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 &&
152 echo "Added language pack for $lang."
153 fi
155 CUR_DIR=$(pwd)
156 mkdir -p $TEMP_DIR
157 cd $TEMP_DIR
159 if [ -f $SOURCE_DIR/$TARBALL ]
160 then
161 echo "Using existing archive file $TARBALL"
162 else
163 action "Fetching the archives..."
164 newline
165 # Check if $SOURCE_DIR exists
166 [ -d $SOURCE_DIR ] || mkdir -p $SOURCE_DIR
167 wget -c $WGET_URL -O $SOURCE_DIR/$TARBALL || continue
168 if [ -n $L_TARBALL ] # language pack required?
169 then
170 wget -c $LANG_URL -O $SOURCE_DIR/$L_TARBALL
171 fi
172 status
173 fi
175 break
177 done # foreach VERSIONS
179 if [ ! -f $SOURCE_DIR/$TARBALL ]
180 then
181 rm -rf $SOURCE_DIR
182 echo "Could not get $TARBALL. Exiting."
183 exit 1
184 fi
186 # === Extract files from archives ===
187 action "Extracting the archives..."
188 newline
189 mkdir -p $TEMP_DIR
190 for TB in $TARBALL $L_TARBALL
191 do
192 tar xvzf $SOURCE_DIR/$TB -C $TEMP_DIR > $LOG 2>&1 ||
193 (echo "Failed to extract $TB" ; exit 1)
194 done
196 # === Create SliTaz package ===
198 # Prepare metadata for SliTaz package
200 # Get version found in archive
201 # (often directory is still RC version when final is present)
202 VERSION_FROM_ARCHIVE=$(cd $TEMP_DIR;find . -type d 2> /dev/null \
203 | grep LibreOffice | head -n 1 | sed 's/_/ /g' | awk '{print $2}')
204 echo -n "(found v${VERSION_FROM_ARCHIVE})"
206 # Merge language pack into main package
207 if [ -n $L_TARBALL ] # language pack required?
208 then
209 TARBALL_NAME="${TARBALL/.tar.gz/}"
210 L_TARBALL_NAME="${L_TARBALL/.tar.gz/}"
211 mv -f $TEMP_DIR/${L_TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS/*.rpm \
212 $TEMP_DIR/${TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS/
213 fi
214 status
216 # Extracted archives can be removed
217 rm -rf $SOURCE_DIR
219 # Extract almost everything from RPMS directory
220 action "Extracting RPMs..."
221 newline
222 cd $TEMP_DIR/${TARBALL_NAME/$VERSION/$VERSION_FROM_ARCHIVE}/RPMS
223 for i in *.rpm
224 do
225 if (! echo $i | egrep -qi $EXCLUDE)
226 then
227 echo -n "."
228 (rpm2cpio $i | cpio -id >> $LOG 2>&1 ) && rm -f $i
229 fi
230 done
231 status
233 # Move files to package tree $PACKAGE-$VERSION/fs/
234 action "Preparing package..."
235 mkdir -p $PACKAGE-$VERSION/fs/usr/lib/libreoffice
236 mkdir -p $PACKAGE-$VERSION/fs/usr/share
238 # use mv instead of 'cp -a' to save space
239 mv opt/libreoffice* $PACKAGE-$VERSION/fs/usr/lib
240 mv usr/share/mime $PACKAGE-$VERSION/fs/usr/share
241 mv usr/share/icons $PACKAGE-$VERSION/fs/usr/share
242 mv usr/bin $PACKAGE-$VERSION/fs/usr
244 # relocalised libexec directory
245 bin=$PACKAGE-$VERSION/fs/usr/bin/libreoffice${VERSION:0:3}
246 if [ -L $bin ]
247 then
248 target=$(readlink $bin)
249 rm -f $bin
250 ln -s ${target/opt/usr\/lib\/libreoffice} $bin
251 else
252 sed -i 's#/opt/#/usr/lib/libreoffice/#' $bin
253 fi
255 # Create recipe for SliTaz package
256 cat > $PACKAGE-$VERSION/receipt <<EOT
257 # SliTaz package receipt.
259 PACKAGE="$PACKAGE"
260 VERSION="$VERSION"
261 CATEGORY="$CATEGORY"
262 TAGS="writer spreadsheet database"
263 SHORT_DESC="$SHORT_DESC"
264 LICENSE="$LICENCE"
265 WEB_SITE="$WEB_SITE"
266 DEPENDS="$DEPENDS"
268 post_install()
269 {
270 ln -sf /usr/lib/libreoffice?* \\
271 /usr/lib/libreoffice
272 path_libreoffice=\$(find /usr/lib/libreoffice -name libreoffice*.*)
274 # Remove links, if existing
275 rm -f /usr/share/applications/libreoffice-*
277 # Create links
278 cd /usr/share/applications
279 ln -sf \$path_libreoffice/share/xdg/base.desktop \\
280 libreoffice-base.desktop
281 ln -sf \$path_libreoffice/share/xdg/impress.desktop \\
282 libreoffice-impress.desktop
283 ln -sf \$path_libreoffice/share/xdg/writer.desktop \\
284 libreoffice-writer.desktop
285 ln -sf \$path_libreoffice/share/xdg/calc.desktop \\
286 libreoffice-calc.desktop
287 ln -sf \$path_libreoffice/share/xdg/math.desktop \\
288 libreoffice-math.desktop
289 ln -sf \$path_libreoffice/share/xdg/draw.desktop \\
290 libreoffice-draw.desktop
292 chmod +x \$path_libreoffice/share/xdg/*.desktop
294 # Fix menu entries
295 sed -i 's|^\\([Ee]xec=libreoffice\\)[0-9\\.]*|\\0|' \\
296 \$path_libreoffice/share/xdg/*.desktop
298 # If necessary, recreate links for soffice
299 rm -f /usr/bin/soffice
300 rm -f /usr/bin/libreoffice
301 ln -sf \$path_libreoffice/program/soffice /usr/bin/libreoffice
302 ln -sf \$path_libreoffice/program/soffice /usr/bin/soffice
303 }
305 post_remove()
306 {
307 rm -f /usr/share/applications/libreoffice-*
308 }
309 EOT
311 status
313 # Create the package
314 tazpkg pack $PACKAGE-$VERSION
316 # Remove package tree
317 rm -rf $PACKAGE-$VERSION
319 # === Install the SliTaz package ===
320 [ "$install" == "yes" ] &&
321 tazpkg install $PACKAGE-$VERSION.tazpkg --root="$root"
323 # === Cleanup ===
324 # Preserve package file, if requested
325 [ "$keep" == "yes" ] && mv $PACKAGE-$VERSION.tazpkg $CUR_DIR
327 # Remove temporary build directory
328 cd $CUR_DIR
329 rm -rf $TEMP_DIR