install 8.36 KB
#!/bin/sh
#   
# The installation shell for Anubis under Linux. 
# Copyright (c) Alain Proute' 2006
#   
   
MUST_LDCONFIG=0
ERROR_COUNT=0      
   
# Performing a command, tracing it and counting errors
function perform ()
   {
   echo -n "   " $1 " ... "
   if 2> errors_report $1;
   then echo "OK"
   else echo "*** Error ***";
        ((ERROR_COUNT++))
   fi
   }

   
ADD_LINES="   Add lines."   
DONT_ADD_LINES="   Don't add lines."   
PATH_LINE1=""
PATH_LINE2=""   
   
# adding a value to the 'PATH' variable (this is only for non root installations)
function add_value_to_PATH ()
   {
   # $1 is the value to be added (for example '/home/georges/bin')
   PATH_LINE1="PATH=$1:\$PATH";
   PATH_LINE2="export PATH";
   echo -e "\n--- Checking that '$1' is in the 'PATH' ---";
   if [[ $PATH == *$1* ]]
   then echo -e "   $1 is already in the 'PATH' variable.";
   else echo -e "   $1 is not in the 'PATH' variable.";
        echo -e "   May I add the following lines to your '.bash_profile' ?";
        echo -e $PATH_LINE1;
        echo -e $PATH_LINE2;
        select RESULT in "$ADD_LINES" "$DONT_ADD_LINES" ; 
          do if [ "$RESULT" == "$ADD_LINES" ]
             then echo $PATH_LINE1 >> $HOME/.bash_profile;
                  echo $PATH_LINE2 >> $HOME/.bash_profile;
                  echo -e "The lines have been appended at the end of '.bash_profile'";
             else echo -e "'.bash_profile' is unchanged";
             fi
             break; 
          done
   fi
   }
   
   
# The same one for the 'LD_LIBRARY_PATH' variable (this is only for non root installations)
function add_value_to_LD_LIBRARY_PATH ()
   {
   # $1 is the value to be added (for example '/home/georges/anubis/lib')
   PATH_LINE1="LD_LIBRARY_PATH=$1:\$LD_LIBRARY_PATH";
   PATH_LINE2="export LD_LIBRARY_PATH";
   echo -e "\n--- Checking that '$1' is in the 'LD_LIBRARY_PATH' ---";
   if [[ $LD_LIBRARY_PATH == *$1* ]]
   then echo -e "   $1 is already in the 'LD_LIBRARY_PATH' variable.";
   else echo -e "   $1 is not in the 'LD_LIBRARY_PATH' variable.";
        echo -e "   May I add the following lines to your '.bash_profile' ?";
        echo -e $PATH_LINE1;
        echo -e $PATH_LINE2;
        select RESULT in "$ADD_LINES" "$DONT_ADD_LINES" ; 
          do if [ "$RESULT" == "$ADD_LINES" ]
             then echo $PATH_LINE1 >> $HOME/.bash_profile;
                  echo $PATH_LINE2 >> $HOME/.bash_profile;
                  echo -e "The lines have been appended at the end of '.bash_profile'";
             else echo -e "'.bash_profile' is unchanged";
             fi
             break; 
          done
   fi
   }
   
   
   
# Copying just one Linux library (if needed)  
function install_library ()
   {
   # $1 is the soname of the library
   # $2 is the realname of the library
   # $3 is the directory where the library must be installed
   # We just test if the soname exists
   if [ -e "$3/$1" ]   
   then echo "   " Library "$3/$2" already installed;
   else perform "cp ./lib/$2 $3";
        # configuration is postponed
        ((MUST_LDCONFIG++))
   fi
   }
   
   
# Chech the existence of a library
function check_library ()
   {
   # $1 is the soname of the library
   # $2 is the realname of the library
   # $3 is the directory where the library must be installed
   # We just test if the soname exists
   if [ -e "$3/$1" ]   
   then echo "   " Library "$3/$2" is installed;
   else echo "   " You should install "$3/$2" manually;
   fi
   }
   
   
   
