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