]> Creatis software - creaToolsTools.git/blobdiff - Linux/menu.sh
avoid touch + rm + touch
[creaToolsTools.git] / Linux / menu.sh
index 27918154ebdd5e3f047df6f9bc6d1e1d57a06016..b902fedfad30faab2d169ce7ef48b617f615859a 100644 (file)
-#!/bin/sh
-
-if [ $UID != 0 ] 
-then
-  echo
-  echo "..ERROR.."
-  echo "==================================================="
-  echo "REMEMBER !"
-  echo ""
-  echo "YOU NEED TO RUN THIS ONE AS root"
-  echo "==================================================="
-  echo
-  echo
-  exit 0
+#!/bin/bash -e
+
+  if [ -f scripts/CreaTools-configure.sh ]
+  then
+     source scripts/CreaTools-configure.sh
+  fi
 
-else
- i=999
-while [ $i != 9 ]
+i=999
+while [ "$i" != 9 ]
 do
+   clear
+   echo
+   echo
+   echo
+   echo "                MENU"
+   echo
+   echo " Choose what you want to do :"
+   echo  
+   echo " Configure :........................0 "
+   echo " Install Third Party Libraries :....1 (as root)"
+   echo " Get the 'CreaTools' source files :.2 (CVS : as user!)" 
+   echo " Compile   the CreaTools :..........3 "
+   echo " Install   the CreaTools :..........4 (as root)"
+   echo " Uninstall the CreaTools :..........5 (as root)"
+   echo
+   echo " Help ..............................7 Help about this menu"   
+   echo " Show some Environment Variables ...8"
+   echo " Exit :.............................9"
+   echo
+   echo
+   echo 
 
-echo
-echo
-echo
-echo "                   MENU"
-echo
-echo " Choose what you want to do :"
-echo  
-echo " Configure :                     0"
-echo " Install Third Party Libraries : 1"
-echo " Compile   the CreaTools :       2"
-echo " Install   the CreaTools :       3"
-echo " Uninstall the CreaTools :       4"
-echo
-echo " Exit :                          9"
-echo
-echo
-echo 
-
-echo "Type in your choice :"
-read i
+  echo "Type in your choice :"
+  read i
 
   case $i in
   0)
-echo
-echo
-  confirm="NO"
-  while [ "$confirm" != "YES" ]
-  do
-  OperatingSystem="XXX"
-  while [[ "$OperatingSystem" != "Fedora" && \
-           "$OperatingSystem" != "Ubuntu" && \
-          "$OperatingSystem" != "MacOS" ]]
-  do
-  echo "Operating System : Fedora/Ubuntu/MacOS (mandatory!)"
-  read OperatingSystem
-  done
-  echo "you said : [" $OperatingSystem "]"
-echo
-echo
-  # ------------------
-  
-  
-  # ------------------
-  echo "Name of the Generation Directory (default is /tmp/myGenerationDir)"
-  read generationdir
-  if [ "$generationdir" = "" ]
-  then
-     generationdir="/tmp/myGenerationDir"
-  fi
-  echo "you said : [" $generationdir "]"
-echo
-echo
-  # ------------------
-
-  installPrefix="XXX"
-     echo "Install Prefix : '$generationdir/creatools_install' / '/usr/local' (default is '$generationdir/creatools_install')"
-     read installPrefix
-  if [ "$installPrefix" = "" ]
-  then
-     installPrefix="$generationdir/creatools_install"
-  fi
-  echo "you said : [" $installPrefix "]"
-echo
-echo 
-  # ------------------
-
-  docgeneration="XXX"
-  while [[ "$docgeneration" != "YES"  && "$docgeneration" != "NO" ]]
-  do
-  echo "Boolean For Doc Generation : YES/NO (default is NO)"
-  read docgeneration
-  if [ "$docgeneration" = "" ]
-  then
-     docgeneration="NO"
-  fi
-  echo "you said : [" $docgeneration "]"
-  done
-echo
-echo
-  # ------------------
-
-  sourcesFrom="XXX"
-  while [[ "$sourcesFrom" != "CVS"  && "$sourcesFrom" != "HTML" ]]
-  do
-  echo "Where do you want to get source files from : CVS/HTML (default is HTML)"
-  read sourcesFrom
-  if [ "$sourcesFrom" = "" ]
+  clear
+  suitable=XXX
+  #ls -l  scripts/CreaTools-configure.sh
+  if [ -f scripts/CreaTools-configure.sh ]
   then
