]> Creatis software - creaToolsTools.git/blob - Linux/menu.sh
Avoid infinire loop
[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 "========================== 1 "
384      source scripts/Check-if-root.sh
385      bash scripts/ThirdParty-install-Base-Stuff.sh     
386      bash scripts/ThirdParty-install-VTK.sh
387      bash scripts/ThirdParty-install-gdcm.sh
388      bash scripts/ThirdParty-install-ITK.sh
389      bash scripts/ThirdParty-install.sh
390      bash scripts/ThirdParty-install-Finalize.sh
391
392      if [ "$sourcesFrom" = "CVS" ]
393      then
394         echo "----------------------------------------------------------------------"
395         echo OK
396         echo "To go on, run again 'bash menu.sh' as '$loginUserName', in a new window"
397         echo "----------------------------------------------------------------------"
398      else
399         echo "----------------------------------------------------------------------"
400         echo OK
401         echo "To go on, run again 'bash menu.sh'  in a new window"
402         echo "----------------------------------------------------------------------"
403      fi
404      echo
405      echo "==>"
406      echo "==> You HAVE to leave current window to continue!" 
407      echo "==>"
408      source $ETC_BASHRC
409      read a
410   ;;
411
412   1.0)
413      echo "========================== 1.0 "
414      source scripts/Check-if-root.sh
415      bash scripts/ThirdParty-install-Base-Stuff.sh     
416      bash scripts/ThirdParty-install-Finalize.sh
417   ;;
418
419   1.1)
420      echo "========================== 1.1 "
421      #source scripts/Check-if-root.sh 
422      bash scripts/ThirdParty-install-VTK.sh  
423      bash scripts/ThirdParty-install-Finalize.sh
424   ;;
425
426   1.2)
427      echo "========================== 1.2 "
428      #source scripts/Check-if-root.sh
429      bash scripts/ThirdParty-install-gdcm.sh
430      bash scripts/ThirdParty-install-Finalize.sh
431   ;;
432
433   1.3)
434      echo "========================== 1.3 "
435      #source scripts/Check-if-root.sh
436      bash scripts/ThirdParty-install-ITK.sh
437      bash scripts/ThirdParty-install-Finalize.sh         
438   ;;
439
440   2)
441      #2.1
442      bash scripts/CreaTools-load.sh
443      #2.2
444      source scripts/CreaTools-configure.sh
445      bash scripts/CreaTools-compile.sh
446      #2.3
447      bash scripts/CreaTools-install.sh
448      echo "==>"
449      echo "==> You HAVE to leave current window to continue!"
450      echo "==>"
451      source $ETC_BASHRC
452      read a
453      kill -9 $PPID
454   ;;
455
456   2.1)
457      echo "========================== 2.1"
458      bash scripts/CreaTools-load.sh
459   ;;
460
461   2.2)
462      echo "========================== 2.2"
463      source scripts/CreaTools-configure.sh
464      
465      bash scripts/CreaTools-compile.sh
466
467      # To allow (*very* aware) user to patch code, later
468      if [ ! -e $generationdir/creatools_source ]
469      then
470         echo "You probabely made a mistake : "
471             echo "Directory $loginUserName $generationdir/creatools_source not found"
472             echo "Make sure you know the mistake"
473             echo "Hit any key to continue"
474             echo "Fix the mistake!"
475             read a
476      else
477         chown -R $loginUserName  $generationdir/creatools_source
478         chgrp -R $loginGroupName $generationdir/creatools_source
479     fi    
480   ;;
481
482   2.3)
483
484       echo "========================= 4"
485       
486       bash scripts/CreaTools-install.sh
487    
488 #      if [ $UID != 0 ]
489 #      then
490 #        echo "You HAVE to leave current window to continue!"
491 #      else
492 #        echo "==> Hit any key to close current window"
493 #      fi
494      source $ETC_BASHRC
495   ;;
496
497   5)
498    if [ $expanded = "NO" ]
499    then
500      expanded="YES"
501    else
502      expanded="NO"
503    fi
504   ;;
505
506   6)
507      echo "========================= 5"
508      bash scripts/CreaTools-uninstall.sh 
509      echo
510      echo "==> Hit any key to go on"
511      read a
512   ;;
513
514   7)
515      clear
516      echo "==================================="
517      more README.txt
518      echo
519      echo "==> Hit any key to go on" 
520      read a
521   ;;
522          
523   8)
524      clear
525      echo "==================================="
526      
527      # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
528      # If user configured without installing third party library,
529      # last third party library is still in use!  JPR
530
531
532      if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
533      then
534         echo WARNING
535         echo
536         echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
537         grep "installPrefixThird=" $ETC_BASHRC
538         echo "VTK_DIR  : " $VTK_DIR
539         echo "ITK_DIR  : " $ITK_DIR
540         echo "GDCM_DIR : " $GDCM_DIR
541         echo
542         echo "installPrefixThird ... " $installPrefixThird
543      fi
544              
545      if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
546      then
547         echo  "Third party config file : " $installPrefixThird/share/creatools_third_party_library_config.sh
548             echo  ------
549             more $installPrefixThird/share/creatools_third_party_library_config.sh
550             echo  ------
551      fi
552      
553      echo
554      
555      if [ -f $installPrefix/share/creatools_base_library_config.sh ]
556      then
557         echo  "Creatools base library config file : " $installPrefix/share/creatools_base_library_config.sh
558             echo  ------ 
559             more $installPrefix/share/creatools_base_library_config.sh
560             echo  ------ 
561             echo
562         echo "installPrefix ... " $installPrefix
563      fi
564      echo  ------
565         echo "VTK_DIR  :                 " $VTK_DIR
566         echo "ITK_DIR  :                 " $ITK_DIR
567         echo "GDCM_DIR :                 " $GDCM_DIR
568         echo
569         echo "crea_DIR :                 " $crea_DIR
570         echo "BBTK_DIR :                 " $BBTK_DIR
571         echo "creaMaracasVisu_DIR :      " $creaMaracasVisu_DIR
572         echo "creaEnvironment_DIR :      " $creaEnvironment_DIR
573         echo "creaBruker_DIR :           " $creaBruker_DIR
574         echo "creaImageIO_DIR :          " $creaImageIO_DIR
575         echo "creaContours_DIR :         " $creaContours_DIR
576         echo "creaRigidRegistration_DIR :" $creaRigidRegistration_DIR
577         echo "bbtkGEditor_DIR :          " $bbtkGEditor_DIR
578         echo "creaTools_DIR :            " $creaTools_DIR
579         echo "creaMiniTools_DIR :        " $creaMiniTools_DIR
580         echo "Ido_DIR :                  " $Ido_DIR
581         echo "==================================="
582         echo
583         echo "Press any key to continue"
584         read a
585    ;;
586
587   9) 
588     echo
589     exit 0
590     ;;
591
592   10)
593   # Hiden option, usefull at debug time
594     bash scripts/ThirdParty-install_no_compile.sh  
595     ;;
596       
597   *)
598
599   if [ expanded="NO" ]
600   then
601      echo "Your answer must be in {0, 1, 2, 5, 6, 7, 8, 9} (was [ $i ])"
602   else
603      echo "Your answer must be in {0, 1, 2.1, 2.2, 2.3, 5, 6, 7, 8, 9} (was [ $i ])"
604   fi
605   ;;
606   esac
607
608 done
609