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