]> Creatis software - creaToolsTools.git/blob - Linux/installscript
Added a new installation mode : via git repository without authentification (option...
[creaToolsTools.git] / Linux / installscript
1 # ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
4 #                        pour la Santé)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 #
7 #  This software is governed by the CeCILL-B license under French law and 
8 #  abiding by the rules of distribution of free software. You can  use, 
9 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
10 #  license as circulated by CEA, CNRS and INRIA at the following URL 
11 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
12 #  or in the file LICENSE.txt.
13 #
14 #  As a counterpart to the access to the source code and  rights to copy,
15 #  modify and redistribute granted by the license, users are provided only
16 #  with a limited warranty  and the software's author,  the holder of the
17 #  economic rights,  and the successive licensors  have only  limited
18 #  liability. 
19 #
20 #  The fact that you are presently reading this means that you have had
21 #  knowledge of the CeCILL-B license and that you accept its terms.
22 # ------------------------------------------------------------------------  
23
24 #!/bin/bash -e
25
26 #########################################################################
27 ############     Local Functions  #######################################
28 #########################################################################
29
30 ##########################################
31 # check that $1 is one of $2, $3, ...
32 function checkVal  {
33     local val=$1
34     shift
35     for x in $* ; do
36         if [ "$val" == "$x" ] ; then
37             echo "true"
38             return
39         fi
40     done
41     echo "false"
42 }
43
44 ###########################################
45 function bigDisplay {
46     echo " ================================================================================================"
47     echo " ================================================================================================"
48     echo " ======= $1"                                       
49     echo " ================================================================================================"
50     echo " ================================================================================================"
51 }
52
53 ###########################################
54 function checkDistrib {
55     local OS=$1
56
57     if [ "`checkVal $OS MacOS Fedora Ubuntu Mandriva`" == "false" ] ; then
58         echo "Operating System not supported: $OS"
59         echo "Currently supported system: Fedora Ubuntu MacOS"
60         exit 1
61     fi
62 }
63
64 ###########################################
65 function getDistrib {
66     local OS=`uname`
67
68       if [ "$OS" == Darwin ] ; then OS=MacOS;
69     elif [ "$OS" == Linux  ] ; then OS=`awk 'NR==1{print $1}' /etc/issue`
70     else OS=""
71     fi
72
73 #    checkDistrib $OS
74
75     echo $OS
76 }
77
78 ###########################################
79 function getncore {
80     if [ `uname` == Darwin ] ; then # MacOS
81         system_profiler | grep Processor | awk '$1=="Number" {print $4}'
82     else
83         cat /proc/cpuinfo | grep processor | wc -l
84     fi
85 }
86
87 ###########################################
88 function getbashrc {
89     if [ ! -f $HOME/.bashrc ] ; then
90         touch $HOME/.bashrc
91     fi
92     echo $HOME/.bashrc
93
94
95 #    # Do it, while we are under user, not under root! # JPR
96 #    if [ -f $HOME/.bashrc ] ; then
97 #        echo $HOME/.bashrc
98 #    else
99 #        if [ -f $HOME/.profile ] ; then
100 #            echo $HOME/.profile
101 #        else
102 #            echo "=============== BIG TROUBLE : neither $HOME/.bashrc nor $HOME/.profile file found" > /dev/stderr
103 #            echo "=============== You'd better abort the program and (try to) fix the issue" > /dec/stderr
104 #            read a # just to let the user time enough to read the message...
105 #        fi
106 #    fi
107 }
108
109
110 ###########################################
111 function printconfig {
112
113     echo
114     echo "Current Configuration:"
115     echo "  Operating System                           : $OperatingSystem"
116     echo "  Number of Cores                            : $corenumber"   
117     echo "  Name of the Generation Directory           : $generationdir"
118     echo "  Install Prefix for Third Party Libraries   : $installPrefixThird"   
119     echo "  Install Prefix for CreaTools               : $installPrefix"
120     echo "  Boolean for Doc Generation                 : $docgeneration"
121     echo "  Where do you want to get source files from : $sourcesFrom"
122     echo "  Login User Name                            : $loginUserName"
123     echo "  Login Group Name                           : $loginGroupName"
124     echo "  Build type                                 : $buildType"          
125     echo "  Gdcm version                               : $gdcmVersion"
126     echo "  ITK version                                : $ITKVersion"
127     echo
128
129 }
130
131
132
133 ##################################################################################################
134 ##################################################################################################
135 ##################################################################################################
136 ##################################################################################################
137 ##################################################################################################
138 ##################################################################################################
139
140 configureFile="scripts/CreaTools-configure.sh"
141
142
143 # default configuration parameters
144 OperatingSystem=`getDistrib`
145 corenumber=`getncore`
146 generationdir=$HOME/CreatoolsGenerationDir
147 installPrefixThird=
148 installPrefix=
149 docgeneration=OFF
150 sourcesFrom=HTML
151
152 loginUserName=$USER
153 loginGroupName=`groups | awk '{print $1}'`
154 buildType=RelWithDebug
155 gdcmVersion=GDCM1
156 ITKVersion=ITK3
157 export ETC_BASHRC=`getbashrc`
158
159
160
161
162
163 function usage {
164     echo "installscript [options] command" 
165     echo "creatools configure/compile/install script" 
166     echo "" 
167     echo "" 
168     echo "OPTIONS ARE USE FOR CONFIGURATION ONLY: THEY WILL BE IGNORED IF <COMMAND> IS NOT \"CONFIG\" OR \"ALL\"" 
169     echo "" 
170     echo "" 
171     echo "    command:" 
172     echo "" 
173     echo "    as a normal user:" 
174     echo "         config            : set the configuration parameters only" 
175     echo "         "                 
176     echo "    as root:" 
177     echo "         3rd               : Get, Compile, Install all 3rd party library "
178     echo "         3rd-base          : Install basic tools (cmake, doxygen...)"
179     echo "         3rd-vtk           : Get, Compile, Install vtk"
180     echo "         3rd-itk           : Get, Compile, Install itk"
181     echo "         3rd-gdcm          : Get, Compile, Install gdcm"
182     echo "         3rd-wx            : Get, Compile, Install wx widget (for Mac Users)"
183     echo "   "
184     echo "    as a normal user:" 
185     echo "         creatools         : Get Compile and Install the CreaTools"
186     echo "         creatools-get     : Get the CreaTools"
187     echo "         creatools-cmp     : Compile the CreaTools"
188     echo "         creatools-install : Install the CreaTools"
189     echo "   "
190     echo "         uninstall         : uninstall the creatools"
191     echo "   "
192     echo "         printconfig       : print the configuration" 
193     echo "         help              : print help"
194     echo "         env               : print some environnement variables"
195     echo "" 
196     echo "         all               : configure / compile / install" 
197     echo "         "                 
198     echo "   "
199     echo "   "
200     echo "   "
201     echo "   "
202     echo "    configure options: !!!!! IGNORED IF COMMAND IS NOT CONFIG OR ALL !!!!!!" 
203     echo "        -os <os>              : operating system distribution (default $OperatingSystem)"
204     echo "        -ncore <n>            : number of core to use (default $corenumber)"
205     echo "        -gdir <dir>           : generation directory (default $generationdir)"
206     echo "        -instprefix <dir>     : creatools install prefix" 
207     echo "        -instprefix3 <dir>    : 3rd party library install prefix" 
208     echo "        -git                  : get creatools from git (CREATIS user only)"
209     echo "        -git-read-only        : get creatools from git (anonymously, no write access)"
210     echo "        -build                : build type Release, RelWithDebug or Debug (default RelWithDebug)"
211     echo ""
212     echo "     experimental configure options (use at your own risk!!):"
213     echo "        -gdcm2         : use GDCM2 "
214     echo "        -doc           : generate documentation"
215     echo "        -itk4          : use ITK4"
216     echo "" 
217     exit 1
218 }
219
220 ##################################################
221 # parse command line
222 while [ $# -ge 1 ] ; do
223     case $1 in
224         -os)                OperatingSystem=$2;                        shift 2;;
225         -ncore)             corenumber=$2;                             shift 2;;                     
226         -gdir)              generationdir=$2;                          shift 2;;                     
227         -instprefix)        installPrefix=$2;                          shift 2;;
228         -instprefix3)       installPrefixThird=$2;                     shift 2;;
229         -doc)               docgeneration=ON;                          shift 1;;
230         -git)               sourcesFrom=GIT;                           shift 1;;
231         -git-read-only)     sourcesFrom=GIT-READ-ONLY;
232 shift 1;;
233         -gdcm2)             gdcmVersion=GDCM2;                         shift 1;;
234         -itk4)              ITKVersion=ITK4;                           shift 1;;
235         -build)             buildType=$2;                              shift 2;;
236         *) break;;
237     esac
238 done
239
240 if [ $# -le 0 ] ; then usage; fi
241
242 command=$1
243
244 # check that command is valid
245 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
246     echo "Unrecognized command: $command"
247     echo ""
248     usage
249 fi
250
251
252 ############################## use existing configuration if command is not config or all
253 if [ `checkVal $command config all` == false ] ; then
254     if [ ! -f $configureFile ] ; then
255         echo "scripts/CreaTools-configure.sh does not exists"
256         echo "please run the scripts with command \"config\" or \"all\""
257         exit
258     fi
259     source $configureFile
260     if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
261         echo WARNING
262         echo "the curently used Third Party libraries are NOT in $installPrefixThird but ... in :"
263         grep "installPrefixThird=" $ETC_BASHRC
264         echo "VTK_DIR  : " $VTK_DIR
265         echo "ITK_DIR  : " $ITK_DIR
266         echo "GDCM_DIR : " $GDCM_DIR
267         echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
268     
269 #        exit
270     fi
271     
272 fi
273
274 ##################################################################################
275 ############################ check configuration parameters
276 # check distrib
277 checkDistrib $OperatingSystem
278
279 # complete default install prefix
280 if [ -z "$installPrefix" ]      ; then installPrefix=$generationdir/creatools_install; fi
281 if [ -z "$installPrefixThird" ] ; then installPrefixThird=$generationdir/thirdparty_install; fi
282
283 # check build type
284 if [ `checkVal $buildType Release Debug RelWithDebug` == "false" ] ; then
285     echo "Unsupported build type: $buildType"
286     echo "Please use one of: Release Debug RelWithDebug"
287     exit 1
288 fi
289
290
291 ##################################################################################
292 ############################  write configuration file
293 if [ `checkVal $command config all` == true ] ; then
294     echo "#!/bin/bash"                            >  $configureFile
295     echo                                          >> $configureFile
296     echo "#File generated by 'installscript'"           >> $configureFile
297     echo "#DO NOT edit !"                         >> $configureFile
298     echo "#(except if you *do* know what you do)" >> $configureFile
299     echo                                          >> $configureFile
300     echo "OperatingSystem=$OperatingSystem"       >> $configureFile
301     echo "corenumber=$corenumber"                 >> $configureFile   
302     echo "generationdir=$generationdir"           >> $configureFile
303     echo "installPrefix=$installPrefix"           >> $configureFile
304     echo "installPrefixThird=$installPrefixThird" >> $configureFile
305     echo "docgeneration=$docgeneration"           >> $configureFile
306     echo "sourcesFrom=$sourcesFrom"               >> $configureFile
307     echo "loginUserName=$loginUserName"           >> $configureFile
308     echo "loginGroupName=$loginGroupName"         >> $configureFile
309     echo "buildType=$buildType"                   >> $configureFile
310     echo "gdcmVersion=$gdcmVersion"               >> $configureFile
311     echo "ITKVersion=$ITKVersion"                 >> $configureFile
312     echo "ETC_BASHRC=$ETC_BASHRC"                 >> $configureFile
313 fi
314
315
316
317 ################################### print current configuration
318 printconfig
319
320
321 ##################################################################################
322 ##################################################################################
323 ############   Process commands
324 ##################################################################################
325 ##################################################################################
326
327
328 ################################################################################## config printconfig
329 # config or printconfig : already done
330 if [ `checkVal $command config printconfig` == true ] ; then
331     exit
332 fi
333
334
335 ################################################################################## 3rd library
336 # install packaged dependencies as root
337 if [ `checkVal $command all 3rd 3rd-base` == true ] ; then
338     bigDisplay "INSTALL PACKAGES DEPENDENCIES"
339     if [ "`whoami`" == root ] ; then
340         bash scripts/ThirdParty-install-Base-Stuff.sh
341     else 
342         # must log as root
343         echo "Please enter the root passwd to add necessary packages:"; 
344         sudo su -c "bash scripts/ThirdParty-install-Base-Stuff.sh"   
345     fi
346     bash scripts/ThirdParty-install.sh
347 fi
348
349
350 # vtk
351 if [ `checkVal $command all 3rd 3rd-vtk` == true ] ; then
352     bigDisplay "INSTALL VTK"
353     bash scripts/ThirdParty-install-VTK.sh
354 fi
355
356 # gdcm
357 if [ `checkVal $command all 3rd 3rd-gdcm` == true ] ; then
358     bigDisplay "INSTALL $gdcmVersion"
359     bash scripts/ThirdParty-install-gdcm.sh
360 fi
361
362 # itk
363 if [ `checkVal $command all 3rd 3rd-itk` == true ] ; then
364     bigDisplay "INSTALL $ITKVersion"
365     bash scripts/ThirdParty-install-ITK.sh
366 fi
367
368 ## ??
369 #if [ `checkVal $command all 3rd` == true ] ; then
370 #    bash scripts/ThirdParty-install.sh
371 #fi
372
373 # Setup the user .bashrc correctly
374 if [ `checkVal $command all 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
375     bigDisplay "FINALIZE 3RD PARTY LIBRARY INSTALLATION"
376     bash scripts/ThirdParty-install-Finalize.sh
377     source $ETC_BASHRC
378     if [ `checkVal $command 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
379         bigDisplay "Third Party Install Done" 
380         bigDisplay "Please copy paste the following command or open a new terminal: source ~/.bashrc" 
381     fi
382 fi
383
384 ################################################################################## creatools
385
386 # download creatools
387 if [ `checkVal $command all creatools creatools-get` == true ] ; then
388     bigDisplay "DOWNLOAD CREATOOLS"
389     bash scripts/CreaTools-load.sh
390 fi
391
392 # compile creatools
393 if [ `checkVal $command all creatools creatools-cmp` == true ] ; then
394     bigDisplay "COMPILE CREATOOLS"
395     source $ETC_BASHRC
396     bash -x scripts/CreaTools-compile.sh
397
398     # To allow (*very* aware) user to patch code, later
399     if [ ! -e $generationdir/creatools_source ] ; then
400         echo "You probabely made a mistake : "
401         echo "Directory $loginUserName $generationdir/creatools_source not found"
402         echo "Make sure you know the mistake"
403         echo "Hit any key to continue"
404         echo "Fix the mistake!"
405         read a
406     else
407         chown -R $loginUserName  $generationdir/creatools_source
408         chgrp -R $loginGroupName $generationdir/creatools_source
409     fi
410 fi
411      
412 #install creatools
413 if [ `checkVal $command all creatools creatools-install` == true ] ; then
414     bigDisplay "INSTALL CREATOOLS"
415     source $ETC_BASHRC
416     bash scripts/CreaTools-install.sh
417     source $ETC_BASHRC
418 fi
419
420 ################################################################################## uninstall
421
422 if [ `checkVal $command uninstall` == true ] ; then
423     bigDisplay "UNINSTALL CREATOOLS"
424     bash scripts/CreaTools-uninstall.sh 
425 fi
426
427 ################################################################################## help
428 if [ `checkVal $command help` == true ] ; then
429     cat README.txt
430 fi
431
432 ################################################################################## print env variables
433 if [ `checkVal $command env` == true ] ; then
434     if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
435         echo WARNING
436         echo
437         echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
438         grep "installPrefixThird=" $ETC_BASHRC
439         echo "VTK_DIR  : " $VTK_DIR
440         echo "ITK_DIR  : " $ITK_DIR
441         echo "GDCM_DIR : " $GDCM_DIR
442         echo
443         echo "installPrefixThird ... " $installPrefixThird
444     fi
445              
446     if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
447         echo  "Third party config file : " $installPrefixThird/share/creatools_third_party_library_config.sh
448         echo  ------
449         cat $installPrefixThird/share/creatools_third_party_library_config.sh
450         echo  ------
451     fi
452      
453     echo
454      
455     if [ -f $installPrefix/share/creatools_base_library_config.sh ] ; then
456        echo  "Creatools base library config file : " $installPrefix/share/creatools_base_library_config.sh
457        echo  ------ 
458        cat $installPrefix/share/creatools_base_library_config.sh
459        echo  ------ 
460        echo
461        echo "installPrefix ... " $installPrefix
462     fi
463
464     echo  ------
465     echo "VTK_DIR  :                 " $VTK_DIR
466     echo "ITK_DIR  :                 " $ITK_DIR
467     echo "GDCM_DIR :                 " $GDCM_DIR
468     echo
469     echo "crea_DIR :                 " $crea_DIR
470     echo "BBTK_DIR :                 " $BBTK_DIR
471     echo "creaMaracasVisu_DIR :      " $creaMaracasVisu_DIR
472     echo "creaEnvironment_DIR :      " $creaEnvironment_DIR
473     echo "creaBruker_DIR :           " $creaBruker_DIR
474     echo "creaImageIO_DIR :          " $creaImageIO_DIR
475     echo "creaContours_DIR :         " $creaContours_DIR
476     echo "creaRigidRegistration_DIR :" $creaRigidRegistration_DIR
477     echo "bbtkGEditor_DIR :          " $bbtkGEditor_DIR
478     echo "creaTools_DIR :            " $creaTools_DIR
479     echo "creaMiniTools_DIR :        " $creaMiniTools_DIR
480     echo "Ido_DIR :                  " $Ido_DIR
481     echo "==================================="
482     echo
483
484 fi
485
486
487