]> Creatis software - creaToolsTools.git/blob - Linux/installscript
9c899b09035957039931f438dd1f802063b62344
[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 #This code is Mac
28 function EEDreadlink() {
29   DIR="${1%/*}"
30   (cd "$DIR" && echo "$(pwd -P)")
31 }
32
33
34 #EED 2120-08-25  This code is not working in MacOS so we use EEDreadlink()
35 #EED scriptDirName=$(dirname $(Ereadlink -f $0) )
36 scriptDirName=$(dirname $(Ereadlink  $0) )/Linux
37
38 #########################################################################
39 ############     Local Functions  #######################################
40 #########################################################################
41
42
43 source scripts/LocalFunctions.sh
44
45 configureFile="scripts/CreaTools-configure.sh"
46
47
48 # default configuration parameters
49 OperatingSystem=`getDistrib`
50 corenumber=`getncore`
51 generationdir=$HOME/Creatis/C11
52 installPrefixThird=
53 installPrefix=
54 docgeneration=OFF
55 sourcesFrom=GIT
56
57 loginUserName=$USER
58 loginGroupName=`groups | awk '{print $1}'`
59 buildType=Release
60 gdcmVersion=GDCM1
61 ITKVersion=ITK3
62 export ETC_BASHRC=`getbashrc`
63 TDx=ON
64
65
66 function usage {
67     echo "installscript [options] command" 
68     echo "creatools configure/compile/install script" 
69     echo "" 
70     echo "" 
71     echo "OPTIONS ARE USE FOR CONFIGURATION ONLY: THEY WILL BE IGNORED IF <COMMAND> IS NOT \"CONFIG\" OR \"ALL\"" 
72     echo "" 
73     echo "" 
74     echo "    command:" 
75     echo "" 
76     echo "    as a normal user:" 
77     echo "         config                    : set the configuration parameters only" 
78     echo "         "                 
79     echo "    need root password:" 
80     echo "         3rd                       : Get, Compile, Install all 3rd party library "
81     echo "         3rd-base                  : Install basic tools (cmake, doxygen...)"
82     echo "         3rd-vtk                   : Get, Compile, Install vtk"
83     echo "         3rd-itk                   : Get, Compile, Install itk"
84     echo "         3rd-gdcm                  : Get, Compile, Install gdcm"
85     echo "         3rd-wx                    : Get, Compile, Install wx widget (for Mac Users)"
86     echo "         3rd-wt                    : Get, Compile, Install wt"
87     echo "   "
88     echo "    as a normal user:" 
89     echo "         creatools                 : Get Compile and Install the CreaTools"
90     echo "         creatools-get             : Get the CreaTools"
91     echo "         creatools-cmp             : Compile the CreaTools"
92     echo "         creatools-install         : Install the CreaTools"
93     echo "   "
94     echo "         creatools-generateBinTGZ  : generation of CreaTools.tgz (binary version)" 
95     echo "   "
96     echo "         uninstall                 : uninstall the creatools"
97     echo "   "
98     echo "         printconfig               : print the configuration" 
99     echo "         help                      : print help"
100     echo "         env                       : print some environnement variables"
101     echo "" 
102     echo "         all                       : configure / compile / install" 
103     echo "         "                 
104     echo "   "
105     echo "   "
106     echo "   "
107     echo "   "
108     echo "    configure options: !!!!! IGNORED IF COMMAND IS NOT CONFIG OR ALL !!!!!!" 
109     echo "        -os <os>              : operating system distribution (default $OperatingSystem)"
110     echo "        -ncore <n>            : number of core to use (default $corenumber)"
111     echo "        -gdir <dir>           : generation directory (default $generationdir)"
112     echo "        -instprefix <dir>     : creatools install prefix" 
113     echo "        -instprefix3 <dir>    : 3rd party library install prefix" 
114     echo "        -html                 : get creatools from HTML"
115     echo "        -git                  : get creatools from git (CREATIS user only)"
116     echo "        -git-read-only        : get creatools from git (anonymously, no write access)"
117     echo "        -build                : build type Release, RelWithDebug or Debug (default RelWithDebug)"
118     echo ""
119     echo "     experimental configure options (use at your own risk!!):"
120     echo "        -gdcm2         : use GDCM2 "
121     echo "        -doc           : generate documentation"
122     echo "        -itk4          : use ITK4"
123     echo "" 
124     exit 1
125 }
126
127 ##################################################
128 # parse command line
129 while [ $# -ge 1 ] ; do
130     case $1 in
131         -os)                OperatingSystem=$2;                        shift 2;;
132         -ncore)             corenumber=$2;                             shift 2;;                     
133         -gdir)              generationdir=$2;                          shift 2;;                     
134         -instprefix)        installPrefix=$2;                          shift 2;;
135         -instprefix3)       installPrefixThird=$2;                     shift 2;;
136         -doc)               docgeneration=ON;                          shift 1;;
137         -html)              sourcesFrom=HTML;                          shift 1;;
138         -git)               sourcesFrom=GIT;                           shift 1;;
139         -git-read-only)     sourcesFrom=GIT-READ-ONLY;
140 shift 1;;
141         -gdcm2)             gdcmVersion=GDCM2;                         shift 1;;
142         -itk4)              ITKVersion=ITK4;                           shift 1;;
143         -build)             buildType=$2;                              shift 2;;
144         *) break;;
145     esac
146 done
147
148 if [ $# -le 0 ] ; then usage; fi
149
150 command=$1
151
152 # check that command is valid
153 if [ `checkVal $command all config 3rd 3rd-base 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx 3rd-wt creatools creatools-get creatools-cmp creatools-install creatools-generateBinTGZ uninstall printconfig help env` == "false" ] ; then
154     echo "Unrecognized command: $command"
155     echo ""
156     usage
157 fi
158
159
160 ############################## use existing configuration if command is not config or all
161 if [ `checkVal $command config all` == false ] ; then
162     if [ ! -f $configureFile ] ; then
163         echo "scripts/CreaTools-configure.sh does not exists"
164         echo "please run the scripts with command \"config\" or \"all\""
165         exit
166     fi
167     source $configureFile
168     if [ ! -f $installPrefixThird/share/creatools/creatools_third_party_library_config.sh ] ; then
169         echo WARNING
170         echo "the curently used Third Party libraries are NOT in $installPrefixThird but ... in :"
171         grep "installPrefixThird=" $ETC_BASHRC
172         echo "VTK_DIR  : " $VTK_DIR
173         echo "ITK_DIR  : " $ITK_DIR
174         echo "GDCM_DIR : " $GDCM_DIR
175         echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
176     
177 #        exit
178     fi
179     
180 fi
181
182 ##################################################################################
183 ############################ check configuration parameters
184 # check distribĂ’
185 checkDistrib $OperatingSystem
186
187 # complete default install prefix
188 if [ -z "$installPrefix" ]      ; then installPrefix=$generationdir/ci; fi
189 if [ -z "$installPrefixThird" ] ; then installPrefixThird=$generationdir/tpli; fi
190
191 # check build type
192 if [ `checkVal $buildType Release Debug RelWithDebug` == "false" ] ; then
193     echo "Unsupported build type: $buildType"
194     echo "Please use one of: Release Debug RelWithDebug"
195     exit 1
196 fi
197
198
199 ##################################################################################
200 ############################  write configuration file
201 if [ `checkVal $command config all` == true ] ; then
202     echo "#!/bin/bash"                            >  $configureFile
203     echo                                          >> $configureFile
204     echo "#File generated by 'installscript'"           >> $configureFile
205     echo "#DO NOT edit !"                         >> $configureFile
206     echo "#(except if you *do* know what you do)" >> $configureFile
207     echo                                          >> $configureFile
208     echo "OperatingSystem=$OperatingSystem"       >> $configureFile
209     echo "corenumber=$corenumber"                 >> $configureFile   
210     echo "generationdir=$generationdir"           >> $configureFile
211     echo "installPrefix=$installPrefix"           >> $configureFile
212     echo "installPrefixThird=$installPrefixThird" >> $configureFile
213     echo "docgeneration=$docgeneration"           >> $configureFile
214     echo "sourcesFrom=$sourcesFrom"               >> $configureFile
215     echo "loginUserName=$loginUserName"           >> $configureFile
216     echo "loginGroupName=$loginGroupName"         >> $configureFile
217     echo "buildType=$buildType"                   >> $configureFile
218     echo "gdcmVersion=$gdcmVersion"               >> $configureFile
219     echo "ITKVersion=$ITKVersion"                 >> $configureFile
220     echo "ETC_BASHRC=$ETC_BASHRC"                 >> $configureFile
221     echo "TDx=$TDx"                               >> $configureFile
222 fi
223
224
225
226 ################################### print current configuration
227 printconfig
228
229
230 ##################################################################################
231 ##################################################################################
232 ############   Process commands
233 ##################################################################################
234 ##################################################################################
235
236
237 ################################################################################## config printconfig
238 # config or printconfig : already done
239 if [ `checkVal $command config printconfig` == true ] ; then
240     exit
241 fi
242
243 ################################################################################## creatools
244 # download creatools
245 if [ `checkVal $command all creatools creatools-get` == true ] ; then
246     bigDisplay "DOWNLOAD CREATOOLS"
247     bash scripts/CreaTools-load.sh
248 fi
249
250 ################################################################################## 3rd library
251 # install packaged dependencies as root
252 if [ `checkVal $command all 3rd 3rd-base` == true ] ; then
253     bigDisplay "INSTALL PACKAGES DEPENDENCIES"
254     bash scripts/CreaTools-configure.sh
255     cd scripts
256     source ThirdParty-install-Base-Stuff.sh $OperatingSystem
257     cd ..
258     bash scripts/ThirdParty-install.sh
259 fi
260
261 # vtk
262 if [ `checkVal $command all 3rd 3rd-vtk` == true ] ; then
263     bigDisplay "INSTALL VTK"
264     bash scripts/ThirdParty-install-VTK.sh
265     cd $scriptDirName
266 fi
267
268 # gdcm
269 if [ `checkVal $command all 3rd 3rd-gdcm` == true ] ; then
270     bigDisplay "INSTALL $gdcmVersion"
271     bash scripts/ThirdParty-install-gdcm.sh
272     pwd
273     echo $scriptDirName 
274     cd $scriptDirName
275 fi
276
277 # itk
278 if [ `checkVal $command all 3rd 3rd-itk` == true ] ; then
279     bigDisplay "INSTALL $ITKVersion"
280     bash scripts/ThirdParty-install-ITK.sh
281     cd $scriptDirName
282 fi
283
284 # wt
285 if [ `checkVal $command all 3rd 3rd-wt` == true ] ; then
286     bigDisplay "INSTALL WT"
287     bash scripts/ThirdParty-install-WT.sh
288     cd $scriptDirName
289 fi
290
291 # Setup the user .bashrc correctly
292 if [ `checkVal $command all 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx 3rd-wt ` == true ] ; then
293     bigDisplay "FINALIZE 3RD PARTY LIBRARY INSTALLATION"
294     bash scripts/ThirdParty-install-Finalize.sh
295     if [ `checkVal $command 3rd 3rd-vtk 3rd-itk 3rd-gdcm 3rd-wx ` == true ] ; then
296         bigDisplay "Third Party Install Done" 
297         bigDisplay "Please copy paste the following command or open a new terminal: source ~/.bashrc" 
298     fi
299 fi
300
301 ################################################################################## creatools
302 # compile creatools
303 if [ `checkVal $command all creatools creatools-cmp` == true ] ; then
304     bigDisplay "COMPILE CREATOOLS"
305 echo "EED installscript compile creatools"
306 echo $ETC_BASHRC
307     source $ETC_BASHRC
308     bash -x scripts/CreaTools-compile.sh
309
310     # To allow (*very* aware) user to patch code, later
311     if [ ! -e $generationdir/creatools_source ] ; then
312         echo "You probabely made a mistake : "
313         echo "Directory $loginUserName $generationdir/creatools_source not found"
314         echo "Make sure you know the mistake"
315         echo "Hit any key to continue"
316         echo "Fix the mistake!"
317         read a
318     else
319         chown -R $loginUserName  $generationdir/creatools_source
320         chgrp -R $loginGroupName $generationdir/creatools_source
321     fi
322 fi
323      
324 #install creatools
325 if [ `checkVal $command all creatools creatools-install` == true ] ; then
326     bigDisplay "INSTALL CREATOOLS"
327     source $ETC_BASHRC
328     bash scripts/CreaTools-install.sh
329     source $ETC_BASHRC
330     echo " "
331     echo " "
332     echo " "
333     echo " "
334     echo "Open a new terminal to run creatools."
335     echo "(Close this window and continue....) "
336     echo " "
337     echo " "
338     ##EED read -p "Press [Enter] key to continue..."
339 fi
340
341 #generate TGZ version of the bin (Creatools and ThirdParty)
342 if [ `checkVal $command creatools-generateBinTGZ` == true ] ; then
343     bash scripts/CreaTools-GenerateBinTGZ.sh
344 fi
345
346 ################################################################################## uninstall
347 if [ `checkVal $command uninstall` == true ] ; then
348     bigDisplay "UNINSTALL CREATOOLS"
349     bash scripts/CreaTools-uninstall.sh 
350 fi
351
352 ################################################################################## help
353 if [ `checkVal $command help` == true ] ; then
354     cat README.txt
355 fi
356
357 ################################################################################## print env variables
358 if [ `checkVal $command env` == true ] ; then
359     if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
360         echo WARNING
361         echo
362         echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
363         grep "installPrefixThird=" $ETC_BASHRC
364         echo "VTK_DIR  : " $VTK_DIR
365         echo "ITK_DIR  : " $ITK_DIR
366         echo "GDCM_DIR : " $GDCM_DIR
367         echo
368         echo "installPrefixThird ... " $installPrefixThird
369     fi
370              
371     if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ] ; then
372         echo  "Third party config file : " $installPrefixThird/share/creatools_third_party_library_config.sh
373         echo  ------
374         cat $installPrefixThird/share/creatools_third_party_library_config.sh
375         echo  ------
376     fi
377      
378     echo
379      
380     if [ -f $installPrefix/share/creatools_base_library_config.sh ] ; then
381        echo  "Creatools base library config file : " $installPrefix/share/creatools_base_library_config.sh
382        echo  ------ 
383        cat $installPrefix/share/creatools_base_library_config.sh
384        echo  ------ 
385        echo
386        echo "installPrefix ... " $installPrefix
387     fi
388
389     echo  ------
390     echo "VTK_DIR  :                 " $VTK_DIR
391     echo "ITK_DIR  :                 " $ITK_DIR
392     echo "GDCM_DIR :                 " $GDCM_DIR
393     echo
394     echo "crea_DIR :                 " $crea_DIR
395     echo "BBTK_DIR :                 " $BBTK_DIR
396     echo "creaMaracasVisu_DIR :      " $creaMaracasVisu_DIR
397     echo "creaEnvironment_DIR :      " $creaEnvironment_DIR
398     echo "creaBruker_DIR :           " $creaBruker_DIR
399     echo "creaImageIO_DIR :          " $creaImageIO_DIR
400     echo "creaContours_DIR :         " $creaContours_DIR
401     echo "creaRigidRegistration_DIR :" $creaRigidRegistration_DIR
402     echo "bbtkGEditor_DIR :          " $bbtkGEditor_DIR
403     echo "creaTools_DIR :            " $creaTools_DIR
404     echo "creaMiniTools_DIR :        " $creaMiniTools_DIR
405     echo "Ido_DIR :                  " $Ido_DIR
406     echo "==================================="
407     echo
408
409 fi
410
411
412