1#!/bin/bash 2# ************************************************************* 3# 4# Licensed to the Apache Software Foundation (ASF) under one 5# or more contributor license agreements. See the NOTICE file 6# distributed with this work for additional information 7# regarding copyright ownership. The ASF licenses this file 8# to you under the Apache License, Version 2.0 (the 9# "License"); you may not use this file except in compliance 10# with the License. You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, 15# software distributed under the License is distributed on an 16# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17# KIND, either express or implied. See the License for the 18# specific language governing permissions and limitations 19# under the License. 20# 21# ************************************************************* 22 23ADD="no" 24LINK="no" 25UPDATE="ask" 26UNPACKDIR="" 27USAGE="Usage: $0 [-a,--add] [-l,--link] [-U,--update] [-h,--help] <rpm-source-dir> <office-installation-dir>" 28 29help() 30{ 31 echo 32 echo "User Mode Installation script for developer and knowledgeable early access tester" 33 echo 34 echo "This installation method is not intended for use in a production environment!" 35 echo "Using this script is unsupported and completely at your own risk" 36 echo 37 echo "Usage:" $0 [-lU] "<rpm-source-dir> <office-installation-dir>" 38 echo " <rpm-source-dir>: directory *only* containing the Linux rpm packages to be installed" 39 echo " or language pack shell script containing the rpm packages" 40 echo " <office-installation-dir>: directory to where the office will get installed into" 41 echo 42 echo "Optional Parameter:" 43 echo " -a,--add: add to an existing <office-installation-dir>" 44 echo " -l,--link: create a link \"soffice\" in $HOME" 45 echo " -U,--update: update without asking" 46 echo " -h,--help: output this help" 47 echo 48} 49 50try_to_unpack_languagepack_file() 51{ 52 FILENAME=$PACKAGE_PATH 53 54 # Checking, if $FILENAME is a language pack. 55 # String "language package" has to exist in the shell script file. 56 # If this is no language pack, the installation is not supported 57 58 SEARCHSTRING=`head --lines=10 $FILENAME | grep "language package"` 59 60 if [ ! -z "$SEARCHSTRING" ] 61 then 62 echo "First parameter $FILENAME is a language pack"; 63 else 64 printf "\nERROR: First parameter $FILENAME is a file, but no language pack shell script.\n" 65 echo $USAGE 66 exit 2 67 fi 68 69 echo "Unpacking shell script $FILENAME" 70 TAILLINE=`head --lines=20 $FILENAME | sed --quiet 's/linenum=//p'` 71 72 UNPACKDIR=/var/tmp/install_$$ 73 mkdir $UNPACKDIR 74 # UNPACKDIR=`mktemp -d` 75 tail -n +$TAILLINE $FILENAME | gunzip | (cd $UNPACKDIR; tar xvf -) 76 77 # Setting the new package path, in which the packages exist 78 PACKAGE_PATH=$UNPACKDIR 79 80 # Setting variable UPDATE, because an Office installation has to exist, if a language pack shall be installed 81 UPDATE="yes" 82} 83 84# 85# this script is for userland not for root 86# 87 88if [ $UID -eq 0 ] 89then 90 printf "\nThis script is for installation without administrative rights only\nPlease use rpm to install as root\n" 91 help 92 exit 2 93fi 94 95set -- `getopt -u -o 'alhU' -l 'add,link,help,update' -- $*` 96 97if [ $? != 0 ] 98then 99 echo $USAGE 100 exit 2 101fi 102 103for i in $* 104do 105 case $i in 106 -a|--add) ADD="yes"; shift;; 107 -h|--help) help; exit 0;; 108 -l|--link) LINK="yes"; shift;; 109 -U|--update) UPDATE="yes"; shift;; 110 --) shift; break;; 111 esac 112done 113 114if [ $# != 2 ] 115then 116 echo $USAGE 117 exit 2 118fi 119 120PACKAGE_PATH=$1 121 122# 123# If the first parameter is a shell script (download installation set), the packages have to 124# be unpacked into temp directory 125# 126 127if [ -f "$PACKAGE_PATH" ] 128then 129 try_to_unpack_languagepack_file 130fi 131 132# 133# Check and get the list of packages to install 134# 135 136RPMLIST=`find $PACKAGE_PATH -maxdepth 2 -type f -name "*.rpm" ! -name "*-menus-*" ! -name "*-desktop-integration-*" ! -name "jre*" ! -name "*-userland-*" -print` 137 138if [ -z "$RPMLIST" ] 139then 140 printf "\n$0: No packages found in $PACKAGE_PATH\n" 141 exit 2 142fi 143 144# #163256# check if we are on a debian system... 145if rpm --help | grep debian >/dev/null; 146then 147 DEBIAN_FLAGS="--force-debian --nodeps" 148else 149 DEBIAN_FLAGS= 150fi 151 152# 153# Determine whether this should be an update or a fresh install 154# 155 156INSTALLDIR=$2 157RPM_DB_PATH=${INSTALLDIR}/var/lib/rpm 158 159# Check for versionrc 160if [ -f ${INSTALLDIR}/program/versionrc ]; then VERSIONRC=versionrc; fi 161 162if [ "$UPDATE" = "ask" ] 163then 164 PRODUCT=`sed --silent -e " 165/^buildid=/ { 166s/buildid=\(.*\)/ [\1]/ 167h 168} 169/^ProductKey=/ { 170s/ProductKey=// 171G 172p 173}" ${INSTALLDIR}/program/${VERSIONRC:-bootstraprc} 2>/dev/null | tr -d "\012"` 174 175 if [ ! -z "$PRODUCT" ] 176 then 177 echo 178 echo "Found an installation of $PRODUCT in $INSTALLDIR" 179 echo 180 while [ "$UPDATE" != "yes" ] 181 do 182 read -a UPDATE -p "Do you want to update this installation (yes/no)? " 183 if [ "$UPDATE" = "no" ] 184 then 185 exit 2 186 fi 187 done 188 elif [ -d $RPM_DB_PATH -a "$ADD" = "no" ] 189 then 190 echo 191 echo "The following packages are already installed in $INSTALLDIR" 192 echo 193 rpm --dbpath `cd $RPM_DB_PATH; pwd` --query --all 194 echo 195 while [ "$UPDATE" != "yes" ] 196 do 197 read -a UPDATE -p "Do you want to continue with this installation (yes/no)? " 198 if [ "$UPDATE" = "no" ] 199 then 200 exit 2 201 fi 202 done 203 else 204 UPDATE="no" 205 fi 206fi 207 208# 209# Check/Create installation directory 210# 211 212if [ "$UPDATE" = "yes" ] 213then 214 # restore original bootstraprc 215 mv -f ${INSTALLDIR}/program/bootstraprc.orig ${INSTALLDIR}/program/bootstraprc 2>/dev/null 216 217 # the RPM_DB_PATH must be absolute 218 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then 219 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd` 220 fi 221 222 # we should use --freshen for updates to not add languages with patches, but this will break 223 # language packs, so leave it for now .. 224# RPMCMD="--freshen" 225 RPMCMD="--upgrade" 226else 227 rmdir ${INSTALLDIR} 2>/dev/null 228 229 if [ -d ${INSTALLDIR} -a "$ADD" = "no" ] 230 then 231 printf "\n$0: ${INSTALLDIR} exists and is not empty.\n" 232 exit 2 233 fi 234 235 mkdir -p $RPM_DB_PATH || exit 2 236 # XXX why ? XXX 237 chmod 700 $RPM_DB_PATH 238 239 # the RPM_DB_PATH must be absolute 240 if [ ! "${RPM_DB_PATH:0:1}" = "/" ]; then 241 RPM_DB_PATH=`cd ${RPM_DB_PATH}; pwd` 242 fi 243 244 # Creating RPM database and initializing 245 if [ "$ADD" = "no" ]; then 246 rpm --initdb --dbpath $RPM_DB_PATH 247 fi 248 249 # Default install command 250 RPMCMD="--install" 251fi 252 253# populate the private rpm database with the dependencies needed 254FAKEDBRPM=/tmp/fake-db-1.0-$$.noarch.rpm 255linenum=??? 256tail -n +$linenum $0 > $FAKEDBRPM 257 258rpm ${DEBIAN_FLAGS} --upgrade --ignoresize --dbpath $RPM_DB_PATH $FAKEDBRPM 259 260rm -f $FAKEDBRPM 261 262echo "Packages found:" 263for i in $RPMLIST ; do 264 echo `basename $i` 265done 266 267# 268# Perform the installation 269# 270 271echo 272echo "####################################################################" 273echo "# Installation of the found packages #" 274echo "####################################################################" 275echo 276echo "Path to the database: " $RPM_DB_PATH 277echo "Path to the packages: " $PACKAGE_PATH 278echo "Path to the installation: " $INSTALLDIR 279echo 280echo "Installing the RPMs" 281 282ABSROOT=`cd ${INSTALLDIR}; pwd` 283RELOCATIONS=`rpm -qp --qf "--relocate %{PREFIXES}=${ABSROOT}%{PREFIXES} \n" $RPMLIST | sort -u | tr -d "\012"` 284UserInstallation=\$OOO_BASE_DIR/../UserInstallation rpm ${DEBIAN_FLAGS} $RPMCMD --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST 285 286# 287# Create a link into the users home directory 288# 289 290if [ "$LINK" = "yes" ] 291then 292 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"' {} \; 293fi 294 295if [ "$UPDATE" = "yes" -a ! -f $INSTALLDIR/program/bootstraprc ] 296then 297 echo 298 echo "Update failed due to a bug in RPM, uninstalling .." 299 rpm ${DEBIAN_FLAGS} --erase -v --nodeps --dbpath $RPM_DB_PATH `rpm --query --queryformat "%{NAME} " --package $RPMLIST --dbpath $RPM_DB_PATH` 300 echo 301 echo "Now re-installing new packages .." 302 echo 303 rpm ${DEBIAN_FLAGS} --install --nodeps --ignoresize -vh $RELOCATIONS --dbpath $RPM_DB_PATH $RPMLIST 304 echo 305fi 306 307# patch the "bootstraprc" to create a self-containing installation 308find "$INSTALLDIR" -type f -name bootstraprc -exec /bin/bash -ce 'test ! -e "$0".orig && mv "$0" "$0".orig && sed '\''s,^UserInstallation=$SYSUSERCONFIG.*,UserInstallation=$OOO_BASE_DIR/../UserInstallation,'\'' "$0".orig > "$0"' {} \; 309 310# if an unpack directory exists, it can be removed now 311if [ ! -z "$UNPACKDIR" ] 312then 313 rm $UNPACKDIR/*.rpm 314 rmdir $UNPACKDIR 315 echo "Removed temporary directory $UNPACKDIR" 316fi 317 318echo 319echo "Installation done ..." 320 321exit 0 322