]> Creatis software - creaToolsTools.git/blob - Linux/installscript
c65468e096a536de700c59c0c3497714ba6d2bb8
[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 "         all               : configure / compile / install" 
173     echo "         "                 
174     echo "         config            : set the configuration parameters only" 
175     echo "         "                 
176     echo "         3rd               : Get, Compile, Install all 3rd party library "
177     echo "         3rd-base          : Install basic tools (cmake, doxygen...)"
178     echo "         3rd-vtk           : Get, Compile, Install vtk"
179     echo "         3rd-itk           : Get, Compile, Install itk"
180     echo "         3rd-gdcm          : Get, Compile, Install gdcm"
181     echo "         3rd-wx            : Get, Compile, Install wx widget (for Mac Users)"
182     echo "   "
183     echo "         creatools         : Get Compile and Install the CreaTools"
184     echo "         creatools-get     : Get the CreaTools"
185     echo "         creatools-cmp     : Compile the CreaTools"
186     echo "         creatools-install : Install the CreaTools"
187     echo "   "
188     echo "         uninstall         : uninstall the creatools"
189     echo "   "
190     echo "         printconfig       : print the configuration" 
191     echo "         help              : print help"
192     echo "         env               : print some environnement variables"
193     echo "   "
194     echo "   "
195     echo "   "
196     echo "   "
197     echo "    configure options: !!!!! IGNORED IF COMMAND IS NOT CONFIG OR ALL !!!!!!" 
198     echo "        -os <os>              : operating system distribution (default $OperatingSystem)"
199     echo "        -ncore <n>            : number of core to use (default $corenumber)"
200     echo "        -gdir <dir>           : generation directory (default $generationdir)"
201     echo "        -instprefix <dir>     : creatools install prefix" 
202     echo "        -instprefix3 <dir>    : 3rd party library install prefix" 
203     echo "        -git                  : get creatools from git (CREATIS user only)"
204     echo "        -build                : build type Release, RelWithDebug or Debug (default RelWithDebug)"
205     echo ""
206     echo "     experimental configure options (use at your own risk!!):"
207     echo "        -gdcm2         : use GDCM2 "
208     echo "        -doc           : generate documentation"
209     echo "        -itk4          : use ITK4"
210     echo "" 
211     exit 1
212 }
213
214 ##################################################
215 # parse command line
216 while [ $# -ge 1 ] ; do
217     case $1 in
218         -os)                OperatingSystem=$2;                        shift 2;;
219         -ncore)             corenumber=$2;                             shift 2;;                     
220         -gdir)              generationdir=$2;                          shift 2;;                     
221         -instprefix)        installPrefix=$2;                          shift 2;;
222         -instprefix3)       installPrefixThird=$2;                     shift 2;;
223         -doc)               docgeneration=ON;                          shift 1;;
224         -git)               sourcesFrom=GIT;                           shift 1;;
225         -gdcm2)             gdcmVersion=GDCM2;                         shift 1;;
226         -itk4)              ITKVersion=ITK4;                           shift 1;;
227         -build)             buildType=$2;                              shift 2;;
228         *) break;;
229     esac
230 done
231
232 if [ $# -le 0 ] ; then usage; fi
233
234 command=$1
235
236 # check that command is valid
237 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
238     echo "Unrecognized command: $command"
239     echo ""
240     usage
241 fi
242
243
244 ############################## use existing configuration if command is not config or all
245 if [ `checkVal $command config all` == false ] ; then
246     if [ ! -f $configureFile ] ; then
247         echo "scripts/CreaTools-configure.sh does not exists"
248         echo "please run the scripts with command \"config\" or \"all\""
249         exit
250     fi
251     source $configureFile
252     if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
253         echo WARNING
254         echo "the curently used Third Party libraries are NOT in $installPrefixThird but ... in :"
255         grep "installPrefixThird=" $ETC_BASHRC
256         echo "VTK_DIR  : " $VTK_DIR
257         echo "ITK_DIR  : " $ITK_DIR
258         echo "GDCM_DIR : " $GDCM_DIR
259         echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
260     
261 #        exit
262     fi
263     
264 fi
265
266 ##################################################################################
267 ############################ check configuration parameters
268 # check distrib
269 checkDistrib $OperatingSystem
270
271 # complete default install prefix
272 if [ -z "$installPrefix" ]      ; then installPrefix=$generationdir/creatools_install; fi
273 if [ -z "$installPrefixThird" ] ; then installPrefixThird=$generationdir/thirdparty_install; fi
274
275 # check build type
276 if [ `checkVal $buildType Release Debug RelWithDebug` == "false" ] ; then
277     echo "Unsupported build type: $buildType"
278     echo "Please use one of: Release Debug RelWithDebug"
279     exit 1
280 fi
281
282
283 ##################################################################################
284 ############################  write configuration file
285 if [ `checkVal $command config all` == true ] ; then
286     echo "#!/bin/bash"                            >  $configureFile
287     echo                                          >> $configureFile
288     echo "#File generated by 'installscript'"           >> $configureFile
289     echo "#DO NOT edit !"                         >> $configureFile
290     echo "#(except if you *do* know what you do)" >> $configureFile
291     echo                                          >> $configureFile
292     echo "OperatingSystem=$OperatingSystem"       >> $configureFile
293     echo "corenumber=$corenumber"                 >> $configureFile   
294     echo "generationdir=$generationdir"           >> $configureFile
295     echo "installPrefix=$installPrefix"           >> $configureFile
296     echo "installPrefixThird=$installPrefixThird" >> $configureFile
297     echo "docgeneration=$docgeneration"           >> $configureFile
298     echo "sourcesFrom=$sourcesFrom"               >> $configureFile
299     echo "loginUserName=$loginUserName"           >> $configureFile
300     echo "loginGroupName=$loginGroupName"         >> $configureFile
301     echo "buildType=$buildType"                   >> $configureFile
302     echo "gdcmVersion=$gdcmVersion"               >> $configureFile
303     echo "ITKVersion=$ITKVersion"                 >> $configureFile
304     echo "ETC_BASHRC=$ETC_BASHRC"                 >> $configureFile
305 fi
306
307
308
309 ################################### print current configuration
310 printconfig
311
312
313 ##################################################################################
314 ##################################################################################
315 ############   Process commands
316 ##################################################################################
317 ##################################################################################
318
319
320 ################################################################################## config printconfig
321 # config or printconfig : already done
322 if [ `checkVal $command config printconfig` == true ] ; then
323     exit
324 fi
325
326
327 ################################################################################## 3rd library
328 # install packaged dependencies as root
329 if [ `checkVal $command all 3rd 3rd-base` == true ] ; then
330     bigDisplay "INSTALL PACKAGES DEPENDENCIES"
331     if [ "`whoami`" == root ] ; then
332         bash scripts/ThirdParty-install-Base-Stuff.sh
333     else 
334         # must log as root
335         echo "Please enter the root passwd to add necessary packages:"; 
336         sudo su -c "bash scripts/ThirdParty-install-Base-Stuff.sh"   
337     fi
338     bash scripts/ThirdParty-install.sh
339 fi
340
341
342 # vtk
343 if [ `checkVal $command all 3rd 3rd-vtk` == true ] ; then
344     bigDisplay "INSTALL VTK"
345     bash scripts/ThirdParty-install-VTK.sh
346 fi
347
348 # gdcm
349 if [ `checkVal $command all 3rd 3rd-gdcm` == true ] ; then
350     bigDisplay "INSTALL $gdcmVersion"
351     bash scripts/ThirdParty-install-gdcm.sh
352 fi
353
354 # itk
355 if [ `checkVal $command all 3rd 3rd-itk` == true ] ; then
356     bigDisplay "INSTALL $ITKVersion"
357     bash scripts/ThirdParty-install-ITK.sh
358 fi
359
360 ## ??
361 #if [ `checkVal $command all 3rd` == true ] ; then
362 #    bash scripts/ThirdParty-install.sh
363 #fi
364
365 # Setup the user .bashrc correctly
366 if [ `checkVal $command all 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
367     bigDisplay "FINALIZE 3RD PARTY LIBRARY INSTALLATION"
368     bash scripts/ThirdParty-install-Finalize.sh
369     source $ETC_BASHRC
370     if [ `checkVal $command 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
371         bigDisplay "Third Party Install Done" 
372         bigDisplay "Please copy paste the following command or open a new terminal: source ~/.bashrc" 
373     fi
374 fi
375
376 ################################################################################## creatools
377
378 # download creatools
379 if [ `checkVal $command all creatools creatools-get` == true ] ; then
380     bigDisplay "DOWNLOAD CREATOOLS"
381     bash scripts/CreaTools-load.sh
382 fi
383
384 # compile creatools
385 if [ `checkVal $command all creatools creatools-cmp` == true ] ; then
386     bigDisplay "COMPILE CREATOOLS"
387     source $ETC_BASHRC
388     bash -x scripts/CreaTools-compile.sh
389
390     # To allow (*very* aware) user to patch code, later
391     if [ ! -e $generationdir/creatools_source ] ; then
392         echo "You probabely made a mistake : "
393         echo "Directory $loginUserName $generationdir/creatools_source not found"
394         echo "Make sure you know the mistake"
395         echo "Hit any key to continue"
396         echo "Fix the mistake!"
397         read a
398     else
399         chown -R $loginUserName  $generationdir/creatools_source
400         chgrp -R $loginGroupName $generationdir/creatools_source
401     fi
402 fi
403      
404 #install creatools
405 if [ `checkVal $command all creatools creatools-install` == true ] ; then
406     bigDisplay "INSTALL CREATOOLS"
407     source $ETC_BASHRC
408     bash scripts/CreaTools-install.sh
409     source $ETC_BASHRC
410 fi
411
412 ################################################################################## uninstall
413
414 if [ `checkVal $command uninstall` == true ] ; then
415     bigDisplay "UNINSTALL CREATOOLS"
416     bash scripts/CreaTools-uninstall.sh 
417 fi
418
419 ################################################################################## help
420 if [ `checkVal $command help` == true ] ; then
421     cat README.txt
422 fi
423
424 ################################################################################## print env variables
425 if [ `checkVal $command env` == true ] ; then
426     if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
427         echo WARNING
428         echo
429         echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
430         grep "installPrefixThird=" $ETC_BASHRC
431         echo "VTK_DIR  : " $VTK_DIR
432         echo "ITK_DIR  : " $ITK_DIR
433         echo "GDCM_DIR : " $GDCM_DIR
434         echo
435         echo "installPrefixThird ... " $installPrefixThird
436     fi
437              
438     if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
439         echo  "Third party config file : " $installPrefixThird/share/creatools_third_party_library_config.sh
440         echo  ------
441         cat $installPrefixThird/share/creatools_third_party_library_config.sh
442         echo  ------
443     fi
444      
445     echo
446      
447     if [ -f $installPrefix/share/creatools_base_library_config.sh ] ; then
448        echo  "Creatools base library config file : " $installPrefix/share/creatools_base_library_config.sh
449        echo  ------ 
450        cat $installPrefix/share/creatools_base_library_config.sh
451        echo  ------ 
452        echo
453        echo "installPrefix ... " $installPrefix
454     fi
455
456     echo  ------
457     echo "VTK_DIR  :                 " $VTK_DIR
458     echo "ITK_DIR  :                 " $ITK_DIR
459     echo "GDCM_DIR :                 " $GDCM_DIR
460     echo
461     echo "crea_DIR :                 " $crea_DIR
462     echo "BBTK_DIR :                 " $BBTK_DIR
463     echo "creaMaracasVisu_DIR :      " $creaMaracasVisu_DIR
464     echo "creaEnvironment_DIR :      " $creaEnvironment_DIR
465     echo "creaBruker_DIR :           " $creaBruker_DIR
466     echo "creaImageIO_DIR :          " $creaImageIO_DIR
467     echo "creaContours_DIR :         " $creaContours_DIR
468     echo "creaRigidRegistration_DIR :" $creaRigidRegistration_DIR
469     echo "bbtkGEditor_DIR :          " $bbtkGEditor_DIR
470     echo "creaTools_DIR :            " $creaTools_DIR
471     echo "creaMiniTools_DIR :        " $creaMiniTools_DIR
472     echo "Ido_DIR :                  " $Ido_DIR
473     echo "==================================="
474     echo
475
476 fi
477
478
479