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