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