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