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