]> Creatis software - creaToolsTools.git/blob - Linux/menu.sh
11727caf90cd25135c4e71ccf063352d6e93063f
[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  # ==> On le genere chez l'utilisateur (no choice!)...
289  # 
290
291    configureFile="scripts/CreaTools-configure.sh"
292    touch  $configureFile
293    echo "#!/bin/bash"                            >  $configureFile
294    echo                                          >> $configureFile
295    echo "#File generated by 'menu.sh'"           >> $configureFile
296    echo "#DO NOT edit !"                         >> $configureFile
297    echo "#(except if you *know* what you do)"    >> $configureFile
298    echo                                          >> $configureFile
299    echo "OperatingSystem=$OperatingSystem"       >> $configureFile
300    echo "generationdir=$generationdir"           >> $configureFile
301    echo "installPrefix=$installPrefix"           >> $configureFile
302    echo "installPrefixThird=$installPrefixThird" >> $configureFile
303    echo "docgeneration=$docgeneration"           >> $configureFile
304    echo "sourcesFrom=$sourcesFrom"               >> $configureFile
305    echo "cvsUserName=$cvsUserName"               >> $configureFile 
306    echo "loginUserName=$loginUserName"           >> $configureFile
307    echo "loginGroupName=$loginGroupName"         >> $configureFile
308    echo "buildType=$buildType"                   >> $configureFile
309    echo "gdcmVersion=$gdcmVersion"               >> $configureFile
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      if [ "$sourcesFrom" = "CVS" ]
322      then
323         echo "----------------------------------------------------------------------"
324         echo OK
325         echo "To go on, run again 'bash menu.sh' as '$loginUserName', in a new window"
326         echo "---------------------------------------------------------------------"
327      else
328         echo "----------------------------------------------------------------------"
329         echo OK
330         echo "To go on, run again 'bash menu.sh'  in a new window"
331         echo "---------------------------------------------------------------------"
332      fi
333      echo
334      echo "==> Hit any key to exit close current window" 
335      read a
336      kill $PPID    
337   ;;
338
339   2)
340      echo "========================== 2" 
341      bash scripts/CreaTools-load.sh
342   ;;
343
344   3)
345      echo "========================== 3"
346      source scripts/CreaTools-configure.sh
347      
348      bash scripts/CreaTools-compile.sh
349
350      # To allow (*very* aware) user to patch code, later
351      if [ ! -e $generationdir/creatools_source ]
352      then
353         echo "You probabely made a mistake : "
354             echo "Directory $loginUserName $generationdir/creatools_source not found"
355             echo "Make sure you know the mistake"
356             echo "Hit any key to continue"
357             echo "Fix the mistake!"
358             read a
359      else
360         chown -R $loginUserName  $generationdir/creatools_source
361         chgrp -R $loginGroupName $generationdir/creatools_source
362         # Too much time consuming
363         #chown -R $loginUserName $generationdir/creatools_source 
364         #chgrp -R $loginGroupName $generationdir/creatools_source
365     fi    
366   ;;
367   
368   4)
369
370 #      if [ $UID != 0 ]
371 #      then
372 #         echo
373 #         echo "..ERROR.."
374 #         echo "==================================================="
375 #         echo "REMEMBER !"
376 #         echo ""
377 #         echo "YOU NEED TO RUN THIS ONE AS root"
378 #         echo "==================================================="
379 #         echo
380 #         echo
381 #         exit 0
382 #      fi
383
384       echo "========================= 4"
385       bash scripts/CreaTools-install.sh
386       
387    
388 #      if [ $UID != 0 ]
389 #      then
390 #        echo "You HAVE to leave current window to continue!"
391 #      else
392 #        echo "==> Hit any key to close current window"
393 #      fi
394
395
396       echo "You HAVE to leave current window to continue!"
397       read a
398       kill $PPID     
399   ;;
400  
401   5)
402      echo "========================= 5"
403      bash scripts/CreaTools-uninstall.sh 
404      echo
405      echo "==> Hit any key to go on"
406      read a
407   ;;
408
409   7)
410      clear
411      echo "==================================="
412      more README.txt
413      echo
414      echo "==> Hit any key to go on" 
415      read a
416   ;;
417          
418   8)
419      clear
420      echo "==================================="
421      
422      # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
423      # if user configured without installing third party library,
424      # Last third party library is still in use!  JPR
425
426
427      if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
428      then
429         echo WARNING
430         echo
431         echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
432         grep "installPrefixThird=" /etc/bashrc
433         echo "VTK_DIR :...." $VTK_DIR
434         echo "ITK_DIR :...." $ITK_DIR
435         echo "GDCM_DIR :..." $GDCM_DIR
436         echo
437         echo "installPrefixThird ... " $installPrefixThird
438      fi
439              
440      if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
441      then
442         echo  $installPrefixThird/share/creatools_third_party_library_config.sh
443         echo  ------
444         more $installPrefixThird/share/creatools_third_party_library_config.sh
445         echo  ------
446      fi
447      
448      echo
449      
450      if [ -f $installPrefix/share/creatools_base_library_config.sh ]
451      then
452         echo  $installPrefix/share/creatools_base_library_config.sh
453         echo  ------ 
454         more $installPrefix/share/creatools_base_library_config.sh
455         echo  ------ 
456         echo
457         echo "installPrefix ... " $installPrefix
458      fi 
459      echo  ------
460         echo "VTK_DIR :...." $VTK_DIR
461         echo "ITK_DIR :...." $ITK_DIR
462         echo "GDCM_DIR :..." $GDCM_DIR
463         echo "CREA_DIR :...................." $CREA_DIR
464         echo "BBTK_DIR :...................." $BBTK_DIR
465         echo "CREAMARACASVISU_DIR :........." $CREAMARACASVISU_DIR
466         echo "CREAENVIRONMENT_DIR :........." $CREAENVIRONMENT_DIR
467         echo "CREABRUKER_DIR :.............." $CREABRUKER_DIR
468         echo "CREAIMAGEIO_DIR :............." $CREAIMAGEIO_DIR
469         echo "CREACONTOUR_DIR :............." $CREACONTOUR_DIR
470         echo "CREARIGIDREGISTRATION_DIR :..." $CREAIGIDREGISTRATION_DIR
471         echo "CREABTKGEDITOR_DIR :.........." $CREABTKGEDITOR_DIR
472         echo "CREATOOLS_DIR :..............." $CREATOOLS_DIR    
473                                     
474         echo "==================================="
475         echo
476         echo "Press any key to continue"
477         read a
478    ;;
479                
480   9) 
481   echo 
482   exit 0
483   ;;
484    
485   *)
486   echo "Your answer must be in {0, 1, 2, 3, 4, 5, 7, 8, 9} (was [ $i ])"
487   ;;
488   esac
489
490 done
491