-     sourcesFrom="HTML"
-  fi
-  echo "you said : [" $sourcesFrom "]"
-  done
-echo
-echo
-  # ------------------
-  
-  cvsUserName=""
-  if [ "$sourcesFrom" = "CVS" ]
-  then
-  while [ "$cvsUserName" == "" ]
-  do
-     echo "CVS User Name (mandatory!)"
-     read cvsUserName
-  done
-  echo "you said : [" $cvsUserName "]"
+     while [[ "$suitable" != "YES" && \
+              "$suitable" != "yes" && \
+              "$suitable" != "Y"   && \
+              "$suitable" != "y"   && \
+              "$suitable" != "NO"  && \
+              "$suitable" != "no"  ]]
+     do          
+        echo "'Configure' already done : "
+        echo "------------------------"
+        more scripts/CreaTools-configure.sh
+        echo "------------------------"
+       
+       # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
+        # if user configured without installing third party library,
+        # Last third party library is still in use!  JPR
+
+
+        if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
+        then
+              echo WARNING
+              echo
+             if [ ! -f /etc/bashrc ]
+             then
+                echo
+                echo "You are probabely running under UBUNTU OS  ?"
+                echo "Troubles expected! (Hope NO!)"
+                echo   
+                echo "Hit any key to continue"
+                 read a
+                echo export ETC_BASHRC="/etc/bash.bashrc"
+              else
+                 echo export ETC_BASHRC="/etc/bashrc"
+              fi             
+              echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
+                
+              grep "installPrefixThird=" $ETC_BASHRC 
+              echo "VTK_DIR :...." $VTK_DIR
+              echo "ITK_DIR :...." $ITK_DIR
+              echo "GDCM_DIR :..." $GDCM_DIR
+             echo "(Have a look at $ETC_BASHRC=, edit it or run again Install Third Party Libraries if you disagree)"
+        fi
+       echo    
+        echo "Are these values suitable for you : YES/NO? (default is YES)"
+        read suitable
+        if [ "$suitable" = "" ]
+        then
+           suitable="YES"
+        fi
+     done
   else
-    cvsUserName="cvsUserNameCannotBeEmpty" 
+     suitable="NO"
   fi
-echo
-echo
-  # ------------------
-
-  linuxUserName=""
-  while [ "$linuxUserName" == "" ]
-  do
-     echo "LINUX/MacOS User Name (mandatory!)"
-     read linuxUserName  
-     echo "you said : [" $linuxUserName "]"  
-  done
-echo
-echo
-  # ------------------
   
-  buildType="XXX"
-  while [[ "$buildType" != "Release"  && "$Debug " != "HTML" ]]
-  do
-  echo "Build type : Release/Debug (default is Release)"
-  read buildType
-  if [ "$buildType" = "" ]
+  if [[ "$suitable" = "YES" || "$suitable" = "Y" || "$suitable" = "yes" || "$suitable" = "y" ]]
   then
-     buildType="Release"
+     source scripts/CreaTools-configure.sh
   fi
-  echo "you said : [" $buildType "]"
-  done
-echo
-echo
-  # ------------------
   
-  gdcmVersion="XXX"
-  while [[ "$gdcmVersion" != "GDCM1"  && "$gdcmVersion " != "GDCM2" ]]
-  do
-  echo "Gdcm version : GDCM1/GDCM2 (default is GDCM1)"
-  read gdcmVersion
-  if [ "$gdcmVersion" = "" ]
+ if [[ "$suitable" = "NO" || "$suitable" = "N"  || "$suitable" = "no" || "$suitable" = "n" ]]
+ #if [ "$suitable" = "NO" ]
   then
