]> Creatis software - creaToolsTools.git/blobdiff - Linux/installscript
redmine feature # 1708
[creaToolsTools.git] / Linux / installscript
diff --git a/Linux/installscript b/Linux/installscript
new file mode 100755 (executable)
index 0000000..b825124
--- /dev/null
@@ -0,0 +1,460 @@
+#!/bin/bash -e
+
+#########################################################################
+############     Local Functions  #######################################
+#########################################################################
+
+##########################################
+# check that $1 is one of $2, $3, ...
+function checkVal  {
+    local val=$1
+    shift
+    for x in $* ; do
+        if [ "$val" == "$x" ] ; then
+            echo "true"
+            return
+        fi
+    done
+    echo "false"
+}
+
+###########################################
+function bigDisplay {
+    echo " ================================================================================================"
+    echo " ================================================================================================"
+    echo " ======= $1"                                       
+    echo " ================================================================================================"
+    echo " ================================================================================================"
+}
+
+###########################################
+function checkDistrib {
+    local OS=$1
+
+    if [ "`checkVal $OS MacOS Fedora Ubuntu Mandriva`" == "false" ] ; then
+        echo "Operating System not supported: $OS"
+        echo "Currently supported system: Fedora Ubuntu MacOS"
+        exit 1
+    fi
+}
+
+###########################################
+function getDistrib {
+    local OS=`uname`
+
+      if [ "$OS" == Darwin ] ; then OS=MacOS;
+    elif [ "$OS" == Linux  ] ; then OS=`awk 'NR==1{print $1}' /etc/issue`
+    else OS=""
+    fi
+
+#    checkDistrib $OS
+
+    echo $OS
+}
+
+###########################################
+function getncore {
+    if [ `uname` == Darwin ] ; then # MacOS
+        system_profiler | grep Processor | awk '$1=="Number" {print $4}'
+    else
+        cat /proc/cpuinfo | grep processor | wc -l
+    fi
+}
+
+###########################################
+function getbashrc {
+    if [ ! -f $HOME/.bashrc ] ; then
+        touch $HOME/.bashrc
+    fi
+    echo $HOME/.bashrc
+
+
+#    # Do it, while we are under user, not under root! # JPR
+#    if [ -f $HOME/.bashrc ] ; then
+#        echo $HOME/.bashrc
+#    else
+#        if [ -f $HOME/.profile ] ; then
+#            echo $HOME/.profile
+#        else
+#            echo "=============== BIG TROUBLE : neither $HOME/.bashrc nor $HOME/.profile file found" > /dev/stderr
+#            echo "=============== You'd better abort the program and (try to) fix the issue" > /dec/stderr
+#            read a # just to let the user time enough to read the message...
+#        fi
+#    fi
+}
+
+
+###########################################
+function printconfig {
+
+    echo
+    echo "Current Configuration:"
+    echo "  Operating System                           : $OperatingSystem"
+    echo "  Number of Cores                            : $corenumber"  
+    echo "  Name of the Generation Directory           : $generationdir"
+    echo "  Install Prefix for Third Party Libraries   : $installPrefixThird"  
+    echo "  Install Prefix for CreaTools               : $installPrefix"
+    echo "  Boolean for Doc Generation                 : $docgeneration"
+    echo "  Where do you want to get source files from : $sourcesFrom"
+    if [ $sourcesFrom = CVS ] ; then
+    echo "  CVS User Name                              : $cvsUserName"
+    fi
+    echo "  Login User Name                            : $loginUserName"
+    echo "  Login Group Name                           : $loginGroupName"
+    echo "  Build type                                 : $buildType"          
+    echo "  Gdcm version                               : $gdcmVersion"
+    echo "  ITK version                                : $ITKVersion"
+    echo
+
+}
+
+
+
+##################################################################################################
+##################################################################################################
+##################################################################################################
+##################################################################################################
+##################################################################################################
+##################################################################################################
+
+configureFile="scripts/CreaTools-configure.sh"
+
+
+# default configuration parameters
+OperatingSystem=`getDistrib`
+corenumber=`getncore`
+generationdir=$HOME/CreatoolsGenerationDir
+installPrefixThird=
+installPrefix=
+docgeneration=OFF
+sourcesFrom=HTML
+
+cvsUserName=
+loginUserName=$USER
+loginGroupName=$GROUP
+buildType=RelWithDebug
+gdcmVersion=GDCM1
+ITKVersion=ITK3
+export ETC_BASHRC=`getbashrc`
+
+
+
+
+
+function usage {
+    echo "menu.sh [options] command" 
+    echo "creatools configure/compile/install script" 
+    echo "" 
+    echo "" 
+    echo "OPTIONS ARE USE FOR CONFIGURATION ONLY: THEY WILL BE IGNORED IF <COMMAND> IS NOT \"CONFIG\" OR \"ALL\"" 
+    echo "" 
+    echo "" 
+    echo "    command:" 
+    echo "         all               : configure / compile / install" 
+    echo "         "                 
+    echo "         config            : set the configuration parameters only" 
+    echo "         "                 
+    echo "         3rd               : Get, Compile, Install all 3rd party library "
+    echo "         3rd-base          : Install basic tools (cmake, doxygen...)"
+    echo "         3rd-vtk           : Get, Compile, Install vtk"
+    echo "         3rd-itk           : Get, Compile, Install itk"
+    echo "         3rd-gdcm          : Get, Compile, Install gdcm"
+    echo "         3rd-wx            : Get, Compile, Install wx widget (for Mac Users)"
+    echo "   "
+    echo "         creatools         : Get Compile and Install the CreaTools"
+    echo "         creatools-get     : Get the CreaTools"
+    echo "         creatools-cmp     : Compile the CreaTools"
+    echo "         creatools-install : Install the CreaTools"
+    echo "   "
+    echo "         uninstall         : uninstall the creatools"
+    echo "   "
+    echo "         printconfig       : print the configuration" 
+    echo "         help              : print help"
+    echo "         env               : print some environnement variables"
+    echo "   "
+    echo "   "
+    echo "   "
+    echo "   "
+    echo "    configure options: !!!!! IGNORED IF COMMAND IS NOT CONFIG OR ALL !!!!!!" 
+    echo "        -os <os>              : operating system distribution (default $OperatingSystem)"
+    echo "        -ncore <n>            : number of core to use (default $corenumber)"
+    echo "        -gdir <dir>           : generation directory (default $generationdir)"
+    echo "        -instprefix <dir>     : creatools install prefix" 
+    echo "        -instprefix3 <dir>    : 3rd party library install prefix" 
+    echo "        -cvs <cvsusername>    : get creatools from cvs (CREATIS user only)"
+    echo "        -build                : build type Release, RelWithDebug or Debug (default RelWithDebug)"
+    echo ""
+    echo "     experimental configure options (use at your own risk!!):"
+    echo "        -gdcm2         : use GDCM2 "
+    echo "        -doc           : generate documentation"
+    echo "        -itk4          : use ITK4"
+    echo "" 
+    exit 1
+}
+
+##################################################
+# parse command line
+while [ $# -ge 1 ] ; do
+    case $1 in
+        -os)                OperatingSystem=$2;                        shift 2;;
+        -ncore)             corenumber=$2;                             shift 2;;                     
+        -gdir)              generationdir=$2;                          shift 2;;                     
+        -instprefix)        installPrefix=$2;                          shift 2;;
+        -instprefix3)       installPrefixThird=$2;                     shift 2;;
+        -doc)               docgeneration=ON;                          shift 1;;
+        -cvs)               sourcesFrom=CVS; cvsUserName=$2;           shift 2;;
+        -gdcm2)             gdcmVersion=GDCM2;                         shift 1;;
+        -itk4)              ITKVersion=ITK4;                           shift 1;;
+        -build)             buildType=$2;                              shift 2;;
+        *) break;;
+    esac
+done
+
+if [ $# -le 0 ] ; then usage; fi
+
+command=$1
+
+# check that command is valid
+if [ `checkVal $command all config 3rd 3rd-base 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx creatools creatools-get creatools-cmp creatools-install uninstall printconfig help env` == "false" ] ; then
+    echo "Unrecognized command: $command"
+    echo ""
+    usage
+fi
+
+
+############################## use existing configuration if command is not config or all
+if [ `checkVal $command config all` == false ] ; then
+    if [ ! -f $configureFile ] ; then
+        echo "scripts/CreaTools-configure.sh does not exists"
+        echo "please run the scripts with command \"config\" or \"all\""
+        exit
+    fi
+    source $configureFile
+    if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
+        echo WARNING
+        echo "the curently used Third Party libraries are NOT in $installPrefixThird but ... in :"
+        grep "installPrefixThird=" $ETC_BASHRC
+        echo "VTK_DIR  : " $VTK_DIR
+        echo "ITK_DIR  : " $ITK_DIR
+        echo "GDCM_DIR : " $GDCM_DIR
+        echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
+    
+#        exit
+    fi
+    
+fi
+
+##################################################################################
+############################ check configuration parameters
+# check distrib
+checkDistrib $OperatingSystem
+
+# complete default install prefix
+if [ -z "$installPrefix" ]      ; then installPrefix=$generationdir/creatools_install; fi
+if [ -z "$installPrefixThird" ] ; then installPrefixThird=$generationdir/thirdparty_install; fi
+
+# check build type
+if [ `checkVal $buildType Release Debug RelWithDebug` == "false" ] ; then
+    echo "Unsupported build type: $buildType"
+    echo "Please use one of: Release Debug RelWithDebug"
+    exit 1
+fi
+
+
+##################################################################################
+############################  write configuration file
+if [ `checkVal $command config all` == true ] ; then
+    echo "#!/bin/bash"                            >  $configureFile
+    echo                                          >> $configureFile
+    echo "#File generated by 'menu.sh'"           >> $configureFile
+    echo "#DO NOT edit !"                         >> $configureFile
+    echo "#(except if you *do* know what you do)" >> $configureFile
+    echo                                          >> $configureFile
+    echo "OperatingSystem=$OperatingSystem"       >> $configureFile
+    echo "corenumber=$corenumber"                 >> $configureFile   
+    echo "generationdir=$generationdir"           >> $configureFile
+    echo "installPrefix=$installPrefix"           >> $configureFile
+    echo "installPrefixThird=$installPrefixThird" >> $configureFile
+    echo "docgeneration=$docgeneration"           >> $configureFile
+    echo "sourcesFrom=$sourcesFrom"               >> $configureFile
+    echo "cvsUserName=$cvsUserName"               >> $configureFile 
+    echo "loginUserName=$loginUserName"           >> $configureFile
+    echo "loginGroupName=$loginGroupName"         >> $configureFile
+    echo "buildType=$buildType"                   >> $configureFile
+    echo "gdcmVersion=$gdcmVersion"               >> $configureFile
+    echo "ITKVersion=$ITKVersion"                 >> $configureFile
+    echo "ETC_BASHRC=$ETC_BASHRC"                 >> $configureFile
+fi
+
+
+
+################################### print current configuration
+printconfig
+
+
+##################################################################################
+##################################################################################
+############   Process commands
+##################################################################################
+##################################################################################
+
+
+################################################################################## config printconfig
+# config or printconfig : already done
+if [ `checkVal $command config printconfig` == true ] ; then
+    exit
+fi
+
+
+################################################################################## 3rd library
+# install packaged dependencies as root
+if [ `checkVal $command all 3rd 3rd-base` == true ] ; then
+    bigDisplay "INSTALL PACKAGES DEPENDENCIES"
+    if [ "`whoami`" == root ] ; then
+        bash scripts/ThirdParty-install-Base-Stuff.sh
+    else 
+        # must log as root
+        echo "Please enter the root passwd to add necessary packages:"; 
+        su -c "bash scripts/ThirdParty-install-Base-Stuff.sh"   
+    fi
+    bash scripts/ThirdParty-install.sh
+fi
+
+# vtk
+if [ `checkVal $command all 3rd 3rd-vtk` == true ] ; then
+    bigDisplay "INSTALL VTK"
+    bash scripts/ThirdParty-install-VTK.sh
+fi
+
+# gdcm
+if [ `checkVal $command all 3rd 3rd-gdcm` == true ] ; then
+    bigDisplay "INSTALL $gdcmVersion"
+    bash scripts/ThirdParty-install-gdcm.sh
+fi
+
+# itk
+if [ `checkVal $command all 3rd 3rd-itk` == true ] ; then
+    bigDisplay "INSTALL $ITKVersion"
+    bash scripts/ThirdParty-install-ITK.sh
+fi
+
+## ??
+#if [ `checkVal $command all 3rd` == true ] ; then
+#    bash scripts/ThirdParty-install.sh
+#fi
+
+# Setup the user .bashrc correctly
+if [ `checkVal $command all 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
+    bigDisplay "FINALIZE 3RD PARTY LIBRARY INSTALLATION"
+    bash scripts/ThirdParty-install-Finalize.sh
+    source $ETC_BASHRC
+    if [ `checkVal $command 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
+        bigDisplay "Third Party Install Done" 
+        bigDisplay "Please copy paste the following command or open a new terminal: source ~/.bashrc" 
+    fi
+fi
+
+################################################################################## creatools
+
+# download creatools
+if [ `checkVal $command all creatools creatools-get` == true ] ; then
+    bigDisplay "DOWNLOAD CREATOOLS"
+    bash scripts/CreaTools-load.sh
+fi
+
+# compile creatools
+if [ `checkVal $command all creatools creatools-cmp` == true ] ; then
+    bigDisplay "COMPILE CREATOOLS"
+    source $ETC_BASHRC
+    bash -x scripts/CreaTools-compile.sh
+
+    # To allow (*very* aware) user to patch code, later
+    if [ ! -e $generationdir/creatools_source ] ; then
+        echo "You probabely made a mistake : "
+        echo "Directory $loginUserName $generationdir/creatools_source not found"
+        echo "Make sure you know the mistake"
+        echo "Hit any key to continue"
+        echo "Fix the mistake!"
+        read a
+    else
+        chown -R $loginUserName  $generationdir/creatools_source
+        chgrp -R $loginGroupName $generationdir/creatools_source
+    fi
+fi
+     
+#install creatools
+if [ `checkVal $command all creatools creatools-install` == true ] ; then
+    bigDisplay "INSTALL CREATOOLS"
+    source $ETC_BASHRC
+    bash scripts/CreaTools-install.sh
+    source $ETC_BASHRC
+fi
+
+################################################################################## uninstall
+
+if [ `checkVal $command uninstall` == true ] ; then
+    bigDisplay "UNINSTALL CREATOOLS"
+    bash scripts/CreaTools-uninstall.sh 
+fi
+
+################################################################################## help
+if [ `checkVal $command help` == true ] ; then
+    cat README.txt
+fi
+
+################################################################################## print env variables
+if [ `checkVal $command env` == true ] ; then
+    if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
+        echo WARNING
+        echo
+        echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
+        grep "installPrefixThird=" $ETC_BASHRC
+        echo "VTK_DIR  : " $VTK_DIR
+        echo "ITK_DIR  : " $ITK_DIR
+        echo "GDCM_DIR : " $GDCM_DIR
+        echo
+        echo "installPrefixThird ... " $installPrefixThird
+    fi
+            
+    if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
+        echo  "Third party config file : " $installPrefixThird/share/creatools_third_party_library_config.sh
+        echo  ------
+        cat $installPrefixThird/share/creatools_third_party_library_config.sh
+        echo  ------
+    fi
+     
+    echo
+     
+    if [ -f $installPrefix/share/creatools_base_library_config.sh ] ; then
+       echo  "Creatools base library config file : " $installPrefix/share/creatools_base_library_config.sh
+       echo  ------ 
+       cat $installPrefix/share/creatools_base_library_config.sh
+       echo  ------ 
+       echo
+       echo "installPrefix ... " $installPrefix
+    fi
+
+    echo  ------
+    echo "VTK_DIR  :                 " $VTK_DIR
+    echo "ITK_DIR  :                 " $ITK_DIR
+    echo "GDCM_DIR :                 " $GDCM_DIR
+    echo
+    echo "crea_DIR :                 " $crea_DIR
+    echo "BBTK_DIR :                 " $BBTK_DIR
+    echo "creaMaracasVisu_DIR :      " $creaMaracasVisu_DIR
+    echo "creaEnvironment_DIR :      " $creaEnvironment_DIR
+    echo "creaBruker_DIR :           " $creaBruker_DIR
+    echo "creaImageIO_DIR :          " $creaImageIO_DIR
+    echo "creaContours_DIR :         " $creaContours_DIR
+    echo "creaRigidRegistration_DIR :" $creaRigidRegistration_DIR
+    echo "bbtkGEditor_DIR :          " $bbtkGEditor_DIR
+    echo "creaTools_DIR :            " $creaTools_DIR
+    echo "creaMiniTools_DIR :        " $creaMiniTools_DIR
+    echo "Ido_DIR :                  " $Ido_DIR
+    echo "==================================="
+    echo
+
+fi
+
+
+