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