# installing Anubis as root
function install_as_root ()
   {
   echo -e "\n---" Creating the 'anubis' directory \(if needed\) "---";
   perform "mkdir -p /usr/share/anubis";

   echo -e "\n---" Installing the Anubis library and documentation "---";
   perform "tar -C /usr/share/anubis -xzf anubis_files.tar.gz";
   
   echo -e "\n--- Installing the Anubis binaries ---";
   perform "tar -xzf anubis_binaries.tar.gz";
   perform "cp bin/anubis  /usr/bin/anubis";
   perform "cp bin/anbexec /usr/bin/anbexec";
   perform "chmod a+x /usr/bin/anubis";
   perform "chmod a+x /usr/bin/anbexec";
   perform "chown root /usr/bin/anbexec";
   perform "chgrp root /usr/bin/anbexec";
   perform "chmod ug+s /usr/bin/anbexec";
   
   echo -e "\n---" Copying the not already installed Linux libraries "---";
   /sbin/ldconfig    # to be sure that the current libraries are configured
   # Usage: install_library soname realname installation_directory
   # All libraries are in ./lib
   install_library "libjpeg.so.62" "libjpeg.so.62.0.0" "/usr/lib";
   install_library "libm.so.6" "libm-2.3.2.so" "/lib";
   install_library "libX11.so.6" "libX11.so.6.2" "/usr/X11R6/lib";
   install_library "libdl.so.2" "libdl-2.3.2.so" "/lib";
   install_library "libstdc++.so.5" "libstdc++.so.5.0.7" "/usr/lib";
   check_library "libpthread.so.0" "libpthread-0.10.so" "/lib";
   install_library "libgcc_s.so.1" "libgcc_s.so.1" "/lib";
   
   echo -e "\n---" Configuring $MUST_LDCONFIG libraries "---";
   if [ $MUST_LDCONFIG != 0 ]   
   then perform "/sbin/ldconfig";
   fi
   }
   
   
   
# installing Anubis as non root
function install_as_non_root ()
   {
   echo -e "\n--- Installing Anubis for user '$USER' only. ---";
      
   echo -e "\n---" Creating the 'anubis' directory \(if needed\) "---";
   perform "mkdir -p $HOME/anubis";

   echo -e "\n---" Installing the Anubis library and documentation "---";
   perform "tar -C $HOME/anubis -xzf anubis_files.tar.gz";
   
   echo -e "\n--- Installing the Anubis binaries ---";
   perform "mkdir -p $HOME/bin"; 
   perform "mkdir -p $HOME/anubis/lib"; 
   perform "tar -xzf anubis_binaries.tar.gz";
   perform "cp bin/anubis  $HOME/bin/anubis";
   perform "cp bin/anbexec $HOME/bin/anbexec";
   perform "chmod a+x $HOME/bin/anubis";
   perform "chmod a+x $HOME/bin/anbexec";
   add_value_to_PATH "$HOME/bin";
   
   echo -e "\n---" Copying the not already installed Linux libraries "---";
   perform "mkdir -p $HOME/anubis/lib";
   # Usage: install_library soname realname installation_directory
   # All libraries are in ./lib
   install_library "libjpeg.so.62" "libjpeg.so.62.0.0" "$HOME/anubis/lib";
   install_library "libm.so.6" "libm-2.3.2.so" "$HOME/anubis/lib";
   install_library "libX11.so.6" "libX11.so.6.2" "$HOME/anubis/lib";
   install_library "libdl.so.2" "libdl-2.3.2.so" "$HOME/anubis/lib";
   install_library "libstdc++.so.5" "libstdc++.so.5.0.7" "$HOME/anubis/lib";
   check_library "libpthread.so.0" "libpthread-0.10.so" "$HOME/anubis/lib";
   install_library "libgcc_s.so.1" "libgcc_s.so.1" "$HOME/anubis/lib";
   add_value_to_LD_LIBRARY_PATH "$HOME/anubis/lib";
   
   echo -e "\n---" Configuring $MUST_LDCONFIG libraries "---";
   perform "/sbin/ldconfig -n $HOME/anubis/lib";
   }
   
   
# Installing Anubis
function install_anubis ()
   {
   if [ $UID == "0" ]
   then echo -e "\n---" Installing Anubis as \'root\' "---";
        install_as_root
   else if [ "$1" == "non_root" ]
        then install_as_non_root
        else
           echo -e " (1) If you have 'root' access, you should better install Anubis as 'root'.";
           echo -e "     Hence, become 'root' before restarting this installation shell.";
           echo -e " (2) If definitely you have no 'root' access, you can still install";
           echo -e "     Anubis as a non privileged user. In this case, just issue the command:";
           echo -e "install non_root";
           return
        fi
   fi
   
   if [ $ERROR_COUNT != 0 ]
   then echo -e "\n--- $ERROR_COUNT errors occured. ---";
        return;
   else echo -e "\n--- Installation successful. ---";
        echo -e "    You may remove the directory '$(pwd)' and its content.";
   fi
   if [ $UID == "0" ]
   then echo -e "    Each user must execute 'anubis' at least one time to have";
        echo -e "    the 'my_anubis' directory setup in his 'home' directory.";
        echo -e "    The documentation may be found in '/usr/share/anubis/en' or";
        echo -e "    '/usr/share/anubis/fr'.";
   else echo -e "    You must now execute 'anubis' at least one time to have";
        echo -e "    your 'my_anubis' directory setup in your 'home' directory.";
        echo -e "    The documentation may be found in '" $HOME"/anubis/en' or";
        echo -e "    '" $HOME"/anubis/fr'.";
        echo -e "    If you want to be able to listen on privileged ports,";
        echo -e "    you must ask 'root' to execute the following commands:";
        echo -e "chown root $HOME/bin/anbexec";
        echo -e "chmod ug+s $HOME/bin/anbexec";
   fi
   }
   
   
install_anubis $*