User:Nnino/Scripts/LiboParaInstall.sh

From The Document Foundation Wiki
Jump to: navigation, search

Purpose

This script installs a LibreOffice install archive in parallel to an existing LibreOffice version.

Usage

  1. Change into a $PATH directory like e.g. ~/bin
  2. Copy the script into a file called e.g. LiboParaInstall.sh
  3. chmod +x LiboParaInstall.sh
  4. ./LiboParaInstall.sh -h shows how to use the script.

Script

#!/bin/bash
# Simple shell script which installs a given libreoffice version in parallel
# (see [[Installing in parallel]])
#
# This script is released under the GPL (GNU General Public License,
# see http://www.gnu.org/licenses/gpl-3.0.html)
# (C) Nino Novak 2012 (nn.libo - at - kflog.org)
# Version 0.1, tested with LibreOffice 3.5.2rc2
# Version 0.2, added ability to install master builds - 2012-08-26
# Version 0.3, adapted for LibreOffice 4.1.0 - 2013-06-26 


### GENERAL OPTIONS ###

SCRIPTNAME="`basename $0`"
DEBUG=1
DOWNLOADROOT=`pwd`


### GENERAL FUNCTIONS ###

now() {
    date "+%x %X"
}

usage() {
    echo
    echo "Usage: $SCRIPTNAME <INSTALLARCHIVE>"
    echo
    echo "   try $SCRIPTNAME -h for description"
    echo
}

showhelp() {
    echo "   General description:"
    echo
    echo "       $SCRIPTNAME is a shell script which installs LibreOffice in a separate"
    echo "       directory from where it can be started in parallel to existing"
    echo "       installations (e.g. for testing purposes)."
    echo "       LibreOffice is hereby installed without desktop integration and"
    echo "       therefore must be run from command line."
    echo
    echo "   Arguments:"
    echo
    echo "       <INSTALLARCHIVE> is the file name of the downloaded install archive."
    echo "       If you want a non-english install, please chose the langpack archive,"
    echo "       so the script can detect the desired language."
    echo
    echo "       $SCRIPTNAME can be run on any of the three install archive"
    echo "       types (i.e. _install.tar.gz, .langpack.tar.gz and .helppack.tar.gz)"
    echo "       but behaves differently depending on the type:"
    echo
    echo "       If INSTALLARCHIVE does not have a qualifyer like langpack or helppack,"
    echo "           the script will create a subdirectory of the current directory"
    echo "           named like the archive (but without the \".tar.gz\") and put "
    echo "           the program binaries into a sub-subdir named install/  "
    echo "           but then you will have to install langpack/helppack separately "
    echo "       else, if INSTALLARCHIVE is of type _langpack,"
    echo "           the script will add its contents to an existing install subdir"
    echo "           or - if no install subdir exists - create a new install subdir and"
    echo "           install two of the archives (_install & _langpack) there"
    echo "       else, if INSTALLARCHIVE is of type _helppack,"
    echo "           the script will add its contents to an existing install subdir"
    echo "           or - if no install subdir exists - create a new install subdir and"
    echo "           install all three archives (_install & _langpack & _helppack) there."
    echo
    echo "   Options:"
    echo
    echo "       -h         Show this help and exit"
    echo
    echo "   Author:"
    echo
    echo "       Nino Novak (nn.libo - at - kflog.org)"
    echo
    exit
}

abort() {
    echo "##################################################################"
    echo "$SCRIPTNAME: FATAL: Aborting! $2"
    usage
    exit $1
}


### GENERAL CHECK

