]> Creatis software - creaToolsTools.git/blob - Linux/menu.sh
a965358a6cd4af655677bb7b6cd653db7b8548f0
[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 i=999
9 while [ "$i" != 9 ]
10 do
11    clear
12    echo
13    echo
14    echo
15    echo "                MENU"
16    echo
17    echo " Choose what you want to do :"
18    echo  
19    echo " Configure :........................0 "
20    echo " Install Third Party Libraries :....1 (as root)"
21    echo " Get the 'CreaTools' source files :.2 (CVS : as user!)" 
22    echo " Compile   the CreaTools :..........3 "
23    echo " Install   the CreaTools :..........4 (as root)"
24    echo " Uninstall the CreaTools :..........5 (as root)"
25    echo
26    echo " Help ..............................7 Help about this menu"   
27    echo " Show some Environment Variables ...8"
28    echo " Exit :.............................9"
29    echo
30    echo
31    echo 
32
33   echo "Type in your choice :"
34   read i
35
36   case $i in
37   0)
38   clear
39   suitable=XXX
40   #ls -l  scripts/CreaTools-configure.sh
41   if [ -f scripts/CreaTools-configure.sh ]
42   then
43      while [[ "$suitable" != "YES" && \
44               "$suitable" != "yes" && \
45               "$suitable" != "Y"   && \
46               "$suitable" != "y"   && \
47               "$suitable" != "NO"  && \
48               "$suitable" != "no"  ]]
49      do   
50         echo "'Configure' already done : "
51         echo "------------------------"
52         more scripts/CreaTools-configure.sh
53         echo "------------------------"
54         
55         # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
56         # if user configured without installing third party library,
57         # Last third party library is still in use!  JPR
58         
59         
60         
61         if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
62         then
63               echo WARNING
64               echo
65               if [ ! -f /etc/bashrc ]
66               then
67                  echo
68                  echo "You are probabely running under UBUNTU OS  ?"
69                  echo "Troubles expected! (Hope NO!)"
70                  echo   
71                  echo "Hit any key to continue"
72                  read a
73                  echo export ETC_BASHRC="/etc/bash.bashrc"
74               else
75                  echo export ETC_BASHRC="/etc/bashrc"
76               fi              
77               echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
78                  
79               grep "installPrefixThird=" $ETC_BASHRC 
80               echo "VTK_DIR :...." $VTK_DIR
81               echo "ITK_DIR :...." $ITK_DIR
82               echo "GDCM_DIR :..." $GDCM_DIR
83               echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
84         fi
85         echo    
86         echo "Are these values suitable for you : YES/NO? (default is YES)"
87         read suitable
88         if [ "$suitable" = "" ]
89         then
90            suitable="YES"
91         fi
92      done
93   else
94      suitable="NO"
95   fi
96   
97   if [[ "$suitable" = "YES" || "$suitable" = "Y" || "$suitable" = "yes" || "$suitable" = "y" ]]
98   then
99      source scripts/CreaTools-configure.sh
100   fi
101   
102  if [[ "$suitable" = "NO" || "$suitable" = "N"  || "$suitable" = "no" || "$suitable" = "n" ]]
103  #if [ "$suitable" = "NO" ]
104   then
105      echo
106      echo
107      confirm="NO"
108      while [ "$confirm" != "YES" ]
109      do
110      
111         OperatingSystem="XXX"
112         while [[ "$OperatingSystem" != "Fedora" && \
113                  "$OperatingSystem" != "Ubuntu" && \
114                  "$OperatingSystem" != "MacOS" ]]
115         do
116            echo "Operating System : Fedora/Ubuntu/MacOS (default : Fedora)"
117            read OperatingSystem
118            if [ "$OperatingSystem" = "" ]
119            then
120              OperatingSystem="Fedora"
121            fi  
122         done
123         echo "you said : [" $OperatingSystem "]"
124         echo
125         echo
126
127         # ------------------
128         echo "Name of the Generation Directory (default is /tmp/myGenerationDir)"
129         read generationdir
130         if [ "$generationdir" = "" ]
131         then
132            generationdir="/tmp/myGenerationDir"
133         fi
134         echo "you said : [" $generationdir "]"
135
136         echo
137         echo
138         # ------------------
139         installPrefixThird="___"
140         echo "Install Prefix For Third Party Library : '$generationdir/thirdparty_install' / '/usr/local' (default is '$generationdir/thirdparty_install')"
141         read installPrefixThird
142         if [ "$installPrefixThird" = "" ]
143         then
144            installPrefixThird="$generationdir/thirdparty_install"
145         fi
146         echo "you said : [" $installPrefixThird "]"
147         echo
148         echo 
149         # ------------------
150
151
152         installPrefix="___"
153         echo "Install Prefix for CreaTools : '$generationdir/creatools_install' / '/usr/local' (default is '$generationdir/creatools_install')"
154         read installPrefix
155         if [ "$installPrefix" = "" ]
156         then
157            installPrefix="$generationdir/creatools_install"
158         fi
159         echo "you said : [" $installPrefix "]"
160         echo
161         echo 
162         # ------------------
163
164         docgeneration="___"
165         while [[ "$docgeneration" != "ON"  && "$docgeneration" != "OFF" ]]
166         do
167            echo "Boolean For Doc Generation : ON/OFF (default is OFF)"
168            read docgeneration
169           if [ "$docgeneration" = "" ]
170           then
171              docgeneration="OFF"
172           fi
173           echo "you said : [" $docgeneration "]"
174         done
175         echo
176         echo
177         # ------------------
178
179         sourcesFrom="___"
180         while [[ "$sourcesFrom" != "CVS"  && "$sourcesFrom" != "HTML" ]]
181         do
182            echo "Where do you want to get source files from : CVS/HTML (default is CVS)"
183            read sourcesFrom
184            if [ "$sourcesFrom" = "" ]
185            then
186               sourcesFrom="CVS"
187            fi
188            echo "you said : [" $sourcesFrom "]"
189         done
190         echo
191         echo
192         # ------------------
193
194         cvsUserName=""
195         if [ "$sourcesFrom" = "CVS" ]
196         then
197            while [ "$cvsUserName" == "" ]
198            do
199               echo "CVS User Name (mandatory!)"
200               read cvsUserName
201            done
202            echo "you said : [" $cvsUserName "]"
203         else
204            cvsUserName="ForgetThisOne" 
205         fi
206         echo
207         echo
208         # ------------------
209
210
211         loginUserName=""
212         while [ "$loginUserName" == "" ]
213         do 
214            echo "Have a look at the following line to know 'Login User Name'/'Login Group Name'"
215            ls -l menu.sh
216            echo "Login User Name (mandatory!)"
217            read loginUserName  
218            echo "you said : [" $loginUserName "]"  
219         done
220         echo
221         echo
222
223         loginGroupName=""
224         while [ "$loginGroupName" == "" ]
225         do
226             #echo "Have a look at the following line to know 'Login User Name'/'Login Group Name'"
227             #echo "Login Group Name (mandatory!)"
228            echo "Login Group Name (mandatory!)"
229            read loginGroupName  
230            echo "you said : [" $loginGroupName "]"  
231         done
232         echo
233         echo
234         # ------------------
235
236         buildType="___"
237         while [[ "$buildType" != "Release"  && "$buildType" != "Debug" ]]
238         do
239            echo "Build type : Release/Debug (default is Release)"
240            read buildType
241            if [ "$buildType" = "" ]
242            then
243               buildType="Release"
244            fi
245            echo "you said : [" $buildType "]"
246         done
247         echo
248         echo
249         # ------------------
250
251         gdcmVersion="___"
252         while [[ "$gdcmVersion" != "GDCM1"  && "$gdcmVersion " != "GDCM2" ]]
253         do
254            echo "Gdcm version : GDCM1/GDCM2 (default is GDCM1)"
255            read gdcmVersion
256            if [ "$gdcmVersion" = "" ]
257            then
258               gdcmVersion="GDCM1"
259            fi
260            echo "you said : [" $gdcmVersion "]"
261         done
262         echo
263         echo
264         echo
265         echo
266         echo "You said :"
267         echo "  Operating System                           : $OperatingSystem"
268         echo "  Name of the Generation Directory           : $generationdir"
269         echo "  Install Prefix for Third Party Libraries   : $installPrefixThird"       
270         echo "  Install Prefix for CreaTools               : $installPrefix"
271         echo "  Boolean for Doc Generation                 : $docgeneration"
272         echo "  Where do you want to get source files from : $sourcesFrom"
273         if [ $sourcesFrom = CVS ]
274         then
275            echo "  CVS User Name                              : $cvsUserName"
276         fi
277         echo "  Login User Name                            : $loginUserName"
278         echo "  Login Group Name                           : $loginGroupName"
279         echo "  Build type                                 : $buildType"          
280         echo "  Gdcm version                               : $gdcmVersion"
281         echo
282         echo
283      
284         echo "Do you confirm your choices : YES/NO ? (default is YES)"
285         read confirm
286         if [ "$confirm" = "" ]
287         then
288            confirm=YES
289         fi
290    done
291
292  # GROS SOUCIS : Ou generer le fichier CreaTools-configure.sh?
293  # dans $generationdir/creatools_bin ?
294  # -> il n'est pas encore cree !
295  # dans ./Linux/scripts?
296  # -> ? 
297
298    configureFile="scripts/CreaTools-configure.sh"
299    touch  $configureFile
300    echo "#!/bin/bash"                            >  $configureFile
301    echo                                          >> $configureFile
302    echo "#File generated by 'menu.sh'"           >> $configureFile
303    echo "#DO NOT edit !"                         >> $configureFile
304    echo "#(except if you *know* what you do)"    >> $configureFile
305    echo                                          >> $configureFile
306    echo "OperatingSystem=$OperatingSystem"       >> $configureFile
307    echo "generationdir=$generationdir"           >> $configureFile
308    echo "installPrefix=$installPrefix"           >> $configureFile
309    echo "installPrefixThird=$installPrefixThird" >> $configureFile
310    echo "docgeneration=$docgeneration"           >> $configureFile
311    echo "sourcesFrom=$sourcesFrom"               >> $configureFile
312    echo "cvsUserName=$cvsUserName"               >> $configureFile 
313    echo "loginUserName=$loginUserName"           >> $configureFile
314    echo "loginGroupName=$loginGroupName"         >> $configureFile
315    echo "buildType=$buildType"                   >> $configureFile
316    echo "gdcmVersion=$gdcmVersion"               >> $configureFile
317    
318
319   # ------------------      
320   # endif 'suitable'
321   fi 
322   ;;
323   
324   1)
325      echo "========================== 1 "
326      source scripts/Check-if-root.sh
327      bash scripts/ThirdParty-install.sh
328      
329 #      vtkdirVariable=""
330 #      while [ "$vtkdirVariable" = "" ]
331 #      do
332 #         while [ ! -e "$vtkdirVariable" ]
333 #         do
334 #            echo
335 #          echo " --------------------------------"
336 #            echo " Set VTK_DIR environment variable"
337 #          echo " --------------------------------"
338 #            echo               
339 # #            #read vtkdirVariable
340 #          if [  ! -e "$vtkdirVariable" ]
341 #          then
342 # #           echo $vtkdirVariable is NOT a valid directory
343 #          fi
344 #         done
345 #      done
346 #      echo "you said [" $vtkdirVariable "]"
347
348      #vtkdirVariable=""
349      #while [ "$vtkdirVariable" = "" ]
350      #do
351      #   echo " Set VTK_DIR environment variable"
352       #  read vtkdirVariable
353      #done
354      #echo "you said [" $vtkdirVariable "]"
355           
356 #      latexCompilerVariable=""
357 #      while [ "$latexCompilerVariable" = "" ]
358 #      do
359 #         while [ ! -f "$latexCompilerVariable" ]
360 #         do 
361 #          echo
362 # #        echo " ---------------------------------------"
363 #            echo " Set LATEX_COMPILER environment variable"
364 # #        echo " ---------------------------------------"
365 #            echo               
366 #            read latexCompilerVariable
367 #          if [  ! -e "$latexCompilerVariable" ]
368 #          then
369 #             echo $latexCompilerVariable is NOT a valid file
370 #          fi
371 # #     done
372 #      done
373 #      echo "you said [" $latexCompilerVariable "]"     
374
375 #     sed -i -e '/.*VTK_DIR*/ d'        $ETC_BASHRC
376 #     sed -i -e '/.*LATEX_COMPILER*/ d' $ETC_BASHRC 
377 #     echo "export VTK_DIR=$vtkdirVariable" >> $ETC_BASHRC
378 #     echo "export LATEX_COMPILER=$latexCompilerVariable" >> $ETC_BASHRC
379
380      if [ "$sourcesFrom" = "CVS" ]
381      then
382         echo "----------------------------------------------------------------------"
383         echo OK
384         echo "To go on, run again 'bash menu.sh' as '$loginUserName', in a new window"
385         echo "---------------------------------------------------------------------"
386      else
387         echo "----------------------------------------------------------------------"
388         echo OK
389         echo "To go on, run again 'bash menu.sh'  in a new window"
390         echo "---------------------------------------------------------------------"
391      fi
392      echo
393      echo "==> Hit any key to exit close current window" 
394      read a
395      kill $PPID    
396   ;;
397
398   2)
399     
400      
401      echo "========================== 2" 
402      bash scripts/CreaTools-load.sh
403   ;;
404   
405   3)
406      echo "========================== 3"
407      source scripts/CreaTools-configure.sh
408      bash scripts/CreaTools-compile.sh
409      
410      # To allow (*very* aware) user to patch code, later
411   
412      chown -R $loginUserName $generationdir/creatools_source
413      chgrp -R $loginGroupName $generationdir/creatools_source
414      # Too much time consuming
415      #chown -R $loginUserName $generationdir/creatools_source 
416      #chgrp -R $loginGroupName $generationdir/creatools_source     
417   ;;
418   
419   4) 
420       if [ $UID != 0 ] 
421       then
422          echo
423          echo "..ERROR.."
424          echo "==================================================="
425          echo "REMEMBER !"
426          echo ""
427          echo "YOU NEED TO RUN THIS ONE AS root"
428          echo "==================================================="
429          echo
430          echo
431          exit 0
432       fi
433       echo "========================= 4"
434       bash scripts/CreaTools-install.sh 
435      echo
436      echo "==> Hit any key to close current window" 
437      read a
438      kill $PPID        
439   ;;
440  
441   5)
442      echo "========================= 5"
443      bash scripts/CreaTools-uninstall.sh
444   ;;
445
446   7)
447      clear
448      echo "==================================="
449      more README.txt
450       echo
451      echo "==> Hit any key to go on" 
452      read a
453   ;;
454          
455   8)
456      clear
457      echo "==================================="
458      
459      # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
460      # if user configured without installing third party library,
461      # Last third party library is still in use!  JPR
462
463
464      if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
465      then
466               echo WARNING
467               echo
468               echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
469               grep "installPrefixThird=" /etc/bashrc    
470               echo "VTK_DIR :...." $VTK_DIR
471               echo "ITK_DIR :...." $ITK_DIR
472               echo "GDCM_DIR :..." $GDCM_DIR
473      fi
474              
475      if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
476      then
477         echo  $installPrefixThird/share/creatools_third_party_library_config.sh
478         echo  ------
479         more $installPrefixThird/share/creatools_third_party_library_config.sh
480         echo  ------
481      fi
482      
483      echo
484      
485      if [ -f $installPrefix/share/creatools_base_library_config.sh ]
486      then
487         echo  $installPrefix/share/creatools_base_library_config.sh
488         echo  ------ 
489         more $installPrefix/share/creatools_base_library_config.sh
490         echo  ------ 
491      fi   
492      echo "==================================="
493      echo
494      echo "Press any key to continue"
495      read a
496    ;;
497                
498   9) 
499   echo 
500   exit 0
501   ;;
502    
503   *)
504   echo "Your answer must be in {0, 1, 2, 3, 4, 5, 9} (was [ $i ])"
505   ;;
506   esac
507
508 done
509