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