]> Creatis software - creaToolsTools.git/blob - Linux/menu.sh
618a633fa0875960c59c8a5c72d0380150422cb1
[creaToolsTools.git] / Linux / menu.sh
1 #!/bin/bash -e
2
3   if [ -f scripts/CreaTools-configure.sh ]
4   then
5      source scripts/CreaTools-configure.sh
6   fi
7
8 expanded="NO"
9 i=999
10 while [ "$i" != 9 ]
11 do
12    clear
13    echo
14    echo
15    echo
16    echo "                MENU"
17    echo
18    echo " Choose what you want to do :"
19    echo  
20    echo " Configure :........................0"
21
22    if [ $expanded = "YES" ]
23    then 
24       echo " Install all base stuff  :..........1.0"
25       echo "        (cmake, doxygen, graphviz, ...)"
26       echo " Get, Compile, Install vtk   .......1.1"                
27       echo " Get, Compile, Install gdcm :.. .  .1.2" 
28       echo " Get, Compile, Install itk  :.......1.3"
29
30    else
31       echo " Install Third Party Libraries :....1 (as root)"   
32    fi
33      
34    if [ $expanded = "YES" ]
35    then
36       echo " Get the 'CreaTools' source files :.2.1 (CVS : as user!)" 
37       echo " Compile   the CreaTools :..........2.2"
38       # Install creatools as user (no longer as root) // JPR 2/5/2011   
39       echo " Install   the CreaTools :..........2.3"
40    else
41       echo " Get and Install the 'CreaTools':...2"
42    fi
43    echo
44    if [ $expanded = "NO" ]
45    then
46       echo " Use Expanded menu :................5 "
47    else
48       echo " Use compact menu :.................5 "
49    fi
50    echo " Uninstall the CreaTools :..........6 "
51    echo " Help ..............................7 Help about this menu"   
52    echo " Show some Environment Variables ...8"
53    echo " Exit :.............................9"
54    echo
55    echo
56    echo 
57
58   echo "Type in your choice :"
59   read i
60
61   case $i in
62   0)
63   
64   # Do it, while we are under user, not under root! # JPR
65               if [ -f $HOME/.bashrc ]
66               then
67                  export ETC_BASHRC=$HOME/.bashrc
68               else
69                  if [ -f $HOME/.profile ]
70                      then
71                     export ETC_BASHRC=$HOME/.profile
72                      else
73                         echo "======================== BIG TROUBLE : neither $HOME/.bashrc nor $HOME/.profile file found"
74                         echo "======================== You'd better to abort the program and (try to) fix the issue"
75                         read a # just to let the user time enough to read the message...
76                      fi
77           fi
78           
79   clear
80   suitable=XXX
81   #ls -l  scripts/CreaTools-configure.sh
82   if [ -f scripts/CreaTools-configure.sh ]
83   then
84      while [[ "$suitable" != "YES" && \
85               "$suitable" != "yes" && \
86               "$suitable" != "Y"   && \
87               "$suitable" != "y"   && \
88               "$suitable" != "NO"  && \
89               "$suitable" != "no"  ]]
90      do   
91         echo "'Configure' already done; Content of scripts/CreaTools-configure.sh :"
92         echo "------------------------"
93         more scripts/CreaTools-configure.sh
94         echo "------------------------"
95         
96             # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
97         # If user configured without installing third party library,
98         # last third party library is still in use!  JPR
99
100         if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
101         then
102            echo WARNING
103            echo "the curently used Third Party libraries are NOT in $installPrefixThird but ... in :"
104            grep "installPrefixThird=" $ETC_BASHRC 
105            echo "VTK_DIR  : " $VTK_DIR
106            echo "ITK_DIR  : " $ITK_DIR
107            echo "GDCM_DIR : " $GDCM_DIR
108            echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
109         fi
110         echo    
111         echo "Are these values suitable for you : YES/NO? (default is YES)"
112         read suitable
113         if [ "$suitable" = "" ]
114         then
115            suitable="YES"
116         fi
117      done
118   else
119      suitable="NO"
120   fi
121
122   if [[ "$suitable" = "YES" || "$suitable" = "Y" || "$suitable" = "yes" || "$suitable" = "y" ]]
123   then
124      source scripts/CreaTools-configure.sh
125   fi
126   
127  if [[ "$suitable" = "NO" || "$suitable" = "N"  || "$suitable" = "no" || "$suitable" = "n" ]]
128  #if [ "$suitable" = "NO" ]
129   then
130      echo
131      echo
132      confirm="NO"
133      while [ "$confirm" != "YES" ]
134      do
135         # ///\TODO what about SuSE? Debian? Mandriva? Gentoo?    
136         OperatingSystem="XXX"
137         while [[ "$OperatingSystem" != "Fedora" && \
138                  "$OperatingSystem" != "Ubuntu" && \
139                  "$OperatingSystem" != "MacOS" ]]
140         do
141            echo "Operating System : Fedora/Ubuntu/MacOS (default : Fedora)"
142            read OperatingSystem
143            if [ "$OperatingSystem" = "" ]
144            then
145              OperatingSystem="Fedora"
146            fi  
147         done
148         echo "you said : [" $OperatingSystem "]"
149         echo
150         echo
151         
152         # ------------------
153         echo "How many cores on your computer 2 (default is 2)"
154         read corenumber
155         if [ "$corenumber" = "" ]
156         then
157            corenumber="2"
158         fi
159         echo "you said : [" $corenumber "]"
160
161         echo
162         echo
163                 
164         racine=$HOME/myDefaultCreatoolsGenerationDir
165         # ------------------
166         echo "Name of the Generation Directory (default is $racine)"
167         read generationdir
168         if [ "$generationdir" = "" ]
169         then
170            generationdir=$racine
171         fi
172         echo "you said : [" $generationdir "]"
173
174         echo
175         echo
176         # ------------------
177         installPrefixThird="___"
178         echo "Install Prefix For Third Party Library : '$generationdir/thirdparty_install' / '/usr/local' (default is '$generationdir/thirdparty_install')"
179         read installPrefixThird
180         if [ "$installPrefixThird" = "" ]
181         then
182            installPrefixThird="$generationdir/thirdparty_install"
183         fi
184         echo "you said : [" $installPrefixThird "]"
185         echo
186         echo 
187         # ------------------
188
189         installPrefix="___"
190         echo "Install Prefix for CreaTools : '$generationdir/creatools_install' / '/usr/local' (default is '$generationdir/creatools_install')"
191         read installPrefix
192         if [ "$installPrefix" = "" ]
193         then
194            installPrefix="$generationdir/creatools_install"
195         fi
196         echo "you said : [" $installPrefix "]"
197         echo
198         echo 
199         # ------------------
200
201 if [ false ]
202 then
203         docgeneration="___"
204         while [[ "$docgeneration" != "ON"  && "$docgeneration" != "OFF" ]]
205         do
206            echo "Boolean For Doc Generation : ON/OFF (default is OFF)"
207            read docgeneration
208            if [ "$docgeneration" = "" ]
209            then
210               docgeneration="OFF"
211            fi
212            echo "you said : [" $docgeneration "]"
213          done
214          echo
215          echo
216 fi
217
218 docgeneration="OFF"
219
220         # ------------------
221
222         sourcesFrom="___"
223         while [[ "$sourcesFrom" != "CVS"  && "$sourcesFrom" != "HTML" ]]
224         do
225            echo "Where do you want to get source files from : CVS/HTML ( CVS : for registered CREATIS users only! )"
226            read sourcesFrom
227            if [ "$sourcesFrom" = "" ]
228            then
229               sourcesFrom="CVS"
230            fi
231            echo "you said : [" $sourcesFrom "]"
232         done
233         echo
234         echo
235         # ------------------
236
237         cvsUserName=""
238         if [ "$sourcesFrom" = "CVS" ]
239         then
240            while [ "$cvsUserName" == "" ]
241            do
242               echo "CVS User Name ( registered CREATIS user : mandatory!)"
243               read cvsUserName
244            done
245            echo "you said : [" $cvsUserName "]"
246         else
247            cvsUserName="ForgetThisOne" 
248         fi
249         echo
250         echo
251         # ------------------
252
253
254         #loginUserName=""
255             loginUserName=$USER
256         #while [ "$loginUserName" == "" ]
257         #do 
258            echo "Have a look at the following line to know 'Login User Name'/'Login Group Name'"
259            ls -l menu.sh
260          #  echo "Login User Name (mandatory!)"
261          #  read loginUserName  
262          #  echo "you said : [" $loginUserName "]"  
263         #done
264         echo
265         echo
266
267         loginGroupName=""
268         while [ "$loginGroupName" == "" ]
269         do
270            echo "Have a look at the following line to know 'Login User Name'/'Login Group Name'"
271                echo "Login Group Name (mandatory!)"
272            read loginGroupName  
273            echo "you said : [" $loginGroupName "]"  
274         done
275         echo
276         echo
277         # ------------------
278
279         buildType="___"
280         while [[ "$buildType" != "Release"  && "$buildType" != "Debug" ]]
281         do
282            echo "Build type : Release/Debug (default is Release)"
283            read buildType
284            if [ "$buildType" = "" ]
285            then
286               buildType="Release"
287            fi
288            echo "you said : [" $buildType "]"
289         done
290         echo
291         echo
292         # ------------------
293
294         gdcmVersion="___"
295         while [[ "$gdcmVersion" != "GDCM1"  && "$gdcmVersion" != "GDCM2" ]]
296         do
297            echo "Gdcm version : GDCM1/GDCM2 (default is GDCM1)"
298            read gdcmVersion
299            if [ "$gdcmVersion" = "" ]
300            then
301               gdcmVersion="GDCM1"
302            fi
303            echo "you said : [" $gdcmVersion "]"
304         done
305
306 # NOT YET CHECKED ! JPR
307         ITKVersion="___"
308         while [[ "$ITKVersion" != "ITK3"  && "$ITKVersion" != "ITK4" ]]
309         do
310            echo "ITK version : ITK3/ITK4 (default is ITK3)"
311            read ITKVersion
312            if [ "$ITKVersion" = "" ]
313            then
314               ITKVersion="ITK3"
315            fi
316            echo "you said : [" $ITKVersion "]"
317         done
318
319         echo
320         echo
321         echo
322         echo
323         echo "You said :"
324         echo "  Operating System                           : $OperatingSystem"
325         echo "  Number of Cores                            : $corenumber"       
326         echo "  Name of the Generation Directory           : $generationdir"
327         echo "  Install Prefix for Third Party Libraries   : $installPrefixThird"       
328         echo "  Install Prefix for CreaTools               : $installPrefix"
329         echo "  Boolean for Doc Generation                 : $docgeneration"
330         echo "  Where do you want to get source files from : $sourcesFrom"
331         if [ $sourcesFrom = CVS ]
332         then
333            echo "  CVS User Name                              : $cvsUserName"
334         fi
335         echo "  Login User Name                            : $loginUserName"
336         echo "  Login Group Name                           : $loginGroupName"
337         echo "  Build type                                 : $buildType"          
338         echo "  Gdcm version                               : $gdcmVersion"
339         echo "  ITK version                                : $ITKVersion"
340         echo
341         echo
342      
343         echo "Do you confirm your choices : YES/NO ? (default is YES)"
344         read confirm
345         if [ "$confirm" = "" ]
346         then
347            confirm=YES
348         fi
349    done
350
351  # ==> On genere le fichier CreaTools-configure.sh genere chez l'utilisateur (no choice!)...
352  # 
353
354    configureFile="scripts/CreaTools-configure.sh"
355    touch  $configureFile
356    echo "#!/bin/bash"                            >  $configureFile
357    echo                                          >> $configureFile
358    echo "#File generated by 'menu.sh'"           >> $configureFile
359    echo "#DO NOT edit !"                         >> $configureFile
360    echo "#(except if you *do* know what you do)" >> $configureFile
361    echo                                          >> $configureFile
362    echo "OperatingSystem=$OperatingSystem"       >> $configureFile
363    echo "corenumber=$corenumber"                 >> $configureFile   
364    echo "generationdir=$generationdir"           >> $configureFile
365    echo "installPrefix=$installPrefix"           >> $configureFile
366    echo "installPrefixThird=$installPrefixThird" >> $configureFile
367    echo "docgeneration=$docgeneration"           >> $configureFile
368    echo "sourcesFrom=$sourcesFrom"               >> $configureFile
369    echo "cvsUserName=$cvsUserName"               >> $configureFile 
370    echo "loginUserName=$loginUserName"           >> $configureFile
371    echo "loginGroupName=$loginGroupName"         >> $configureFile
372    echo "buildType=$buildType"                   >> $configureFile
373    echo "gdcmVersion=$gdcmVersion"               >> $configureFile
374    echo "ITKVersion=$ITKVersion"                 >> $configureFile
375    echo "ETC_BASHRC=$ETC_BASHRC"                 >> $configureFile
376
377   # ------------------      
378   # endif 'suitable'
379   fi 
380   ;;
381   
382   1)    
383      echo "===================================at begin 1) ======ETC_BASHRC : " $ETC_BASHRC
384      read a
385      echo "========================== 1 "
386      source scripts/Check-if-root.sh
387      bash scripts/ThirdParty-install-Base-Stuff.sh     
388      bash scripts/ThirdParty-install-VTK.sh
389      bash scripts/ThirdParty-install-gdcm.sh
390      bash scripts/ThirdParty-install-ITK.sh
391      bash scripts/ThirdParty-install.sh
392      bash scripts/ThirdParty-install-Finalize.sh 
393      echo "===================================after ThirdParty-install-Finalize.sh ======ETC_BASHRC : " $ETC_BASHRC
394
395      if [ "$sourcesFrom" = "CVS" ]
396      then
397         echo "----------------------------------------------------------------------"
398         echo OK
399         echo "To go on, run again 'bash menu.sh' as '$loginUserName', in a new window"
400         echo "---------------------------------------------------------------------"
401      else
402         echo "----------------------------------------------------------------------"
403         echo OK
404         echo "To go on, run again 'bash menu.sh'  in a new window"
405         echo "---------------------------------------------------------------------"
406      fi
407      echo
408      echo "==>"
409      echo "==> You HAVE to leave current window to continue!" 
410      echo "==>"
411      source $ETC_BASHRC
412      read a
413      kill -9 $PPID 
414   ;;
415
416   1.0)
417      echo "========================== 1.0 "
418      source scripts/Check-if-root.sh
419      bash scripts/ThirdParty-install-Base-Stuff.sh     
420      bash scripts/ThirdParty-install-Finalize.sh
421   ;;
422
423   1.1)
424      echo "========================== 1.1 "
425      #source scripts/Check-if-root.sh 
426      bash scripts/ThirdParty-install-VTK.sh  
427      bash scripts/ThirdParty-install-Finalize.sh      
428      read a       
429   ;;
430
431   1.2)
432      echo "========================== 1.2 "
433      #source scripts/Check-if-root.sh
434      bash scripts/ThirdParty-install-gdcm.sh
435      bash scripts/ThirdParty-install-Finalize.sh
436   ;;
437
438   1.3)
439      echo "========================== 1.3 "
440      #source scripts/Check-if-root.sh
441      bash scripts/ThirdParty-install-ITK.sh
442      bash scripts/ThirdParty-install-Finalize.sh         
443      read a
444   ;;
445
446   2)
447      #2.1
448      bash scripts/CreaTools-load.sh
449      #2.2
450      source scripts/CreaTools-configure.sh
451      bash scripts/CreaTools-compile.sh
452      #2.3
453      bash scripts/CreaTools-install.sh
454      echo "==>"
455      echo "==> You HAVE to leave current window to continue!"
456      echo "==>"
457      source $ETC_BASHRC
458      read a
459      kill -9 $PPID
460   ;;
461
462   2.1)
463      echo "========================== 2.1"
464      bash scripts/CreaTools-load.sh
465   ;;
466
467   2.2)
468      echo "========================== 2.2"
469      source scripts/CreaTools-configure.sh
470      
471      bash scripts/CreaTools-compile.sh
472
473      # To allow (*very* aware) user to patch code, later
474      if [ ! -e $generationdir/creatools_source ]
475      then
476         echo "You probabely made a mistake : "
477             echo "Directory $loginUserName $generationdir/creatools_source not found"
478             echo "Make sure you know the mistake"
479             echo "Hit any key to continue"
480             echo "Fix the mistake!"
481             read a
482      else
483         chown -R $loginUserName  $generationdir/creatools_source
484         chgrp -R $loginGroupName $generationdir/creatools_source
485     fi    
486   ;;
487
488   2.3)
489
490       echo "========================= 4"
491       
492       bash scripts/CreaTools-install.sh
493    
494 #      if [ $UID != 0 ]
495 #      then
496 #        echo "You HAVE to leave current window to continue!"
497 #      else
498 #        echo "==> Hit any key to close current window"
499 #      fi
500      source $ETC_BASHRC
501   ;;
502
503   5)
504    if [ $expanded = "NO" ]
505    then
506      expanded="YES"
507    else
508      expanded="NO"
509    fi
510   ;;
511
512   6)
513      echo "========================= 5"
514      bash scripts/CreaTools-uninstall.sh 
515      echo
516      echo "==> Hit any key to go on"
517      read a
518   ;;
519
520   7)
521      clear
522      echo "==================================="
523      more README.txt
524      echo
525      echo "==> Hit any key to go on" 
526      read a
527   ;;
528          
529   8)
530      clear
531      echo "==================================="
532      
533      # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
534      # If user configured without installing third party library,
535      # last third party library is still in use!  JPR
536
537
538      if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
539      then
540         echo WARNING
541         echo
542         echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
543         grep "installPrefixThird=" $ETC_BASHRC
544         echo "VTK_DIR  : " $VTK_DIR
545         echo "ITK_DIR  : " $ITK_DIR
546         echo "GDCM_DIR : " $GDCM_DIR
547         echo
548         echo "installPrefixThird ... " $installPrefixThird
549      fi
550              
551      if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
552      then
553         echo  "Third party config file : " $installPrefixThird/share/creatools_third_party_library_config.sh
554             echo  ------
555             more $installPrefixThird/share/creatools_third_party_library_config.sh
556             echo  ------
557      fi
558      
559      echo
560      
561      if [ -f $installPrefix/share/creatools_base_library_config.sh ]
562      then
563         echo  "Creatools base library config file : " $installPrefix/share/creatools_base_library_config.sh
564             echo  ------ 
565             more $installPrefix/share/creatools_base_library_config.sh
566             echo  ------ 
567             echo
568         echo "installPrefix ... " $installPrefix
569      fi
570      echo  ------
571         echo "VTK_DIR  :                 " $VTK_DIR
572         echo "ITK_DIR  :                 " $ITK_DIR
573         echo "GDCM_DIR :                 " $GDCM_DIR
574         echo
575         echo "crea_DIR :                 " $crea_DIR
576         echo "BBTK_DIR :                 " $BBTK_DIR
577         echo "creaMaracasVisu_DIR :      " $creaMaracasVisu_DIR
578         echo "creaEnvironment_DIR :      " $creaEnvironment_DIR
579         echo "creaBruker_DIR :           " $creaBruker_DIR
580         echo "creaImageIO_DIR :          " $creaImageIO_DIR
581         echo "creaContours_DIR :         " $creaContours_DIR
582         echo "creaRigidRegistration_DIR :" $creaRigidRegistration_DIR
583         echo "bbtkGEditor_DIR :          " $bbtkGEditor_DIR
584         echo "creaTools_DIR :            " $creaTools_DIR
585         echo "creaMiniTools_DIR :        " $creaMiniTools_DIR
586         echo "Ido_DIR :                  " $Ido_DIR
587         echo "==================================="
588         echo
589         echo "Press any key to continue"
590         read a
591    ;;
592
593   9) 
594     echo
595     exit 0
596     ;;
597
598   10)
599   # Hiden option, usefull at debug time
600     bash scripts/ThirdParty-install_no_compile.sh  
601     ;;
602       
603   *)
604
605   if [ expanded="NO" ]
606   then
607      echo "Your answer must be in {0, 1, 2, 5, 6, 7, 8, 9} (was [ $i ])"
608   else
609      echo "Your answer must be in {0, 1, 2.1, 2.2, 2.3, 5, 6, 7, 8, 9} (was [ $i ])"
610   fi
611   ;;
612   esac
613
614 done
615