Bump version to 6.4-15
[LibreOffice.git] / setup_native / scripts / install_linux.sh
blobdf224211e53088570a04884fae13bd9f809602a9
1 #!/bin/bash
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 ADD="no"
21 LINK="no"
22 UPDATE="ask"
23 UNPACKDIR=""
24 USAGE="Usage: $0 [-a,--add] [-l,--link] [-U,--update] [-h,--help] <rpm-source-dir> <office-installation-dir>"
26 help()
28 echo
29 echo "User Mode Installation script for developer and knowledgeable early access tester"
30 echo
31 echo "This installation method is not intended for use in a production environment!"
32 echo "Using this script is unsupported and completely at your own risk"
33 echo
34 echo "Usage:" $0 [-lU] "<rpm-source-dir> <office-installation-dir>"
35 echo " <rpm-source-dir>: directory *only* containing the Linux rpm packages to be installed"
36 echo " or language pack shell script containing the rpm packages"
37 echo " <office-installation-dir>: directory to where the office will get installed into"
38 echo
39 echo "Optional Parameter:"
40 echo " -a,--add: add to an existing <office-installation-dir>"
41 echo " -l,--link: create a link \"soffice\" in $HOME"
42 echo " -U,--update: update without asking"
43 echo " -h,--help: output this help"
44 echo
47 try_to_unpack_languagepack_file()
49 FILENAME=$PACKAGE_PATH
51 # Checking, if $FILENAME is a language pack.
52 # String "language package" has to exist in the shell script file.
53 # If this is no language pack, the installation is not supported
55 SEARCHSTRING=`head --lines=10 $FILENAME | grep "language package"`
57 if [ ! -z "$SEARCHSTRING" ]
58 then
59 echo "First parameter $FILENAME is a language pack";
60 else
61 printf "\nERROR: First parameter $FILENAME is a file, but no language pack shell script.\n"
62 echo $USAGE
63 exit 2
66 echo "Unpacking shell script $FILENAME"
67 TAILLINE=`head --lines=20 $FILENAME | sed --quiet 's/linenum=//p'`
69 UNPACKDIR=/var/tmp/install_$$
70 mkdir $UNPACKDIR
71 # UNPACKDIR=`mktemp -d`
72 tail -n +$TAILLINE $FILENAME | gunzip | (cd $UNPACKDIR; tar xvf -)
74 # Setting the new package path, in which the packages exist
75 PACKAGE_PATH=$UNPACKDIR
77 # Setting variable UPDATE, because an Office installation has to exist, if a language pack shall be installed
78 UPDATE="yes"
82 # this script is for userland not for root
85 if [ $UID -eq 0 ]
86 then
87 printf "\nThis script is for installation without administrative rights only\nPlease use rpm to install as root\n"
88 help
89 exit 2
92 set -- `getopt -u -o 'alhU' -l 'add,link,help,update' -- $*`
94 if [ $? != 0 ]
95 then
96 echo $USAGE
97 exit 2
100 for i in $*
102 case $i in
103 -a|--add) ADD="yes"; shift;;
104 -h|--help) help; exit 0;;
105 -l|--link) LINK="yes"; shift;;
106 -U|--update) UPDATE="yes"; shift;;
107 --) shift; break;;
108 esac
109 done
111 if [ $# != 2 ]
112 then
113 echo $USAGE
114 echo "Example: $0 . ~/libreoffice"
115 exit 2
118 PACKAGE_PATH=$1
121 # If the first parameter is a shell script (download installation set), the packages have to
122 # be unpacked into temp directory
125 if [ -f "$PACKAGE_PATH" ]
126 then
127 try_to_unpack_languagepack_file
131 # Check and get the list of packages to install
134 RPMLIST=`find $PACKAGE_PATH -maxdepth 2 -type f -name "*.rpm" ! -name "*-menus-*" ! -name "*-desktop-integration-*" ! -name "jre*" ! -name "*-userland-*" -print`
136 if [ -z "$RPMLIST" ]
137 then
138 printf "\n$0: No packages found in $PACKAGE_PATH\n"
139 exit 2
142 # #163256# check if we are on a debian system...
143 if rpm --help | grep debian >/dev/null;
144 then
145 DEBIAN_FLAGS="--force-debian --nodeps"
146 else
147 DEBIAN_FLAGS=
151 # Determine whether this should be an update or a fresh install
154 INSTALLDIR=$2
155 RPM_DB_PATH=${INSTALLDIR}/.RPM_OFFICE_DATABASE
157 # Check for versionrc
158 if [ -f ${INSTALLDIR}/program/versionrc ]; then VERSIONRC=versionrc; fi
160 if [ "$UPDATE" = "ask" ]
161 then
162 PRODUCT=`sed --silent -e "
163 /^buildid=/ {
164 s/buildid=\(.*\)/ [\1]/
167 /^ProductKey=/ {
168 s/ProductKey=//
171 }" ${INSTALLDIR}/program/${VERSIONRC:-bootstraprc} 2>/dev/null | tr -d "\012"`
173 if [ ! -z "$PRODUCT" ]
174 then
175 echo
176 echo "Found an installation of $PRODUCT in $INSTALLDIR"
177 echo
178 while [ "$UPDATE" != "yes" ]
180 read -a UPDATE -p "Do you want to update this installation (yes/no)? "
181 if [ "$UPDATE" = "no" ]
182 then
183 exit 2
185 done
186 elif [ -d $RPM_DB_PATH -a "$ADD" = "no" ]
187 then
188 echo
189 echo "The following packages are already installed in $INSTALLDIR"
190 echo
191 rpm --dbpath `cd $RPM_DB_PATH; pwd` --query --all
192 echo
193 while [ "$UPDATE" != "yes" ]
195 read -a UPDATE -p "Do you want to continue with this installation (yes/no)? "
196 if [ "$UPDATE" = "no" ]
197 then
198 exit 2
200 done
201 else
202 UPDATE="no"
207 # Check/Create installation directory
210 if [ "$UPDATE" = "yes" ]
211 then
212 # restore original bootstraprc
213 mv -f ${INSTALLDIR}/program/bootstraprc.orig ${INSTALLDIR}/program/bootstraprc 2>/dev/null
215 # the RPM_DB_PATH must be absolute
216 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then
217 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd`
220 # we should use --freshen for updates to not add languages with patches, but this will break
221 # language packs, so leave it for now ..
222 # RPMCMD="--freshen"
223 RPMCMD="--upgrade"
224 else
225 rmdir ${INSTALLDIR} 2>/dev/null
227 mkdir -p $RPM_DB_PATH || exit 2
228 # XXX why? XXX
229 chmod 700 $RPM_DB_PATH
231 # the RPM_DB_PATH must be absolute
232 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then
233 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd`
236 # Creating RPM database and initializing
237 if [ "$ADD" = "no" ]; then
238 rpm --initdb --dbpath $RPM_DB_PATH
241 # Default install command
242 RPMCMD="--install"
245 # populate the private rpm database with the dependencies needed
246 FAKEDBRPM=/tmp/fake-db-1.0-$$.noarch.rpm
247 linenum=???
248 tail -n +$linenum $0 > $FAKEDBRPM
250 rpm ${DEBIAN_FLAGS} --upgrade --ignoresize --dbpath $RPM_DB_PATH $FAKEDBRPM
252 rm -f $FAKEDBRPM
254 echo "Packages found:"
255 for i in $RPMLIST ; do
256 echo `basename $i`
257 done
260 # Perform the installation
263 echo
264 echo "####################################################################"
265 echo "# Installation of the found packages #"
266 echo "####################################################################"
267 echo
268 echo "Path to the database: " $RPM_DB_PATH
269 echo "Path to the packages: " $PACKAGE_PATH
270 echo "Path to the installation: " $INSTALLDIR
271 echo
272 echo "Installing the RPMs"
274 ABSROOT=`cd ${INSTALLDIR}; pwd`
275 RELOCATIONS=`rpm -qp --qf "--relocate %{PREFIXES}=${ABSROOT}%{PREFIXES} \n" $RPMLIST | sort -u | tr -d "\012"`
276 UserInstallation=\$BRAND_BASE_DIR/../UserInstallation rpm ${DEBIAN_FLAGS} --nodeps $RPMCMD --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST
279 # Create a link into the users home directory
282 if [ "$LINK" = "yes" ]
283 then
284 find `cd "$INSTALLDIR" && pwd` -name soffice -type f -perm /u+x -exec /bin/bash -ce 'ln -sf "$0" "$HOME/soffice" && echo "Creating link from $0 to $HOME/soffice"' {} \;
287 if [ "$UPDATE" = "yes" -a ! -f $INSTALLDIR/program/bootstraprc ]
288 then
289 echo
290 echo "Update failed due to a bug in RPM, uninstalling .."
291 rpm ${DEBIAN_FLAGS} --erase -v --nodeps --dbpath $RPM_DB_PATH `rpm --query --queryformat "%{NAME} " --package $RPMLIST --dbpath $RPM_DB_PATH`
292 echo
293 echo "Now re-installing new packages .."
294 echo
295 rpm ${DEBIAN_FLAGS} --install --nodeps --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST
296 echo
299 # patch the "bootstraprc" to create a self-containing installation
300 find "$INSTALLDIR" -type f -name bootstraprc -exec /bin/bash -ce 'test ! -e "$0".orig && mv "$0" "$0".orig && sed '\''s,^UserInstallation=$SYSUSERCONFIG.*,UserInstallation=$BRAND_BASE_DIR/../UserInstallation,'\'' "$0".orig > "$0"' {} \;
302 # if an unpack directory exists, it can be removed now
303 if [ ! -z "$UNPACKDIR" ]
304 then
305 rm $UNPACKDIR/*.rpm
306 rmdir $UNPACKDIR
307 echo "Removed temporary directory $UNPACKDIR"
310 echo
311 echo "Installation done ..."
313 exit 0