Update ooo320-m1
[ooovba.git] / setup_native / scripts / install_linux.sh
blob955a185ace757f026ff35913e135ad3d32b3c2ae
1 #!/bin/bash
3 ADD="no"
4 LINK="no"
5 UPDATE="ask"
6 UNPACKDIR=""
7 USAGE="Usage: $0 [-a,--add] [-l,--link] [-U,--update] [-h,--help] <rpm-source-dir> <office-installation-dir>"
9 help()
11 echo
12 echo "User Mode Installation script for developer and knowledgeable early access tester"
13 echo
14 echo "This installation method is not intended for use in a production environment!"
15 echo "Using this script is unsupported and completely at your own risk"
16 echo
17 echo "Usage:" $0 [-lU] "<rpm-source-dir> <office-installation-dir>"
18 echo " <rpm-source-dir>: directory *only* containing the Linux rpm packages to be installed"
19 echo " or language pack shell script containing the rpm packages"
20 echo " <office-installation-dir>: directory to where the office will get installed into"
21 echo
22 echo "Optional Parameter:"
23 echo " -a,--add: add to an existing <office-installation-dir>"
24 echo " -l,--link: create a link \"soffice\" in $HOME"
25 echo " -U,--update: update without asking"
26 echo " -h,--help: output this help"
27 echo
30 try_to_unpack_languagepack_file()
32 FILENAME=$PACKAGE_PATH
34 # Checking, if $FILENAME is a language pack.
35 # String "language package" has to exist in the shell script file.
36 # If this is no language pack, the installation is not supported
38 SEARCHSTRING=`head --lines=10 $FILENAME | grep "language package"`
40 if [ ! -z "$SEARCHSTRING" ]
41 then
42 echo "First parameter $FILENAME is a language pack";
43 else
44 printf "\nERROR: First parameter $FILENAME is a file, but no language pack shell script.\n"
45 echo $USAGE
46 exit 2
49 echo "Unpacking shell script $FILENAME"
50 TAILLINE=`head --lines=20 $FILENAME | sed --quiet 's/linenum=//p'`
52 UNPACKDIR=/var/tmp/install_$$
53 mkdir $UNPACKDIR
54 # UNPACKDIR=`mktemp -d`
55 tail -n +$TAILLINE $FILENAME | gunzip | (cd $UNPACKDIR; tar xvf -)
57 # Setting the new package path, in which the packages exist
58 PACKAGE_PATH=$UNPACKDIR
60 # Setting variable UPDATE, because an Office installation has to exist, if a language pack shall be installed
61 UPDATE="yes"
65 # this script is for userland not for root
68 if [ $UID -eq 0 ]
69 then
70 printf "\nThis script is for installation without administrative rights only\nPlease use rpm to install as root\n"
71 help
72 exit 2
75 set -- `getopt -u -o 'alhU' -l 'add,link,help,update' -- $*`
77 if [ $? != 0 ]
78 then
79 echo $USAGE
80 exit 2
83 for i in $*
85 case $i in
86 -a|--add) ADD="yes"; shift;;
87 -h|--help) help; exit 0;;
88 -l|--link) LINK="yes"; shift;;
89 -U|--update) UPDATE="yes"; shift;;
90 --) shift; break;;
91 esac
92 done
94 if [ $# != 2 ]
95 then
96 echo $USAGE
97 exit 2
100 PACKAGE_PATH=$1
103 # If the first parameter is a shell script (download installation set), the packages have to
104 # be unpacked into temp directory
107 if [ -f "$PACKAGE_PATH" ]
108 then
109 try_to_unpack_languagepack_file
113 # Check and get the list of packages to install
116 RPMLIST=`find $PACKAGE_PATH -maxdepth 2 -type f -name "*.rpm" ! -name "*-menus-*" ! -name "*-desktop-integration-*" ! -name "jre*" ! -name "*-userland-*" -print`
118 if [ -z "$RPMLIST" ]
119 then
120 printf "\n$0: No packages found in $PACKAGE_PATH\n"
121 exit 2
125 # Determine whether this should be an update or a fresh install
128 INSTALLDIR=$2
129 RPM_DB_PATH=${INSTALLDIR}/var/lib/rpm
131 # Check for versionrc
132 if [ -f ${INSTALLDIR}/program/versionrc ]; then VERSIONRC=versionrc; fi
134 if [ "$UPDATE" = "ask" ]
135 then
136 PRODUCT=`sed --silent -e "
137 /^buildid=/ {
138 s/buildid=\(.*\)/ [\1]/
141 /^ProductKey=/ {
142 s/ProductKey=//
145 }" ${INSTALLDIR}/program/${VERSIONRC:-bootstraprc} 2>/dev/null | tr -d "\012"`
147 if [ ! -z "$PRODUCT" ]
148 then
149 echo
150 echo "Found an installation of $PRODUCT in $INSTALLDIR"
151 echo
152 while [ "$UPDATE" != "yes" ]
154 read -a UPDATE -p "Do you want to update this installation (yes/no)? "
155 if [ "$UPDATE" = "no" ]
156 then
157 exit 2
159 done
160 elif [ -d $RPM_DB_PATH -a "$ADD" = "no" ]
161 then
162 echo
163 echo "The following packages are already installed in $INSTALLDIR"
164 echo
165 rpm --dbpath `cd $RPM_DB_PATH; pwd` --query --all
166 echo
167 while [ "$UPDATE" != "yes" ]
169 read -a UPDATE -p "Do you want to continue with this installation (yes/no)? "
170 if [ "$UPDATE" = "no" ]
171 then
172 exit 2
174 done
175 else
176 UPDATE="no"
181 # Check/Create installation directory
184 if [ "$UPDATE" = "yes" ]
185 then
186 # restore original bootstraprc
187 mv -f ${INSTALLDIR}/program/bootstraprc.orig ${INSTALLDIR}/program/bootstraprc 2>/dev/null
189 # the RPM_DB_PATH must be absolute
190 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then
191 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd`
194 # we should use --freshen for updates to not add languages with patches, but this will break
195 # language packs, so leave it for now ..
196 # RPMCMD="--freshen"
197 RPMCMD="--upgrade"
198 else
199 rmdir ${INSTALLDIR} 2>/dev/null
201 if [ -d ${INSTALLDIR} -a "$ADD" = "no" ]
202 then
203 printf "\n$0: ${INSTALLDIR} exists and is not empty.\n"
204 exit 2
207 mkdir -p $RPM_DB_PATH || exit 2
208 # XXX why ? XXX
209 chmod 700 $RPM_DB_PATH
211 # the RPM_DB_PATH must be absolute
212 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then
213 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd`
216 # Creating RPM database and initializing
217 if [ "$ADD" = "no" ]; then
218 rpm --initdb --dbpath $RPM_DB_PATH
221 # Default install command
222 RPMCMD="--install"
225 # populate the private rpm database with the dependencies needed
226 FAKEDBRPM=/tmp/fake-db-1.0-$$.noarch.rpm
227 linenum=???
228 tail -n +$linenum $0 > $FAKEDBRPM
230 rpm --upgrade --ignoresize --dbpath $RPM_DB_PATH $FAKEDBRPM
232 rm -f $FAKEDBRPM
234 echo "Packages found:"
235 for i in $RPMLIST ; do
236 echo `basename $i`
237 done
240 # Perform the installation
243 echo
244 echo "####################################################################"
245 echo "# Installation of the found packages #"
246 echo "####################################################################"
247 echo
248 echo "Path to the database: " $RPM_DB_PATH
249 echo "Path to the packages: " $PACKAGE_PATH
250 echo "Path to the installation: " $INSTALLDIR
251 echo
252 echo "Installing the RPMs"
254 ABSROOT=`cd ${INSTALLDIR}; pwd`
255 RELOCATIONS=`rpm -qp --qf "--relocate %{PREFIXES}=${ABSROOT}%{PREFIXES} \n" $RPMLIST | sort -u | tr -d "\012"`
256 UserInstallation=\$BRAND_BASE_DIR/../UserInstallation rpm $RPMCMD --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST
259 # Create a link into the users home directory
262 if [ "$LINK" = "yes" ]
263 then
264 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"' {} \;
267 if [ "$UPDATE" = "yes" -a ! -f $INSTALLDIR/program/bootstraprc ]
268 then
269 echo
270 echo "Update failed due to a bug in RPM, uninstalling .."
271 rpm --erase -v --nodeps --dbpath $RPM_DB_PATH `rpm --query --queryformat "%{NAME} " --package $RPMLIST --dbpath $RPM_DB_PATH`
272 echo
273 echo "Now re-installing new packages .."
274 echo
275 rpm --install --nodeps --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST
276 echo
279 # patch the "bootstraprc" to create a self-containing installation
280 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"' {} \;
282 # if an unpack directory exists, it can be removed now
283 if [ ! -z "$UNPACKDIR" ]
284 then
285 rm $UNPACKDIR/*.rpm
286 rmdir $UNPACKDIR
287 echo "Removed temporary directory $UNPACKDIR"
290 echo
291 echo "Installation done ..."
293 exit 0