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