wok-stable view get-LibreOffice/stuff/get-LibreOffice @ rev 11148
xterm: add xterm.desktop & xterm.png
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Nov 01 09:40:24 2011 +0100 (2011-11-01) |
parents | 094990fe3941 |
children | 31976c6bdebf |
line source
1 #!/bin/sh
2 # get-LibreOffice - install LibreOffice excl. KDE/Gnome integration & test suite.
3 #
4 # (C) 2010 SliTaz - GNU General Public License v3.
5 # Author : Ben Arnold <ben@seawolfsanctuary.com>
6 # via : get-OpenOffice3 (Eric Joseph-Alexandre <erjo@slitaz.org>)
7 #
9 PACKAGE="LibreOffice"
10 URL="http://www.libreoffice.org"
11 ROOT="$1"
12 DIR="stable"
13 SUFFIX="Linux_x86_install-rpm_en-US.tar.gz"
14 WGET_URL="http://download.documentfoundation.org/libreoffice/$DIR"
16 VERSION="$(basename $(wget -O - $WGET_URL/ 2> /dev/null | \
17 sed '/href=\"[0-9]/!d;s/.*href=\"//;s/[/\">].*//' | tail -1))"
18 if [ -z "$VERSION" ]; then
19 echo "Can't detect an appropriate version. The version numbering or URL may have changed. Aborted."
20 exit 0
21 fi
22 VER="${VERSION/\-/}" # without hyphens
25 TARBALL="LibO_${VER}_${SUFFIX}"
27 for LOC in ${LANG/_/-} ${LANG%_*}; do
28 L_SUFFIX="Linux_x86_langpack-rpm_$LOC.tar.gz"
29 L_TARBALL="LibO_${VER}_${L_SUFFIX}"
30 LANG_URL="$WGET_URL/${VERSION}/rpm/x86/${L_TARBALL}"
31 busybox wget -s $LANG_URL 2> /dev/null || continue
32 echo "Added $LANG ($LOC)."
33 break
34 done
35 WGET_URL="$WGET_URL/${VERSION}/rpm/x86/${TARBALL}"
37 CUR_DIR=$(pwd)
38 TEMP_DIR="/tmp/$PACKAGE.$$"
39 SOURCE_DIR="/tmp/src.$$"
40 EXCLUDE="kde|gnome|test"
41 LOG="/tmp/$(basename $0 .sh).log"
44 # Status function with color (supported by Ash).
45 status()
46 {
47 local CHECK=$?
48 echo -en "\\033[70G[ "
49 if [ $CHECK = 0 ]; then
50 echo -en "\\033[1;33mOK"
51 else
52 echo -en "\\033[1;31mFailed"
53 fi
54 echo -e "\\033[0;39m ]"
55 return $CHECK
56 }
58 # Check if user is root to install, or remove packages.
59 check_root()
60 {
61 if test $(id -u) != 0 ; then
62 echo -e "\nYou must be root to run `basename $0` with this option."
63 echo -e "Please use 'su' and root password to become super-user.\n"
64 exit 0
65 fi
66 }
68 check_if_installed()
69 {
70 # Avoid reinstall
71 if [ -d $ROOT/var/lib/tazpkg/installed/$PACKAGE ];then
72 return 0
73 else
74 return 1
75 fi
76 }
78 # We need to be root
79 check_root
81 # Check if package already installed
82 if (check_if_installed $PACKAGE); then
83 echo "$PACKAGE is already installed."
84 [ -n "$ROOT" ] && exit 0
85 echo -n "Would you like to remove and reinstall this package [y/n]? "
86 read answer
87 case "$answer" in
88 y|Y)
89 tazpkg remove $PACKAGE ;;
90 *)
91 exit 0 ;;
92 esac
94 fi
97 # Check if we have the tarball before.
98 if [ ! -f $SOURCE_DIR/$TARBALL ]; then
99 echo "Downloading LibreOffice tarball (it's time to have a break)... "
100 # Check if $SOURCE_DIR exist
101 test -d $SOURCE_DIR || mkdir -p $SOURCE_DIR
102 # Get the file.
103 wget -c $WGET_URL -O $SOURCE_DIR/$TARBALL
104 if [ -n $L_TARBALL ] ; then # Are we localised?
105 wget -c $LANG_URL -O $SOURCE_DIR/$L_TARBALL
106 fi
107 status
108 fi
109 if [ ! -f $SOURCE_DIR/$TARBALL ]; then
110 rm -rf $SOURCE_DIR
111 echo "Could not download $TARBALL. Exiting."
112 exit 1
113 fi
115 echo -n "Extracting files (this may take a while): "
117 # Creates TEMP_DIR and extract tarball
118 mkdir -p $TEMP_DIR
119 for TB in $TARBALL $L_TARBALL ; do
120 tar xvzf $SOURCE_DIR/$TB -C $TEMP_DIR > $LOG 2>&1 || \
121 (echo "Failed to extract $TB" ; exit 1)
122 done
124 # Get version found in archive (often directory is still RC version when final is present)
125 ARCHIVED_VERSION=`find $TEMP_DIR -type d 2> /dev/null | grep LibO | head -n 1 | sed 's/_/ /g' | awk '{print $2}'`
126 echo -n "(found v${ARCHIVED_VERSION})"
128 # Consolidate localisations into main package
129 if [ -n $L_TARBALL ] ; then # Are we localised?
130 TARBALL_NAME="${TARBALL/.tar.gz/}"
131 L_TARBALL_NAME="${L_TARBALL/.tar.gz/}"
132 mv -f $TEMP_DIR/${L_TARBALL_NAME/$VERSION/$ARCHIVED_VERSION}/RPMS/*.rpm $TEMP_DIR/${TARBALL_NAME/$VERSION/$ARCHIVED_VERSION}/RPMS/
133 fi
134 status
136 # Extracted pkg can be removed: Save RAM
137 rm -rf $SOURCE_DIR
139 # Extract everything from RPMS
140 cd $TEMP_DIR/${TARBALL_NAME/$VERSION/$ARCHIVED_VERSION}/RPMS
141 for i in *.rpm
142 do
143 if (! echo $i | egrep -qi $EXCLUDE); then
144 echo -n "."
145 (rpm2cpio $i | cpio -id >> $LOG 2>&1 ) && rm -f $i
146 fi
147 done
148 rpm2cpio desktop-integration/*freedesktop*.rpm | cpio -id >> $LOG 2>&1
150 # extracted pkg can be removed: Save RAM
151 rm -f desktop-integration/*freedesktop*.rpm
153 status
154 echo -n "Preparing package... "
156 # Make the package
157 mkdir -p $PACKAGE-$VERSION/fs/usr/lib/libreoffice \
158 $PACKAGE-$VERSION/fs/usr/share
160 # use mv instead of 'cp -a' to save RAM
161 mv opt/libreoffice* $PACKAGE-$VERSION/fs/usr/lib
162 mv usr/share/mime $PACKAGE-$VERSION/fs/usr/share
163 mv usr/share/icons $PACKAGE-$VERSION/fs/usr/share
164 mv usr/bin $PACKAGE-$VERSION/fs/usr
166 # relocalized libexec directory
167 bin=$(ls $PACKAGE-$VERSION/fs/usr/bin/libreoffice???)
168 if [ -L $bin ]; then
169 target=$(readlink $bin)
170 rm -f $bin
171 ln -s ${target/opt/usr\/lib\/libreoffice} $bin
172 else
173 sed -i 's#/opt/#/usr/lib/libreoffice/#' $bin
174 fi
176 # Create receipt
177 cat > $PACKAGE-$VERSION/receipt <<EOT
178 # SliTaz package receipt.
180 PACKAGE="$PACKAGE"
181 VERSION="$VERSION"
182 CATEGORY="office"
183 SHORT_DESC="Productivity suite."
184 DEPENDS="java6-jre"
185 WEB_SITE="$URL"
187 post_install()
188 {
189 cd /usr/share/applications
190 ln -s /usr/lib/libreoffice?*/share/xdg/base.desktop libreoffice-base.desktop
191 ln -s /usr/lib/libreoffice?*/share/xdg/impress.desktop libreoffice-impress.desktop
192 ln -s /usr/lib/libreoffice?*/share/xdg/writer.desktop libreoffice-writer.desktop
193 ln -s /usr/lib/libreoffice?*/share/xdg/calc.desktop libreoffice-calc.desktop
194 ln -s /usr/lib/libreoffice?*/share/xdg/math.desktop libreoffice-math.desktop
195 ln -s /usr/lib/libreoffice?*/share/xdg/draw.desktop libreoffice-draw.desktop
196 ln -s /usr/lib/libreoffice?*/share/xdg/printeradmin.desktop libreoffice-printeradmin.desktop
197 chmod +x /usr/lib/libreoffice?*/share/xdg/*.desktop
199 cd /usr/bin
200 ln -s /usr/lib/libreoffice?* /usr/lib/libreoffice
201 ln -sf /usr/lib/libreoffice/program/soffice
202 }
204 post_remove()
205 {
206 rm -f /usr/share/applications/libreoffice-*
207 }
209 EOT
210 status
212 # Pack
213 tazpkg pack $PACKAGE-$VERSION
215 # Clean to save RAM memory
216 rm -rf $PACKAGE-$VERSION
218 # Install pseudo package
219 tazpkg install $PACKAGE-$VERSION.tazpkg --root=$ROOT
220 case " $@ " in
221 *\ --k*) mv $PACKAGE-$VERSION.tazpkg $CUR_DIR ;;
222 esac
224 # Clean
225 cd $CUR_DIR
226 rm -rf $TEMP_DIR