[[ $# -lt  1 ]] && abort 1 "Wrong argument count!"
[[ "$1" = "-h" ]] && usage && showhelp


### SPECIAL FUNCTIONS ###

extractAndCreate()  {

    ARCHIVE=$1.tar.gz

    if [ "$TYPE" = "master" ] ; then
        DIR=`shorten $1`
        DIR=`shorten $DIR`
    else
        DIR=$1
    fi

    [[ $DEBUG ]] && echo -n "$SCRIPTNAME: checking environment ... "

    if [ -d $DIR ] ; then
        echo;
        echo -n "$SCRIPTNAME: NOTICE: Directory \"$DIR\" already exists. Continue? [y]/n? " && read CMD
        [[ "$CMD" = "n" ]]  && echo "ok, aborting..." && exit 1
    fi

    [[ -f $ARCHIVE ]] || abort 1 "File \"$ARCHIVE\" not found."

    echo "ok"

    echo -n "$SCRIPTNAME: extracting \"$ARCHIVE\" ... "

    tar -xzvf $ARCHIVE  && echo " done"

    [[ $DEBUG ]] && echo "$SCRIPTNAME: cd to \"$DIR/$PACKAGEDIR\""

# Version hat meist noch einen RC-Anhang, der kann aber erst erkannt werden,
# nachdem das Tar-Kommando abgelaufen ist. Hier sollte also erst $DIR konstruiert werden.
#    TESTVAR=$DIR/$PACKAGEDIR
#
#    while [[ ! -d $TESTVAR ]] ; do
#       echo -n "Versionsbezeichnung?" 
#       read INPUT
#
#    done       



    cd $DIR/$PACKAGEDIR || abort 2 "$SCRIPTNAME: FATAL: Aborting: could not cd to \"$DIR/$PACKAGEDIR\""

    [[ $DEBUG ]] && echo -n "$SCRIPTNAME: creating subdirectory \"install\" ... "

    mkdir install && echo "done"

    cd install

    [[ $DEBUG ]] && echo -n "$SCRIPTNAME: installing packages ..."

    if [ "$PACKAGETYPE" = "deb" ] ; then

        for i in ../*.deb ; do
            dpkg-deb -x $i . && echo -n "."
        done

    elif [ "$PACKAGETYPE" = "rpm" ] ; then

        for i in ../*.rpm; do
            rpm2cpio $i | cpio -id && echo -n "."
        done

    fi

    [[ $DEBUG ]] && echo " ... done "
}

parseFromStart() {
    MAXLEN=${#1}
    INDEX=`expr index $1 "_"`
    STRING=${1:0:((INDEX-1))}
    echo $STRING
}

shorten() {
    MAXLEN=${#1}
    INDEX=`expr index $1 "_"`
    echo ${1:INDEX:MAXLEN}
}


### MAIN ###

IDENTIFIER=${1%.tar.gz} # test string = file name without .tar.gz
TESTVAR=$IDENTIFIER
DESTINATION=$IDENTIFIER

if [ "${TESTVAR:0:12}" = "libreoffice-" ] ; then

    BUILDDATE=`parseFromStart $TESTVAR`
    TESTVAR=`shorten $TESTVAR`
    BUILDTIME=`parseFromStart $TESTVAR`
    TESTVAR=`shorten $TESTVAR`
    TYPE="master"
#     abort 1 "Master-Build! Install script does not work yet."
    BUILD=${BUILDDATE}_${BUILDTIME}_

else

    TYPE="std"
    BUILD=''

fi

SOFTWARE=`parseFromStart $TESTVAR`
TESTVAR=`shorten $TESTVAR`
VERSION=`parseFromStart $TESTVAR`
TESTVAR=`shorten $TESTVAR`
OS=`parseFromStart $TESTVAR`
TESTVAR=`shorten $TESTVAR`
ARCH=`parseFromStart $TESTVAR`
TESTVAR=`shorten $TESTVAR`
PACKAGE=`parseFromStart $TESTVAR`
TESTVAR=`shorten $TESTVAR`

if [ "${TESTVAR:0:8}" = "langpack" ] ; then
        LANG=`shorten $TESTVAR`
else 
        abort 1 "cannot guess language; please try calling me with langpack archive."
fi

echo "Build    = $BUILD"
echo "Software = $SOFTWARE"
echo "Version  = $VERSION"
echo "OS       = $OS"
echo "ARCH     = $ARCH"
echo "PACKAGE  = $PACKAGE"
echo "LANG     = $LANG"

PREFIX=${BUILD}${SOFTWARE}_${VERSION}_${OS}_${ARCH}
DIRNAME=${SOFTWARE}_${VERSION}_${OS}_${ARCH}

echo "PREFIX   = $PREFIX"
echo "DIRNAME  = $DIRNAME"

# if [ "$TYPE" = "master" ] ; then abort 1 "Master-Build! Install script does not work yet." ; fi

PACKAGETYPE=${PACKAGE##[a-z]*-}

echo "P.TYPE   = $PACKAGETYPE"

if [ "$PACKAGETYPE" = "deb" ] ; then
    PACKAGEDIR='DEBS'
elif [ "$PACKAGETYPE" = "rpm" ] ; then
    PACKAGEDIR='RPMS'
else
    abort 1 "Unknown package type: $PACKAGETYPE"
fi

echo "P.DIR    = $PACKAGEDIR"

# abort 1 "for testing ..."

extractAndCreate ${PREFIX}_${PACKAGETYPE}

INSTALLDIR=`pwd`

cd $DOWNLOADROOT

for i in langpack helppack ; do

    extractAndCreate ${PREFIX}_${PACKAGETYPE}_${i}_${LANG}
    cp -R * $INSTALLDIR/
    cd $DOWNLOADROOT

done

if [ "$TYPE" = "master" ] ; then
    LODIR="lodev${VERSION:0:3}"
else
    LODIR="libreoffice${VERSION:0:3}"
fi

BOOTSTRAPRC=$INSTALLDIR/opt/$LODIR/program/bootstraprc

echo -n "$SCRIPTNAME: saving (copying) boostraprc to bootstraprc.orig... "

cp $BOOTSTRAPRC $BOOTSTRAPRC.orig && echo "done" || abort 128 "$SCRIPTNAME: bootstraprc copy failure"

echo -n "$SCRIPTNAME: modifying bootstraprc... "

chmod +w $BOOTSTRAPRC || abort 1 "Could not chmod bootstraprc"

cat $BOOTSTRAPRC.orig | sed -e 's/$SYSUSERCONFIG.*/$ORIGIN\/../' > $BOOTSTRAPRC && echo "done"|| echo "$SCRIPTNAME: bootstraprc sed failure"

SYMLINKDIR=~/bin

        

echo "$SCRIPTNAME `now`: $SOFTWARE $VERSION $BUILD parallel installation finished"