install 5.75 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
   }
   
# 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
   }
   
   
   
# 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 "libssl.so.0.9.7" "libssl.so.0.9.7" "/usr/lib"
   install_library "libcrypto.so.0.9.7" "libcrypto.so.0.9.7" "/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"
   install_library "libpthread.so.0" "libpthread-0.10.so" "/lib"
   install_library "libc.so.6" "libc-2.3.2.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";
   
   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 "libssl.so.0.9.7" "libssl.so.0.9.7" "$HOME/anubis/lib"
   install_library "libcrypto.so.0.9.7" "libcrypto.so.0.9.7" "$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"
   install_library "libpthread.so.0" "libpthread-0.10.so" "$HOME/anubis/lib"
   install_library "libc.so.6" "libc-2.3.2.so" "$HOME/anubis/lib"
   install_library "libgcc_s.so.1" "libgcc_s.so.1" "$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. ---"
   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'."
   fi
   }
   
   
install_anubis $*