-     gdcmVersion="GDCM1"
-  fi
-  echo "you said : [" $gdcmVersion "]"
-  done
-echo
-echo
-echo
-echo
-echo "You said :"
-echo "           Operating System                           : $OperatingSystem"
-echo "           Name of the Generation Directory           : $generationdir"
-echo "           Install Prefix                             : $installPrefix"
-echo "           Boolean For Doc Generation                 : $docgeneration"
-echo "           Where do you want to get source files from : $sourcesFrom"
-if [ $sourcesFrom = CVS ]
-then
-echo "           CVS User Name                              : $cvsUserName"
-fi
-echo "           LINUX/MacOS User Name                      : $linuxUserName"
-echo "           Build type                                 : $buildType"          
-echo "           Gdcm version                               : $gdcmVersion"
-echo
-echo
-echo "Do you confirm your choices : YES/NO ? (default is NO)"
-read confirm
-done 
-
-
- # GROS SOUCIS : Ou creer le fichier CreaTools-configure.sh?
+     echo
+     echo
+     confirm="NO"
+     while [ "$confirm" != "YES" ]
+     do
+     
+        OperatingSystem="XXX"
+        while [[ "$OperatingSystem" != "Fedora" && \
+                 "$OperatingSystem" != "Ubuntu" && \
+                "$OperatingSystem" != "MacOS" ]]
+        do
+           echo "Operating System : Fedora/Ubuntu/MacOS (default : Fedora)"
+           read OperatingSystem
+           if [ "$OperatingSystem" = "" ]
+           then
+             OperatingSystem="Fedora"
+           fi  
+        done
+        echo "you said : [" $OperatingSystem "]"
+        echo
+        echo
+
+        # ------------------
+        echo "Name of the Generation Directory (default is /tmp/myGenerationDir)"
+        read generationdir
+        if [ "$generationdir" = "" ]
+        then
+           generationdir="/tmp/myGenerationDir"
+        fi
+        echo "you said : [" $generationdir "]"
+
+        echo
+        echo
+        # ------------------
+        installPrefixThird="___"
+        echo "Install Prefix For Third Party Library : '$generationdir/thirdparty_install' / '/usr/local' (default is '$generationdir/thirdparty_install')"
+        read installPrefixThird
+        if [ "$installPrefixThird" = "" ]
+        then
+           installPrefixThird="$generationdir/thirdparty_install"
+        fi
+        echo "you said : [" $installPrefixThird "]"
+        echo
+        echo 
+        # ------------------
+
+        installPrefix="___"
+        echo "Install Prefix for CreaTools : '$generationdir/creatools_install' / '/usr/local' (default is '$generationdir/creatools_install')"
+        read installPrefix
+        if [ "$installPrefix" = "" ]
+        then
+           installPrefix="$generationdir/creatools_install"
+        fi
+        echo "you said : [" $installPrefix "]"
+        echo
+        echo 
+        # ------------------
+
+        docgeneration="___"
+        while [[ "$docgeneration" != "ON"  && "$docgeneration" != "OFF" ]]
+        do
+           echo "Boolean For Doc Generation : ON/OFF (default is OFF)"
+           read docgeneration
+          if [ "$docgeneration" = "" ]
+          then
+             docgeneration="OFF"
+          fi
+          echo "you said : [" $docgeneration "]"
+        done
+        echo
+        echo
+        # ------------------
+
+        sourcesFrom="___"
+        while [[ "$sourcesFrom" != "CVS"  && "$sourcesFrom" != "HTML" ]]
+        do
+           echo "Where do you want to get source files from : CVS/HTML (default is CVS)"
+           read sourcesFrom
+           if [ "$sourcesFrom" = "" ]
+           then
+              sourcesFrom="CVS"
+           fi
+           echo "you said : [" $sourcesFrom "]"
+        done
+        echo
+        echo
+        # ------------------
+
+        cvsUserName=""
+        if [ "$sourcesFrom" = "CVS" ]
+        then
+           while [ "$cvsUserName" == "" ]
+           do
+              echo "CVS User Name (mandatory!)"
+              read cvsUserName
+           done
+           echo "you said : [" $cvsUserName "]"
+        else
+           cvsUserName="ForgetThisOne" 
+        fi
+        echo
+        echo
+        # ------------------
+
+
+        loginUserName=""
+        while [ "$loginUserName" == "" ]
+        do 
+           echo "Have a look at the following line to know 'Login User Name'/'Login Group Name'"
+           ls -l menu.sh
+           echo "Login User Name (mandatory!)"
+           read loginUserName  
+           echo "you said : [" $loginUserName "]"  
+        done
+        echo
+        echo
+
+        loginGroupName=""
+        while [ "$loginGroupName" == "" ]
+        do
+            #echo "Have a look at the following line to know 'Login User Name'/'Login Group Name'"
+            #echo "Login Group Name (mandatory!)"
+          echo "Login Group Name (mandatory!)"
+           read loginGroupName  
+           echo "you said : [" $loginGroupName "]"  
+        done
+        echo
+        echo
+        # ------------------
+
+        buildType="___"
+        while [[ "$buildType" != "Release"  && "$buildType" != "Debug" ]]
+        do
+           echo "Build type : Release/Debug (default is Release)"
+           read buildType
+           if [ "$buildType" = "" ]
+           then
+              buildType="Release"
+           fi
+           echo "you said : [" $buildType "]"
+        done
+        echo
+        echo
+        # ------------------
+
+        gdcmVersion="___"
+        while [[ "$gdcmVersion" != "GDCM1"  && "$gdcmVersion " != "GDCM2" ]]
+        do
+           echo "Gdcm version : GDCM1/GDCM2 (default is GDCM1)"
+           read gdcmVersion
+           if [ "$gdcmVersion" = "" ]
+           then
+              gdcmVersion="GDCM1"
+           fi
+           echo "you said : [" $gdcmVersion "]"
+        done
+        echo
+        echo
+        echo
+        echo
+        echo "You said :"
+        echo "  Operating System                           : $OperatingSystem"
+        echo "  Name of the Generation Directory           : $generationdir"
+        echo "  Install Prefix for Third Party Libraries   : $installPrefixThird"      
+        echo "  Install Prefix for CreaTools               : $installPrefix"
+        echo "  Boolean for Doc Generation                 : $docgeneration"
+        echo "  Where do you want to get source files from : $sourcesFrom"
+        if [ $sourcesFrom = CVS ]
+        then
+           echo "  CVS User Name                              : $cvsUserName"
+        fi
+        echo "  Login User Name                            : $loginUserName"
+        echo "  Login Group Name                           : $loginGroupName"
+        echo "  Build type                                 : $buildType"          
+        echo "  Gdcm version                               : $gdcmVersion"
+        echo
+        echo
+     
+        echo "Do you confirm your choices : YES/NO ? (default is YES)"
+        read confirm
+       if [ "$confirm" = "" ]
+       then
+          confirm=YES
+       fi
+   done
+
+ # GROS SOUCIS : Ou generer le fichier CreaTools-configure.sh?
  # dans $generationdir/creatools_bin ?
  # -> il n'est pas encore cree !
  # dans ./Linux/scripts?
  # -> ? 
 
