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