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