-configureFile="scripts/CreaTools-configure.sh"
-touch  $configureFile
-echo "#!/bin/sh"                         >> $configureFile
-echo "OperatingSystem=$OperatingSystem"  >> $configureFile
-echo "generationdir=$generationdir"      >> $configureFile
-echo "installPrefix=$installPrefix"      >> $configureFile
-echo "docgeneration=$docgeneration"      >> $configureFile
-echo "sourcesFrom=$sourcesFrom"          >> $configureFile
-echo "cvsUserName=$cvsUserName"          >> $configureFile 
-echo "linuxUserName=$linuxUserName"      >> $configureFile
-echo "buildType=$buildType"              >> $configureFile
-echo "gdcmVersion=$gdcmVersion"          >> $configureFile
+   configureFile="scripts/CreaTools-configure.sh"
+   touch  $configureFile
+   echo "#!/bin/bash"                            >  $configureFile
+   echo                                          >> $configureFile
+   echo "#File generated by 'menu.sh'"           >> $configureFile
+   echo "#DO NOT edit !"                         >> $configureFile
+   echo "#(except if you *know* what you do)"    >> $configureFile
+   echo                                          >> $configureFile
+   echo "OperatingSystem=$OperatingSystem"       >> $configureFile
+   echo "generationdir=$generationdir"           >> $configureFile
+   echo "installPrefix=$installPrefix"           >> $configureFile
+   echo "installPrefixThird=$installPrefixThird" >> $configureFile
+   echo "docgeneration=$docgeneration"           >> $configureFile
+   echo "sourcesFrom=$sourcesFrom"               >> $configureFile
+   echo "cvsUserName=$cvsUserName"               >> $configureFile 
+   echo "loginUserName=$loginUserName"           >> $configureFile
+   echo "loginGroupName=$loginGroupName"         >> $configureFile
+   echo "buildType=$buildType"                   >> $configureFile
+   echo "gdcmVersion=$gdcmVersion"               >> $configureFile
+   
 
