#!/bin/bash # Linux SCENARI application installer & setup # Copyright (c) 2007-2010 samuel.monsarrat@kelis.fr # vMyName=`basename $0` vMyVersionMaj=1 vMyVersionMed=9 vMyVersionMin=1 vMyVersion=$vMyVersionMaj.$vMyVersionMed.$vMyVersionMin #vMyUsage="Usage: $vMyName [-n[x.y]|-s[x.y]] {scbd|scch|sccl|sckt|scmd} [-cd{u|r}fas]" vMyUsage="Usage: $vMyName [-n] {scbd|scch|sccl|sckt|scmd} [-cd{u|r}fas]" vTmpDir="/tmp/"`id -un`".scinstall" vLastScAppBinPathFile=$vTmpDir"/lastScAppBinPath.txt" vStableSigVersion="3.6" vNightlySigVersion="3.7" vSrvUrlNight="http://scenarilms.utc.fr/build$vNightlySigVersion" vSrvUrlStable="http://scenari-platform.org/projects/scenari/files" vSrvUrlSci="http://scenari-platform.org/svn/sci/trunk" vSCApp="" vScAppFullName="" vScPackList="" vCurrDir=`pwd` #=============================================================================== xInit () { vBashVers=`echo $BASH_VERSION` if [ -z "$vBashVers" ]; then echo echo "WARNING: $vMyName is a BASH script. It seems that the BASH shell is not" echo "available this system. You may run into problems." echo -n "Do you want to continue? (y|N): " read vResponse vResponse=`echo $vResponse | tr 'A-Z' 'a-z'` if [ "$vResponse" = "n" ]; then echo "Aborting installation." echo exit 1 fi fi # Check for dependencies. vMissingApps="" wget --version >> /dev/null 2>&1 if [ "$?" -ne "0" ];then vMissingApps=$vMissingApps" - wget (http://www.gnu.org/software/wget/) " fi if [ "$vMissingApps" != "" ]; then echo echo "ERROR: the folowing dependencies are not met:" echo "$vMissingApps" echo "Aborting installation." echo exit 1 fi # This script should not be run as root. if [ `id -u` -eq "0" ];then echo echo "WARNING! you are trying to run $vMyName with root privileges." echo "This is not currenty supported. Please run $vMyName as a normal user." echo echo "$vMyName -h for more details" exit 1 fi # Look for a newer version of sci. xCheckSciUpdate } #=============================================================================== xHelp () { echo # echo "--------------------------------------------------------------------------------" echo "$vMyName downloads and installs requested SCENARI applications from the" echo "scenari-platform website." echo "$vMyUsage" echo echo "By default $vMyName will attempt to install applications system-wide and as such" echo "requires the current user to be a sudo user that has root access" echo "to /opt and /usr. Should this not be the case, either use the -u option to" echo "perform a local user installation or the -r option to perform a system-wide" echo "installation using the su command requiring the root password." echo echo "OPTIONS:" echo "Installation type (optional):" echo " -n Nightly build: $vMyName will install the latest nightly build of the" echo " application that you request. If this switch is not present $vMyName" echo " will install the latest stable version." echo echo "Application name (required):" echo " scbd Download and install SCENARIbuilder, you should at least install the" echo " modeling builderpack by adding the -m option (see below)." echo " scch Download and install SCENARIchain." echo " sccl Download and install SCENARIclient." echo " sckt Download SCENARIkit to the current directory." echo " scmd Download and install modeling builderpacks into an existing" echo " SCENARIbuilder installation. you must provide at least one of the" echo " folowing options: -m, -a, -s (ADVANCED)." echo echo "Installation options (optional)" echo " -c Clean download and install: delete any previously attempted downloads" echo " -d Download only, do not install." echo " before starting the download & install process." echo " -f 'force' mode: the installer does not interact with the user, all" echo " default choices are used. If the application is already installed" echo " it will be replaced. This is basically equivalent to pressing" echo " return for each question the the installer normally asks the user." echo " -u Local user installation: $vMyName will install the application in the" echo " current user's home directory." echo " -r System-wide installation using the su command requiring the root" echo " password. This option should be used if you are not a sudo user but" echo " have root access though the su command." echo echo "SCENARIbuilder specific options (optional)" echo " -m Download and install the modeling extension builderpack" echo " -a Download and install the modeling assessment extension builderpack" echo " -s Download and install the modeling sound extension builderpack" echo echo "NOTES:" echo "Even when a system-wide installation is required $vMyName must be run as a" echo "normal user. This is because although SCENARI binaries can be installed for all" echo "users, SCENARIbuilder builderpacks MUST be installed in the user's profile." echo echo "Copyright (c) 2007-2010 samuel.monsarrat@kelis.fr" } #=============================================================================== xCheckSciUpdate () { echo -n "Looking for updates for $vMyName..." mkdir $vTmpDir >> /dev/null 2>&1 wget -q --no-cache -O $vTmpDir/latestsciversion.txt $vSrvUrlSci/latestversion.txt . $vTmpDir/latestsciversion.txt rm -f $vTmpDir/latestsciversion.txt if [ -z "$vSciLatestVersionMaj" ];then echo echo "WARNING: cannot connect to sci site to search for updates" else if [ "$vSciLatestVersionMaj" -gt "$vMyVersionMaj" ];then xSciUpdateAvailable elif [ "$vSciLatestVersionMaj" -eq "$vMyVersionMaj" ];then if [ "$vSciLatestVersionMed" -gt "$vMyVersionMed" ];then xSciUpdateAvailable elif [ "$vSciLatestVersionMed" -eq "$vMyVersionMed" ];then if [ "$vSciLatestVersionMin" -gt "$vMyVersionMin" ];then xSciUpdateAvailable "warnOnly" fi fi fi echo "OK" fi } xSciUpdateAvailable () { echo echo "WARNING: a new version (v$vSciLatestVersionMaj.$vSciLatestVersionMed.$vSciLatestVersionMin) of $vMyName exists and is available" echo "at $vSrvUrlSci/sci.sh" if [ "$1" = "warnOnly" ];then echo "You should download an use this version instead." echo -n "Do you still want to continue with the current version? [y/N]: " read vUserRes echo vUserRes=`echo $vUserRes | tr 'A-Z' 'a-z'` if [ "$vUserRes" != "y" ];then echo exit 1 fi else echo "You must download an use this version instead." echo exit 1 fi } #=============================================================================== xScInst () { vAppName=$1 if [ -z "$vNightly" ];then vSrvUrl=$vSrvUrlBase/"$vAppName"/lin/latestStable/ vInstallType="Stable" else vSrvUrl=$vSrvUrlBase/"$vAppName"_lin/J-0/ vInstallType="Nightly" fi echo "$vInstallType SCENARI application installer" if [ -z "$vUserInst" ] || [ ! -z "$vSUInst" ];then echo "System-wide installation." else echo "Local user installation" fi mkdir $vTmpDir >> /dev/null 2>&1 wget -q --no-cache -O $vTmpDir/$vAppName.html $vSrvUrl if [ "$?" -ne "0" ];then echo echo "ERROR: cannot connect to the scenari-platform website." echo "Aborting installation." echo exit 1 fi vAppTgz=`grep "\"SCENARI.*tgz\"" -o $vTmpDir/$vAppName.html | grep "SCENARI.*tgz" -o` rm -f $vTmpDir/$vAppName.html echo "The latest $vInstallType $vScAppFullName package is:" echo "$vAppTgz" echo "Downloading..." wget -c --no-cache -O $vTmpDir/$vAppTgz $vSrvUrl$vAppTgz if [ "$?" -ne "0" ];then echo echo "ERROR: $vMyName was unable to finish downloading $vScAppFullName." echo "Please try again." echo "Aborting installation." echo exit 1 fi if [ -z "$vDwnLdOnly" ];then # Start install if not "download only" echo "Installing..." rm -f $vLastScAppBinPathFile >> /dev/null 2>&1 touch $vLastScAppBinPathFile rm -Rf $vTmpDir/tmp >> /dev/null 2>&1 mkdir $vTmpDir/tmp cp $vTmpDir/$vAppTgz $vTmpDir/tmp/$vAppTgz cd $vTmpDir/tmp >> /dev/null 2>&1 tar xzf $vAppTgz if [ "$?" -ne "0" ]; then echo echo "ERROR: The downloaded copy of $vScAppFullName seems corrupted." echo " Unable to open $vAppTgz." echo "Please run $vMyName with -c in order to download a fresh copy." echo exit 1 fi if [ -z "$vUserInst" ];then echo "System-wide installation (defaults to /opt)" if [ -z "$vSUInst" ];then echo "$vMyName will use the sudo command that may require your password." sudo -v >/dev/null if [ "$?" -eq "0" ]; then sudo -s ./install.sh -l$vForceMode $vLastScAppBinPathFile if [ "$?" -ne "0" ]; then echo echo "ERROR: $vScAppFullName installation failed, $vMyName aborting." echo exit 1 fi else echo echo "ERROR: Aborting installation." echo "Please run $vMyName with either:" echo " -u for a local user installation" echo " -r for a system-wide installation if you have root access." echo exit 1 fi else echo "$vMyName will use the su command that may require the root password." su -c "./install.sh -l$vForceMode $vLastScAppBinPathFile" if [ "$?" -ne "0" ]; then echo echo "ERROR: $vScAppFullName installation failed, $vMyName aborting." echo exit 1 fi fi else ./install.sh -l$vForceMode $vLastScAppBinPathFile if [ "$?" -ne "0" ]; then echo echo "ERROR: $vScAppFullName installation failed, $vMyName aborting." echo exit 1 fi fi cd $vCurrDir >> /dev/null 2>&1 rm -Rf $vTmpDir/tmp >> /dev/null 2>&1 fi echo } #=============================================================================== xScKitDwnld () { vAppName=$1 if [ -z "$vNightly" ];then vSrvUrl=$vSrvUrlBase/"$vAppName"/latestStable/ vInstallType="Stable" else vSrvUrl=$vSrvUrlBase/"$vAppName"/J-0/ vInstallType="Nightly" fi echo "$vInstallType SCENARIkit downloader" mkdir $vTmpDir >> /dev/null 2>&1 wget -q --no-cache -O $vTmpDir/scKit.html $vSrvUrl if [ "$?" -ne "0" ];then echo echo "ERROR: cannot connect to the scenari-platform website." echo "Aborting installation." echo exit 1 fi vAppTgz=`grep "\"SCENARI.*sckit\"" -o $vTmpDir/scKit.html | grep "SCENARI.*sckit" -o` rm -f $vTmpDir/scKit.html echo "The latest $vInstallType $vScAppFullName package is:" echo "$vAppTgz" echo "Downloading..." wget -c --no-cache -O $vAppTgz $vSrvUrl$vAppTgz if [ "$?" -ne "0" ];then echo echo "ERROR: $vMyName was unable to finish downloading $vScAppFullName." echo "Please try again." echo "Aborting installation." echo exit 1 fi echo } #=============================================================================== xScPackGet () { vPackName=$1 vPackExt=$2 vAppName=$3 vExeName=$4 echo if [ -f $vLastScAppBinPathFile ]; then . $vLastScAppBinPathFile fi if [ -z "$vLastScAppBinPath" ] && [ ! -z "$vExeName" ]; then vLastScAppBinPath=`which $vExeName` fi if [ ! -f "$vLastScAppBinPath" ] && [ -z "$vDwnLdOnly" ]; then echo "WARNING: $vMyName cannot find the latest installaton of $3." echo " Unable to install $vPackName." else if [ -z "$vNightly" ];then vSrvUrl=$vSrvUrlBase/"$vAppName"/extensions/"$vPackName"/latestStable/ vInstallType="Stable" else vSrvUrl=$vSrvUrlBase/"$vPackName"/J-0/ vInstallType="Nightly" fi echo "$vInstallType $vScAppFullName $vPackExt installer" mkdir $vTmpDir >> /dev/null 2>&1 wget -q --no-cache -O $vTmpDir/$vPackName.html $vSrvUrl if [ "$?" -ne "0" ];then echo echo "WARNING: cannot connect to the scenari-platform website." echo "Aborting $vPackName $vPackExt installation." else vBuilderPack=`grep "\"$vPackName.*$vPackExt\"" -o $vTmpDir/$vPackName.html | grep "$vPackName.*$vPackExt" -o` rm -f $vTmpDir/$vPackName.html echo "The latest $vInstallType $vPackName $vPackExt is:" echo "$vBuilderPack" echo "Downloading..." wget -c --no-cache -O $vTmpDir/$vBuilderPack $vSrvUrl$vBuilderPack if [ "$?" -ne "0" ];then echo echo "ERROR: $vMyName was unable to finish downloading $vPackName $vPackExt." echo "Please try again." echo "Aborting $vPackName $vPackExt installation." else vScPackList="$vScPackList::$vTmpDir/$vBuilderPack" fi fi fi } #=============================================================================== xScPackInst () { if [ ! -z "$vLastScAppBinPath" ] && [ ! -z "$vScPackList" ]; then echo -n "Installing requested packs..." cd $vTmpDir $vLastScAppBinPath -installWsppack $vScPackList vExitCode=$? if [ "$vExitCode" -ne "0" ];then echo "ERROR" echo "$vMyName was unable to install the requested packs." echo "$vScAppFullName did not run properly (error code $vExitCode)." echo "Please check the log file /tmp/$vScAppFullName_"`id -un`".log" else echo "OK" fi fi } #=============================================================================== #START echo "Linux SCENARI application installer & setup (version v$vMyVersion)" # If help wanted then just display help. if [ "$1" = "-h" ];then xHelp exit 1 fi # Run init script xInit # See how we were called. if [ "$1" = "-n" ];then vNightly="true" vSrvUrlBase=$vSrvUrlNight shift else vSrvUrlBase=$vSrvUrlStable fi vSCApp=$1 shift if echo "$1" | grep -q c ; then rm -Rf $vTmpDir >> /dev/null 2>&1 fi if echo "$1" | grep -q f ; then vForceMode="f" fi if echo "$1" | grep -q d ; then vDwnLdOnly="true" fi if echo "$1" | grep -q u ; then vUserInst="true" fi if echo "$1" | grep -q r ; then vSUInst="true" fi if [ ! -z "$vUserInst" ] && [ ! -z "$vSUInst" ];then echo echo "ERROR: You cannot use both -u and -r at the same time." echo "$vMyUsage" echo echo "$vMyName -h for more details" exit 1 fi echo # Just do it. case "$vSCApp" in scbd) if [ -z "$vNightly" ];then # Stable vScAppFullName="SCENARIbuilder$vStableSigVersion" xScInst SCENARIbuilder if echo "$1" | grep -q m ; then xScPackGet modeling builderpack SCENARIbuilder fi if echo "$1" | grep -q a ; then xScPackGet modelingAssmnt builderpack SCENARIbuilder fi if echo "$1" | grep -q s ; then xScPackGet modelingSound builderpack SCENARIbuilder fi else # Nightly vScAppFullName="SCENARIbuilder$vNightlySigVersion" xScInst SCBuilder if echo "$1" | grep -q m ; then xScPackGet modeling builderpack SCENARIbuilder$vNightlySigVersion fi if echo "$1" | grep -q a ; then xScPackGet modelingAssmnt builderpack SCENARIbuilder$vNightlySigVersion fi if echo "$1" | grep -q s ; then xScPackGet modelingSound builderpack SCENARIbuilder$vNightlySigVersion fi fi if [ -z "$vDwnLdOnly" ];then # Start install if not "download only" xScPackInst echo echo "Finished installing $vScAppFullName." else echo echo "Finished downloading $vScAppFullName to $vTmpDir." fi ;; scch) if [ -z "$vNightly" ];then # Stable vScAppFullName="SCENARIchain$vStableSigVersion" xScInst SCENARIchain else # Nightly vScAppFullName="SCENARIchain$vNightlySigVersion" xScInst SCChain fi if [ ! -z "$vDwnLdOnly" ];then echo echo "Finished downloading $vScAppFullName to $vTmpDir." fi ;; sccl) if [ -z "$vNightly" ];then # Stable vScAppFullName="SCENARIclient$vStableSigVersion" xScInst SCENARIclient else # Nightly vScAppFullName="SCENARIclient$vNightlySigVersion" xScInst SCClient fi if [ ! -z "$vDwnLdOnly" ];then echo echo "Finished downloading $vScAppFullName to $vTmpDir." fi ;; sckt) if [ -z "$vNightly" ];then # Stable vScAppFullName="SCENARIkit$vStableSigVersion" xScKitDwnld "SCENARIbuilder/sckit" else # Nightly vScAppFullName="SCENARIkit$vNightlySigVersion" xScKitDwnld SCKit fi ;; scmd) if [ -z "$vNightly" ];then # Stable vScAppFullName="SCENARIbuilder$vStableSigVersion" if echo "$1" | grep -q m ; then xScPackGet modeling builderpack SCENARIbuilder SCENARIbuilder$vStableSigVersion fi if echo "$1" | grep -q a ; then xScPackGet modelingAssmnt builderpack SCENARIbuilder SCENARIbuilder$vStableSigVersion fi if echo "$1" | grep -q s ; then xScPackGet modelingSound builderpack SCENARIbuilder SCENARIbuilder$vStableSigVersion fi else # Nightly vScAppFullName="SCENARIbuilder$vNightlySigVersion" if echo "$1" | grep -q m ; then xScPackGet modeling builderpack SCENARIbuilder$vNightlySigVersion SCENARIbuilder$vNightlySigVersion fi if echo "$1" | grep -q a ; then xScPackGet modelingAssmnt builderpack SCENARIbuilder$vNightlySigVersion SCENARIbuilder$vNightlySigVersion fi if echo "$1" | grep -q s ; then xScPackGet modelingSound builderpack SCENARIbuilder$vNightlySigVersion SCENARIbuilder$vNightlySigVersion fi fi if [ -z "$vDwnLdOnly" ];then # Start install if not "download only" xScPackInst echo echo "Finished installing $vScAppFullName." else echo echo "Finished downloading $vScAppFullName to $vTmpDir." fi ;; *) echo "ERROR: Missing SCENARI application name (scbd|scch|sccl|sckt|scmd)" echo "$vMyUsage" echo echo "$vMyName -h for more details" exit 1 esac