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