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