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