-         
-  # ------------------
-         
+  # ------------------      
+  # endif 'suitable'
+  fi 
   ;;
   
   1)
-     echo "========================== $i "
-     sh scripts/ThirdParty-install.sh
+     echo "========================== 1 "
+     source scripts/Check-if-root.sh
+     bash scripts/ThirdParty-install.sh
+     
+#      vtkdirVariable=""
+#      while [ "$vtkdirVariable" = "" ]
+#      do
+#         while [ ! -e "$vtkdirVariable" ]
+#         do
+#            echo
+#         echo " --------------------------------"
+#            echo " Set VTK_DIR environment variable"
+#         echo " --------------------------------"
+#            echo              
+# #            #read vtkdirVariable
+#         if [  ! -e "$vtkdirVariable" ]
+#         then
+# #          echo $vtkdirVariable is NOT a valid directory
+#         fi
+#         done
+#      done
+#      echo "you said [" $vtkdirVariable "]"
+
+     #vtkdirVariable=""
+     #while [ "$vtkdirVariable" = "" ]
+     #do
+     #   echo " Set VTK_DIR environment variable"
+      #  read vtkdirVariable
+     #done
+     #echo "you said [" $vtkdirVariable "]"
+          
+#      latexCompilerVariable=""
+#      while [ "$latexCompilerVariable" = "" ]
+#      do
+#         while [ ! -f "$latexCompilerVariable" ]
+#         do 
+#         echo
+# #       echo " ---------------------------------------"
+#            echo " Set LATEX_COMPILER environment variable"
+# #       echo " ---------------------------------------"
+#            echo              
+#            read latexCompilerVariable
+#         if [  ! -e "$latexCompilerVariable" ]
+#         then
+#            echo $latexCompilerVariable is NOT a valid file
+#         fi
+# #    done
+#      done
+#      echo "you said [" $latexCompilerVariable "]"     
+
+#     sed -i -e '/.*VTK_DIR*/ d'        $ETC_BASHRC
+#     sed -i -e '/.*LATEX_COMPILER*/ d' $ETC_BASHRC 
+#     echo "export VTK_DIR=$vtkdirVariable" >> $ETC_BASHRC
+#     echo "export LATEX_COMPILER=$latexCompilerVariable" >> $ETC_BASHRC
+
+     if [ "$sourcesFrom" = "CVS" ]
+     then
+        echo "----------------------------------------------------------------------"
+        echo OK
+        echo "To go on, run again 'bash menu.sh' as '$loginUserName', in a new window"
+        echo "---------------------------------------------------------------------"
+     else
+        echo "----------------------------------------------------------------------"
+        echo OK
+        echo "To go on, run again 'bash menu.sh'  in a new window"
+        echo "---------------------------------------------------------------------"
+     fi
+     echo
+     echo "==> Hit any key to exit close current window" 
+     read a
+     kill $PPID    
   ;;
