tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / setup_native / scripts / install_linux.sh
blobabf9b2d84e58c5fbc9810f5b45ebb988ec6425b3
1 #!/usr/bin/env 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=`mktemp -d -p /var/tmp`
70 tail -n +$TAILLINE $FILENAME | gunzip | (cd $UNPACKDIR; tar xvf -)
72 # Setting the new package path, in which the packages exist
73 PACKAGE_PATH=$UNPACKDIR
75 # Setting variable UPDATE, because an Office installation has to exist, if a language pack shall be installed
76 UPDATE="yes"
80 # this script is for userland not for root
83 if [ $UID -eq 0 ]
84 then
85 printf "\nThis script is for installation without administrative rights only\nPlease use rpm to install as root\n"
86 help
87 exit 2
90 set -- `getopt -u -o 'alhU' -l 'add,link,help,update' -- $*`
92 if [ $? != 0 ]
93 then
94 echo $USAGE
95 exit 2
98 for i in $*
100 case $i in
101 -a|--add) ADD="yes"; shift;;
102 -h|--help) help; exit 0;;
103 -l|--link) LINK="yes"; shift;;
104 -U|--update) UPDATE="yes"; shift;;
105 --) shift; break;;
106 esac
107 done
109 if [ $# != 2 ]
110 then
111 echo $USAGE
112 echo "Example: $0 . ~/libreoffice"
113 exit 2
116 PACKAGE_PATH=$1
119 # If the first parameter is a shell script (download installation set), the packages have to
120 # be unpacked into temp directory
123 if [ -f "$PACKAGE_PATH" ]
124 then
125 try_to_unpack_languagepack_file
129 # Check and get the list of packages to install
132 RPMLIST=`find $PACKAGE_PATH -maxdepth 2 -type f -name "*.rpm" ! -name "*-menus-*" ! -name "*-desktop-integration-*" ! -name "jre*" ! -name "*-userland-*" -print`
134 if [ -z "$RPMLIST" ]
135 then
136 printf "\n$0: No packages found in $PACKAGE_PATH\n"
137 exit 2
140 # #163256# check if we are on a debian system...
141 if rpm --help | grep debian >/dev/null;
142 then
143 DEBIAN_FLAGS="--force-debian --nodeps"
144 else
145 DEBIAN_FLAGS=
149 # Determine whether this should be an update or a fresh install
152 INSTALLDIR=$2
153 RPM_DB_PATH=${INSTALLDIR}/.RPM_OFFICE_DATABASE
155 # Check for versionrc
156 if [ -f ${INSTALLDIR}/program/versionrc ]; then VERSIONRC=versionrc; fi
158 if [ "$UPDATE" = "ask" ]
159 then
160 PRODUCT=`sed --silent -e "
161 /^buildid=/ {
162 s/buildid=\(.*\)/ [\1]/
165 /^ProductKey=/ {
166 s/ProductKey=//
169 }" ${INSTALLDIR}/program/${VERSIONRC:-bootstraprc} 2>/dev/null | tr -d "\012"`
171 if [ ! -z "$PRODUCT" ]
172 then
173 echo
174 echo "Found an installation of $PRODUCT in $INSTALLDIR"
175 echo
176 while [ "$UPDATE" != "yes" ]
178 read -a UPDATE -p "Do you want to update this installation (yes/no)? "
179 if [ "$UPDATE" = "no" ]
180 then
181 exit 2
183 done
184 elif [ -d $RPM_DB_PATH -a "$ADD" = "no" ]
185 then
186 echo
187 echo "The following packages are already installed in $INSTALLDIR"
188 echo
189 rpm --dbpath `cd $RPM_DB_PATH; pwd` --query --all
190 echo
191 while [ "$UPDATE" != "yes" ]
193 read -a UPDATE -p "Do you want to continue with this installation (yes/no)? "
194 if [ "$UPDATE" = "no" ]
195 then
196 exit 2
198 done
199 else
200 UPDATE="no"
205 # Check/Create installation directory
208 if [ "$UPDATE" = "yes" ]
209 then
210 # restore original bootstraprc
211 mv -f ${INSTALLDIR}/program/bootstraprc.orig ${INSTALLDIR}/program/bootstraprc 2>/dev/null
213 # the RPM_DB_PATH must be absolute
214 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then
215 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd`
218 # we should use --freshen for updates to not add languages with patches, but this will break
219 # language packs, so leave it for now ..
220 # RPMCMD="--freshen"
221 RPMCMD="--upgrade"
222 else
223 rmdir ${INSTALLDIR} 2>/dev/null
225 mkdir -p $RPM_DB_PATH || exit 2
226 # XXX why? XXX
227 chmod 700 $RPM_DB_PATH
229 # the RPM_DB_PATH must be absolute
230 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then
231 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd`
234 # Creating RPM database and initializing
235 if [ "$ADD" = "no" ]; then
236 rpm --initdb --dbpath $RPM_DB_PATH
239 # Default install command
240 RPMCMD="--install"
243 # populate the private rpm database with the dependencies needed
244 FAKEDBRPM=`mktemp -p /tmp fake-db-1.0-XXXXXXXXXX.noarch.rpm`
245 linenum=???
246 tail -n +$linenum $0 > $FAKEDBRPM
248 rpm ${DEBIAN_FLAGS} --upgrade --ignoresize --dbpath $RPM_DB_PATH $FAKEDBRPM
250 rm -f $FAKEDBRPM
252 echo "Packages found:"
253 for i in $RPMLIST ; do
254 echo `basename $i`
255 done
258 # Perform the installation
261 echo
262 echo "####################################################################"
263 echo "# Installation of the found packages #"
264 echo "####################################################################"
265 echo
266 echo "Path to the database: " $RPM_DB_PATH
267 echo "Path to the packages: " $PACKAGE_PATH
268 echo "Path to the installation: " $INSTALLDIR
269 echo
270 echo "Installing the RPMs"
272 ABSROOT=`cd ${INSTALLDIR}; pwd`
273 RELOCATIONS=`rpm -qp --qf "--relocate %{PREFIXES}=${ABSROOT}%{PREFIXES} \n" $RPMLIST | sort -u | tr -d "\012"`
274 UserInstallation=\$BRAND_BASE_DIR/../UserInstallation rpm ${DEBIAN_FLAGS} --nodeps $RPMCMD --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST
277 # Create a link into the users home directory
280 if [ "$LINK" = "yes" ]
281 then
282 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"' {} \;
285 if [ "$UPDATE" = "yes" -a ! -f $INSTALLDIR/program/bootstraprc ]
286 then
287 echo
288 echo "Update failed due to a bug in RPM, uninstalling .."
289 rpm ${DEBIAN_FLAGS} --erase -v --nodeps --dbpath $RPM_DB_PATH `rpm --query --queryformat "%{NAME} " --package $RPMLIST --dbpath $RPM_DB_PATH`
290 echo
291 echo "Now re-installing new packages .."
292 echo
293 rpm ${DEBIAN_FLAGS} --install --nodeps --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST
294 echo
297 # patch the "bootstraprc" to create a self-containing installation
298 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"' {} \;
300 # if an unpack directory exists, it can be removed now
301 if [ ! -z "$UNPACKDIR" ]
302 then
303 rm $UNPACKDIR/*.rpm
304 rmdir $UNPACKDIR
305 echo "Removed temporary directory $UNPACKDIR"
308 echo
309 echo "Installation done ..."
311 exit 0