-  
+
   2)
-     echo "========================== $i"
-     sh scripts/CreaTools-compile.sh     
+    
+     
+     echo "========================== 2" 
+     bash scripts/CreaTools-load.sh
+  ;;
+  
+  3)
+     echo "========================== 3"
+     source scripts/CreaTools-configure.sh
+     bash scripts/CreaTools-compile.sh
+     
+     # To allow (*very* aware) user to patch code, later
+  
+     chown -R $loginUserName $generationdir/creatools_source
+     chgrp -R $loginGroupName $generationdir/creatools_source
+     # Too much time consuming
+     #chown -R $loginUserName $generationdir/creatools_source 
+     #chgrp -R $loginGroupName $generationdir/creatools_source     
   ;;
   
-  3) 
-     echo "========================= $i"
-     sh scripts/CreaTools-install.sh     
+  4) 
+      if [ $UID != 0 ] 
+      then
+         echo
+         echo "..ERROR.."
+         echo "==================================================="
+         echo "REMEMBER !"
+         echo ""
+         echo "YOU NEED TO RUN THIS ONE AS root"
+         echo "==================================================="
+         echo
+         echo
+         exit 0
+      fi
+      echo "========================= 4"
+      bash scripts/CreaTools-install.sh 
+     echo
+     echo "==> Hit any key to close current window" 
+     read a
+     kill $PPID        
   ;;
  
-  4)
-     echo "========================= $i"
-     sh scripts/CreaTools-uninstall.sh
+  5)
+     echo "========================= 5"
+     bash scripts/CreaTools-uninstall.sh
+  ;;
+
+  7)
+     clear
+     echo "==================================="
+     more README.txt
+      echo
+     echo "==> Hit any key to go on" 
+     read a
   ;;
-       
+         
+  8)
+     clear
+     echo "==================================="
+     
+     # WARNING : $installPrefixThird is taken from CreaTools-configure.sh
+     # if user configured without installing third party library,
+     # Last third party library is still in use!  JPR
+
+
+     if [ ! -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
+     then
+              echo WARNING
+              echo
+              echo "the curently used Third Party libraries are NOT in $installPrefixThird but in :"
+              grep "installPrefixThird=" /etc/bashrc    
+              echo "VTK_DIR :...." $VTK_DIR
+              echo "ITK_DIR :...." $ITK_DIR
+              echo "GDCM_DIR :..." $GDCM_DIR
+     fi
+            
+     if [ -f $installPrefixThird/share/creatools_third_party_library_config.sh ]
+     then
+        echo  $installPrefixThird/share/creatools_third_party_library_config.sh
+       echo  ------
+       more $installPrefixThird/share/creatools_third_party_library_config.sh
+       echo  ------
+     fi
+     
+     echo
+     
+     if [ -f $installPrefix/share/creatools_base_library_config.sh ]
+     then
+        echo  $installPrefix/share/creatools_base_library_config.sh
+       echo  ------ 
+       more $installPrefix/share/creatools_base_library_config.sh
+       echo  ------ 
+     fi   
+     echo "==================================="
+     echo
+     echo "Press any key to continue"
+     read a
+   ;;
+               
   9) 
-  echo exit
+  echo 
+  exit 0
   ;;
    
   *)
-  echo "Your answer must be in {0, 1, 2, 3, 4, 9} (was $i)"
+  echo "Your answer must be in {0, 1, 2, 3, 4, 5, 9} (was [ $i ])"
   ;;
   esac
 
 done
-fi 
+