#!/bin/sh 
# cd Autorun for System gement Software 
# 

function configure_appcore
{
	ASC_INSTALL_PATH=$1
	PASSWORD=$2
	ERL_PATH=$ASC_INSTALL_PATH/lib/erlang
	
	export APPCORE_PATH=$ERL_PATH/lib/appcore-3.0/ebin
	
	pushd $APPCORE_PATH  1>/dev/null 2>/dev/null 

	cp -f $ASC_INSTALL_PATH/config_asc.json ./config.json 

	EVAL_FUN="install:configure([{admin_password,\"$PASSWORD\"}])"
	ERL_OPTIONS=" -noshell -eval $EVAL_FUN -s erlang halt"

	$ERL_PATH/bin/erl  $ERL_OPTIONS 
	
	#Set permissions for cookie file
	chmod 400 .erlang.cookie
	
	popd  1>/dev/null 2>/dev/null 
}

function configure_update_appcore
{
	ASC_INSTALL_PATH=$1
	ERL_PATH=$ASC_INSTALL_PATH/lib/erlang
	
	export APPCORE_PATH=$ERL_PATH/lib/appcore-3.0/ebin
	
	pushd $APPCORE_PATH  1>/dev/null 2>/dev/null 

	cp -f $ASC_INSTALL_PATH/config_asc.json ./config.json 

	EVAL_FUN="install:configure([])"
	ERL_OPTIONS=" -noshell -eval $EVAL_FUN -s erlang halt"

	$ERL_PATH/bin/erl  $ERL_OPTIONS 
	
	#Set permissions for cookie file
	chmod 400 .erlang.cookie
	
	popd  1>/dev/null 2>/dev/null 
}

function startsvcs 
{ 
         #start Services
         echo " "
	 sleep 3
         /etc/init.d/Appcore start 
         sleep 10
         /etc/init.d/lighttpd start 
         /etc/init.d/ascpolicy start 
} 
function stopsvcs 
{ 
         #stop Services
         echo " "
         /etc/init.d/ascpolicy stop 
         /etc/init.d/lighttpd stop 
	 sleep 3
         /etc/init.d/Appcore stop 
         sleep 10
} 
 
function addcronjob 
{ 
         # start crond service - in case its not up by default 
         if [ -e "/etc/SuSE-release" ]; then 
            /etc/init.d/cron start 2> /dev/null 1 > /dev/null 
         elif grep -q -i "release 6" /etc/redhat-release ; then 
            /etc/init.d/crond start 2>&1 > /dev/null
	 elif grep -q -i "release 7" /etc/redhat-release ; then
	    service crond start 2>&1 > /dev/null
	 else
              echo "crond service not found"
         fi; 
 
         crontab -l | grep -v "^#" |grep -v "ascservicemonitor" > /tmp/__asccronjoblist__ 
         echo "*/3 * * * * /usr/local/asc/bin/ascservicemonitor 2>&1 >/dev/null" >> /tmp/__asccronjoblist__ 
         crontab /tmp/__asccronjoblist__ 
         rm -f /tmp/__asccronjoblist__ 
} 
 
# This function will take care of adding bmcresetter to  
# rc.local/boot.local 
function addbmcresetter 
{ 
         # start crond service - in case its not up by default 
         if [ -e "/etc/SuSE-release" ]; then 
            if [ -e "/etc/rc.d/boot.local" ]; then 
		   cat /etc/rc.d/boot.local > /tmp/_boot_local 
		   echo "/usr/local/asc/bin/bmcresetter" >> /tmp/_boot_local 
		   cp -f /tmp/_boot_local /etc/rc.d/boot.local 
		   rm -f /tmp/_boot_local 		 
 		else 
		   echo "/usr/local/asc/bin/bmcresetter" > /etc/rc.d/boot.local 
		fi; 
   	 
         else 
		# REDHAT variants	 
            if [ -e "/etc/rc.d/rc.local" ]; then 
		   cat /etc/rc.d/rc.local > /tmp/_boot_local 
		   echo "/usr/local/asc/bin/bmcresetter" >> /tmp/_boot_local 
		   cp -f /tmp/_boot_local /etc/rc.d/rc.local 
		   rm -f /tmp/_boot_local 
 		else 
		   echo "/usr/local/asc/bin/bmcresetter" > /etc/rc.d/rc.local 
		fi; 
         fi; 
} 
 
function setadmin 
{ 
         stty_orig=`stty -g` 
          
         echo ":" 
         echo "NOTE:" 
         echo "Passwords must be at least 8 characters and not exceed 32 characters," 
         echo "contain at least one special character, one numeric character, one" 
         echo "Capital letter(upper-case), and one small letter (lower-case)." 
         echo "Valid password characters are: a-zA-Z0-9!~#@\$*&^%\`-_=+:;.,?" 
         echo ":" 
 
         RESULT=-1 
 
         until [ "$RESULT" -eq 0 ] 
         do 
             DataIn="PWD1" 
             VerifyIn="PWD2" 
 
             stty -echo 
                 
             until [ "$DataIn" = "$VerifyIn" ] 
             do 
                read -n 32 -p "Create Intel(R) Active System Console Admin Password: " DataIn; echo 
	            read -n 32 -p "Confirm password: " VerifyIn; echo 
             done 
              
             typeset -i validsum  
	         stty $stty_orig 
 
	         lcase=$((`echo $DataIn | sed 's/[^a-z]//g' | wc -m` -1)) 
             ucase=$((`echo $DataIn | sed 's/[^A-Z]//g' | wc -m` -1)) 
             digit=$((`echo $DataIn | sed 's/[^0-9]//g' | wc -m` -1)) 
	         specC=$((`echo $DataIn | sed 's/[^!,~,#,@,\$,*,&,^,%,\`,-,_,=,+,:,;,\.,\,,?]//g' | wc -m` -1)) 
	         valdC=$((`echo $DataIn | sed 's/[^a-zA-Z0-9,!,~,#,@,\$,*,&,^,%,\`,-,_,=,+,:,;,\.,\,,?]//g' | wc -m` -1)) 
             count=$((`echo $DataIn | wc -m` -1)) 
             validsum=($lcase+$ucase+$digit+$specC) 
              
             RESULT=-5; 
 
             if [ "$count" -eq 0 ] || [ "$count" -gt 32 ] ||  
                    [ "$count" -ne "$valdC" ]; then 
                 RESULT=-4 
              
             elif [ "$lcase" -gt 0 ]; then 
                if [ "$ucase" -gt 0 ]; then 
                   if [ "$digit" -gt 0 ]; then 
                      if [ "$specC" -gt 0 ]; then 
                         if [ "$validsum" -ge 8 ]; then 
                           if [ "$validsum" -le 32 ]; then 
                              if [ "$count" -eq "$validsum" ]; then 
                                  RESULT=0 
                              fi 
	                       fi 
                         fi 
                      fi 
                   fi 
                fi 
             fi 
              
              
             echo ":" 
             if [ "$RESULT" -eq -5 ]; then 
 
                 echo "Warning!" 
                echo "  The password you have chosen is a weak password! Weak" 
                echo "passwords increase the security risk of unintended access" 
                echo "to the product. " 
                echo "A strong password should be at least 8 characters and not" 
                echo "exceed 32 characters, contain at least one special character," 
                echo "one numeric character, one Capital letter(upper-case), and" 
                echo "one small letter (lower-case)."
                echo "Valid password characters are: a-zA-Z0-9!~#@\$*&^%\`-_=+:;.,?"
                echo ":"
                echo "If you wish to continue with the weak password" 
                echo "press (I)gnore, else press (R)etry for a new password" 
             fi 
 
             if [ "$RESULT" -eq -4 ]; then 
                echo ":" 
                echo "Invalid password entered!" 
                echo  
                echo "NOTE:" 
                echo "Passwords must be at least 8 characters and not exceed 32 characters," 
                echo "contain at least one special character, one numeric character and" 
                echo "one Capital letter(upper-case), and one small letter (lower-case)." 
                echo "Valid password characters are: a-zA-Z0-9!~#@\$*&^%\`-_=+:;.,?" 
                echo ":"
             fi 
 
             if [ "$RESULT" -ne 0 ]; then 
                echo ":" 
                if [ "$RESULT" -eq -5 ]; then 
                   echo "Do you wish to keep the weak password? " 
                   echo "if you chose to quit this installation will be removed." 
                fi 
	            while true; do 
                   if [ "$RESULT" -eq -5 ]; then 
   	                  read -n 1 -p  "Do you wish to try again? (R)etry or (I)gnore or (Q)uit  " ans  
                   else  
   	                  read -n 1 -p  "Do you wish to try again? (R)etry or (Q)uit  " ans  
                   fi 
                   echo "." 
                case $ans in 
                  "r" | "R") echo "Installation will now continue." 
	                     break;; 
                  "i" | "I") echo "Ignoring -- Installation will now continue" 
                             RESULT=0 
                             break;; 
                  "q" | "Q") echo "This installaion will now be removed." 
                             /usr/local/asc/bin/uninstall 
	                     echo "Installation will now terminate." 
	                     exit;; 
                *) echo "please enter Retry or Quit" ;; 
                esac 
               done 
             fi 
 
             echo ":" 
 
             if [ "$RESULT" -eq 0 ]; then 
 
               pushd . 1>/dev/null 2>/dev/null 
               cd $ASCInstallPath 
               cd bin 
               "$ASCInstallPath/bin/admin" $DataIn 
               popd . 1>/dev/null 2>/dev/null 
			   configure_appcore $ASCInstallPath $DataIn
             fi 
 
         done   
 
} 
 
# detect system configuration and dynamically write HTML 
# 
 
ROOTdir=`pwd`  
pushd . 1>/dev/null 2>/dev/null 
cd .. 
PARENTdir=`pwd`  
popd  1>/dev/null 2>/dev/null 

ARCH="ia64" 
if [ $HOSTTYPE != $ARCH ]; then 
  ARCH="i386" 
fi; 
RVERSION=`uname -r` 
ULANG=`echo $LANG | sed "s/\..*$//;s/_.*$//;" ` 
 
if [ -e "/etc/redhat-release" ]; then 
    NVERSION="RedHat" 
elif [ -e "/etc/SuSE-release" ]; then 
    NVERSION="SUSE" 
elif [ -e "/etc/fedora-release" ]; then 
    NVERSION="RedHat" 
elif [ -e "/etc/debian-release" ]; then 
    NVERSION="RedHat" 
elif [ -e "/etc/centos-release" ]; then 
    NVERSION="RedHat" 
else 
    NVERSION=`uname -s` 
fi; 

COMPATOS="unknown"
COMPATVER="unknown"
REV=0

if [ "$NVERSION" == "RedHat" ]; then
   # Test Redhat flavors
   COMPATOS="RHEL";
   
   #set default version
   COMPATVER="RHEL5";

   REV=`head -n 1 /etc/redhat-release | sed -e 's/(.*//' | tr -dc [0-9,.] | sed -e 's/\([0-9]*\)\(.*\)/\1/'` 

   if [[ -e "/etc/fedora-release" ]]; then 
      NVERSION="Fedora"
      if [ "$REV" -ge "11" ]; then
        COMPATVER="RHEL5"
      else
        COMPATVER="RHEL4"
      fi;
   fi;
   if [[ -e "/etc/debian-release" ]]; then 
      if [ "$REV" -ge "6" ]; then
        COMPATVER="RHEL5"
      else
        COMPATVER="RHEL4"
      fi;
   fi;
   if [[ -e "/etc/centos-release" ]]; then 
      if [ "$REV" -ge "5" ]; then
        COMPATVER="RHEL5"
      else
        COMPATVER="RHEL4"
      fi;
   fi;
   if [[ -e "/etc/redhat-release" ]]; then 
      if [ "$REV" -ge "6" ]; then
        COMPATVER="RHEL6"
      elif [ "$REV" -eq "5" ]; then
        COMPATVER="RHEL5"
      else
        COMPATVER="RHEL4"
      fi;
   fi;
else
  if [ "$NVERSION" == "SUSE" ]; then
     # Test SUSE flavors
     COMPATOS="SLES"

     #set default version
     COMPATVER="SLES11";
    
     REV=`head -n 1 /etc/SuSE-release | sed -e 's/(.*//' | tr -dc [0-9,.] | sed -e 's/\([0-9]*\)\(.*\)/\1/'` 
     if [[ -e "/etc/SuSE-release" ]]; then 
        NVERSION="SUSE"
        if [ "$REV" -ge "11" ]; then
           COMPATVER="SLES11"
        else
           COMPATVER="SLES10"
        fi;
     fi;
  fi;
fi;

 
if [ "$UID" -eq "0" ]; then 
  ADMIN=true 
else 
  ADMIN=false 
fi; 
 
#determine browser 
BROWSER=`which firefox` 
if [ $? != 0 ]; then 
  BROWSER=`which mozilla` 
  if [ $? != 0 ]; then 
     BROWSER=`which htmlview` 
     if [ $? != 0 ]; then 
        BROWSER=`which konqueror` 
        if [ $? != 0 ]; then 
           BROWSER=`which opera` 
           if [ $? != 0 ]; then 
             BROWSER="unknown" 
           fi; 
	fi; 
     fi; 
  fi; 
fi; 
 
ASCInstallPath="/usr/local/asc/" 
export ASCInstallPath 
 
if [ $ADMIN == false ]; then 
   echo "You must be root to install" 
   exit 
fi 
 
 
echo ":" 
echo "Installing:  Intel(R) Active System Console" 
echo "Please read the license agreement" 
 
(`$BROWSER License/default.html 1>/dev/null 2>/dev/null `) 
 
sleep 3 
 
while true; do 
   read -n 1 -p  "Do you agree to the terms of the license? (Y)es or (N)o  " ans  
   echo "." 
   case $ans in 
     "y" | "Y") echo "Installation will now continue." 
	        break;; 
     "n" | "N") echo "Installation will now terminate." 
	        exit;; 
     *) echo "please enter Yes or No" ;; 
   esac 
done 

# Check Whether IPMI Driver is installed
 
if [ -e "/etc/redhat-release" ]; then 

		if [[ -e "/dev/ipmi0" ]]; then
			echo "IASC detected Linux IPMI driver in kernal already enable."
			break;
		else
			echo -e "Intel(R) Active System Console detected \033[31mLinux IPMI driver in kernel\033[0m not enable."
			echo -e "Enable \033[31mLinux IPMI driver\033[0m just type \033[31m'modprobe ipmi_devintf' and  'modprobe ipmi_si'\033[0m in Linux shell."
			echo -e "Installation will be terminate..."
			exit;
		fi;
fi;


if [ -e "/etc/SuSE-release" ]; then
  if [ -e "/proc/efi" ] || [ -e "/sys/firmware/efi" ]; then
	  if [[ -e "/dev/ipmi0" ]]; then
		echo "IASC detected Linux IPMI driver in kernal already enable."
		break;
	  else
		echo -e "Intel(R) Active System Console detected \033[31mLinux IPMI driver in kernel\033[0m not enable."
		echo -e "Enable \033[31mLinux IPMI driver\033[0m just type \033[31m'modprobe ipmi_devintf' and 'modprobe ipmi_si'\033[0m in Linux shell."
		echo -e "Installation will be terminate..."
		exit;
	  fi;
  fi;
fi;


if [ -e "/etc/redhat-release" ]; then 
	OSVER1=$(sed -n '/6.4/p' /etc/redhat-release)
	OSVER2=$(sed -n '/6.5/p' /etc/redhat-release)
	if [ "$OSVER1" == "Red Hat Enterprise Linux Server release 6.4 (Santiago)" ] || [ "$OSVER2" == "Red Hat Enterprise Linux Server release 6.5 (Santiago)" ]; then
		echo "This is linux Redhat 6.4 or 6.5"
		if [[ -e "/dev/ipmi0" ]]; then
			echo "IASC detected Linux IPMI driver in kernal already enable."
			break;
		else
			echo -e "Intel(R) Active System Console detected \033[31mLinux IPMI driver in kernel\033[0m not enable."
			echo -e "Enable \033[31mLinux IPMI driver\033[0m just type \033[31m'modprobe ipmi_devintf'\033[0m in Linux shell."
			echo -e "Installation will be terminate..."
			exit;
		fi;
		rpmfound=$(rpm -qa | grep libxslt-1.1.26-2.el6_3.1.i686)
		if [ "$rpmfound" != "" ]; then
			echo found the require rpm install
			break;
		else
			echo -e "Intel(R) Active System Console detected \033[31m32bits requirement RPM is not install\033[0m."
			echo -e "To install \033[31m32bits requirement RPM\033[0m, there is auto rpm installation script available in '\ASC' folder."
			echo -e "Just type \033[31m'RHELx86_64AUTO.sh'\033[0m in Linux shell."
			echo -e "Installation will be terminate..."
			exit;
		fi;
	else
	  echo "not Redhat 6.4 or 6.5"
	fi;
fi;
 
if [ -e "/etc/SuSE-release" ]; then
  if [ -e "/proc/efi" ] || [ -e "/sys/firmware/efi" ]; then
      OSVER=$(sed -n '/(x86_64)/p' /etc/SuSE-release)
      echo $OSVER
      if [ "$OSVER" == "SUSE Linux Enterprise Server 11 (x86_64)" ]; then
	  echo "This is SuSE 11 UEFI Aware OS"
	  if [[ -e "/dev/ipmi0" ]]; then
		echo "IASC detected Linux IPMI driver in kernal already enable."
		break;
	  else
		echo -e "Intel(R) Active System Console detected \033[31mLinux IPMI driver in kernel\033[0m not enable."
		echo -e "Enable \033[31mLinux IPMI driver\033[0m just type \033[31m'modprobe ipmi_devintf and ipmi_si'\033[0m in Linux shell."
		echo -e "Installation will be terminate..."
		exit;
	  fi;
      else
	echo "not SuSE 11 UEFI Aware OS"
      fi;
   fi;
fi;
 
 
typeset -i FREESPACE 
typeset -i MEMAVAIL 
 
FREESPACE=`df -P -m /usr/local/ | grep "% /" | awk '{ print $4 }'` 
MEMAVAIL=`free -m | grep "Mem:" | awk '{ print $2 }'` 
 
echo ":" 
echo "Checking for Installed Packages" 
#detect installed applications 
CACHERIVER=`rpm -qa | grep CacheRiver` 
if [ $? != 0 ]; then  
  CACHERIVER="MISSING" 
  echo "   Intel(R) CacheRiver: NOT INSTALLED" 
else 
  echo "   Intel(R) CacheRiver: $CACHERIVER" 
fi; 
XERCES=`rpm -qa | grep XERCES` 
if [ $? != 0 ]; then  
   XERCES="MISSING" 
   echo "   Xerces: NOT INSTALLED" 
else 
   echo "   Xerces: $XERCES" 
fi;
APPCORE=`rpm -qa | grep APPCORE` 
if [ $? != 0 ]; then  
   APPCORE="MISSING" 
   echo "   AppCore: NOT INSTALLED" 
else 
   echo "   AppCore: $APPCORE" 
fi; 
ASC=`rpm -qa | grep ASC-` 
if [ $? != 0 ]; then  
   ASC="MISSING" 
   echo "   Intel(R) Active System Console: NOT INSTALLED" 
else 
   echo "   Intel(R) Active System Console: $ASC" 
fi; 
echo ":" 

#detect for cross-compatiblity
MSM=`rpm -qa | grep Multi-ServerManager` 
if [ $? != 0 ]; then  
   MSM="MISSING" 
else
   echo "This installer has detected a previous version of Intel(R) Multi Server Manager."
   echo "Please refer to the product documentation for further information. This"
   echo "installation will not continue."
   exit
fi;
 
 
 
#check everything, exit on failure otherwise install and launch ASC 
if [ $((FREESPACE)) -le 1000 ]; then 
   echo "insufficient space, it is recommended to have 1G available. Available: $FREESPACE MB" 
   exit 
else 
   if [ $((MEMAVAIL)) -le  250 ]; then 
      echo "insufficient Memory Available, it is recommend to have > 250 MB. Available: $MEMAVAIL MB" 
      exit 
   fi; 
fi;    
 
 
 
#install RPMs 
if [ $NVERSION == "RedHat" ]; then 
 
   `ls ../common/$COMPATOS/$COMPATVER/*i386.rpm 1>/dev/null 2>&1` 
   if [ $? == 0 ]; then 
 
      echo "removing older versions" 
      if [ $ASC != "MISSING" ]; then 
         echo "stopping services"
         stopsvcs

	 echo "backing up data"
         rm -rf "/var/tmp/asc"
         mkdir -p "/var/tmp/asc"
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-2.0/ebin/appcore.db" "/var/tmp/asc/."
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-2.0/ebin/appcore_https_server.crt" "/var/tmp/asc/."
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-2.0/ebin/appcore_https_server.pem" "/var/tmp/asc/."
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-2.0/ebin/mk.pem" "/var/tmp/asc/."
         mv -f "/usr/local/asc/bin/SMS.db" "/var/tmp/asc/."
         mv -f "/etc/lighttpd/lighttp.crt" "/var/tmp/asc/."
         mv -f "/etc/lighttpd/lighttp.pem" "/var/tmp/asc/."
         mv -f "/usr/local/asc/bin/db.xml" "/var/tmp/asc/."

         rpm -e $ASC
      fi;
      if [ $APPCORE != "MISSING" ]; then 
          rpm -e $APPCORE
      fi;
      if [ $CACHERIVER != "MISSING" ]; then 
	 rpm -e $CACHERIVER
      fi;

      if [ $ASC != "MISSING" ]; then 
         #leave this for the installer to fixup.
         mkdir -p "/usr/local/asc/bin"
         mv -f "/var/tmp/asc/db.xml" "/usr/local/asc/bin/."
      fi;

 
      #install XERCES 3.1.1 
      if [ $XERCES != "MISSING" ]; then 
         echo "Updating XERCES" 
         rpm -Uhv ../common/$COMPATOS/$COMPATVER/XERCES-*.i386.rpm 
      else 
	 echo "Installing XERCES" 
	 rpm -ihv ../common/$COMPATOS/$COMPATVER/XERCES-*.i386.rpm 
      fi; 
 
     #Install Cache River 2.0 
      if [ $CACHERIVER != "MISSING" ]; then 
         echo "Updating Intel(R) CacheRiver" 
	 rpm -Uhv ../common/$COMPATOS/$COMPATVER/CacheRiver-*.i386.rpm 
      else 
         echo "Installing Intel(R) CacheRiver" 
	 rpm -ihv ../common/$COMPATOS/$COMPATVER/CacheRiver-*.i386.rpm 
      fi; 

      #Install Appcore 2.0 
      if [ $APPCORE != "MISSING" ]; then 
         echo "Updating Intel(R) AppCore" 
	 rpm -Uhv ../common/$COMPATOS/$COMPATVER/APPCORE-*.i386.rpm 
      else 
         echo "Installing Intel(R) AppCore" 
	 rpm -ihv ../common/$COMPATOS/$COMPATVER/APPCORE-*.i386.rpm 
      fi
	      
      export APPCORE_PATH=$ASCInstallPath/lib/erlang/lib/appcore-3.0/ebin

      #Install ASC 
      if [ $ASC != "MISSING" ]; then 
         echo "Updating Intel(R) Active System Console" 
	 rpm -Uhv $COMPATOS/$COMPATVER/ASC-*.i386.rpm 
      else 
	 echo "Installing Intel(R) Active System Console" 
	 rpm -ihv $COMPATOS/$COMPATVER/ASC-*.i386.rpm 

         #set password
         setadmin 

      fi;

      if [ $ASC != "MISSING" ]; then 
         echo "Restoring data"
         mv -f "/var/tmp/asc/appcore.db" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin" 
         mv -f "/var/tmp/asc/appcore_https_server.crt" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin"
         mv -f "/var/tmp/asc/appcore_https_server.pem" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin"
         mv -f "/var/tmp/asc/mk.pem" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin"
         mv -f "/var/tmp/asc/SMS.db" "/usr/local/asc/bin/."
         mv -f "/var/tmp/asc/lighttp.crt" "/etc/lighttpd/."
         mv -f "/var/tmp/asc/lighttp.pem" "/etc/lighttpd/."

		 configure_update_appcore $ASCInstallPath
		 
         # rm -rf "/var/tmp/asc"
      fi;

      # Now call the bmcreset once after installation 	 
      "$ASCInstallPath/bin/bmcresetter" 
 
      # Now call bmcutil
      "$ASCInstallPath/bin/bmcutil"

      startsvcs 
 
      #Add the script to startup tasks 
      addcronjob    
      #addbmcresetter #Not required in the latest platform
      #(`$BROWSER "file://$ROOTdir/License/ASCReadMe.txt" 1>/dev/null 2>/dev/null `)
	  echo -e "\033[31m!!Warning...!!!!\033[0m"
      echo -e "Please check DNS server setting or add the hostname into system file /etc/hosts in order for the Active System Console to do name resolution for the system name to avoid login fail issue,"
      echo -e "refer to the software Release Notes for details."
    
   else 
	echo "Can not locate Installation Files, make sure *i386.rpms exist." 
   fi; 
 
else 
    #added to check for SuSE 12.0 32 rpm libssl.so libcrypto.so and libgcrypt.so and setup for link
   if [ -e "/lib/libssl.so.1.0.0" ]; then
	echo "Create link libssl" 
	ln -s /lib/libssl.so.1.0.0 /usr/lib/libssl.so.0.9.8
   fi;
   if [ -e "/lib/libcrypto.so.1.0.0" ]; then
	echo "Create link libcrypto"
	ln -s /lib/libcrypto.so.1.0.0 /usr/lib/libcrypto.so.0.9.8
   fi;
   if [ -e "/usr/lib/libgcrypt.so.20.0.1" ]; then
	echo "Create link libgcrypt"
	ln -s /usr/lib/libgcrypt.so.20.0.1 /usr/lib/libgcrypt.so.11
   fi;
    
   `ls ../common/$COMPATOS/$COMPATVER/*i586.rpm 1>/dev/null 2>&1` 
   if [ $? == 0 ]; then 
 
      echo "removing older versions" 
      if [ $ASC != "MISSING" ]; then 
         echo "stopping services"
         stopsvcs

	 echo "backing up data"
         rm -rf "/var/tmp/asc"
         mkdir -p "/var/tmp/asc"
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin/appcore.db" "/var/tmp/asc/."
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin/appcore_https_server.crt" "/var/tmp/asc/."
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin/appcore_https_server.pem" "/var/tmp/asc/."
         mv -f "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin/mk.pem" "/var/tmp/asc/."
         mv -f "/usr/local/asc/bin/SMS.db" "/var/tmp/asc/."
         mv -f "/etc/lighttpd/lighttp.crt" "/var/tmp/asc/."
         mv -f "/etc/lighttpd/lighttp.pem" "/var/tmp/asc/."
         mv -f "/usr/local/asc/bin/db.xml" "/var/tmp/asc/."

         rpm -e $ASC
      fi;
      if [ $APPCORE != "MISSING" ]; then 
          rpm -e $APPCORE
      fi;
      if [ $CACHERIVER != "MISSING" ]; then 
	 rpm -e $CACHERIVER
      fi;
 
      if [ $ASC != "MISSING" ]; then 
         #leave this for the installer to fixup.
         mkdir -p "/usr/local/asc/bin"
         mv -f "/var/tmp/asc/db.xml" "/usr/local/asc/bin/."
      fi;

      #install XERCES 3.1.1 
      if [ $XERCES != "MISSING" ]; then 
         echo "Updating XERCES" 
         rpm -Uhv ../common/$COMPATOS/$COMPATVER/XERCES-*.i586.rpm 
      else 
	 echo "Installing XERCES" 
	 rpm -ihv ../common/$COMPATOS/$COMPATVER/XERCES-*.i586.rpm 
      fi; 
 
     #InStall Cache River 2.0 
      if [ $CACHERIVER != "MISSING" ]; then 
         echo "Updating Intel(R) CacheRiver" 
	 rpm -Uhv ../common/$COMPATOS/$COMPATVER/CacheRiver-*.i586.rpm 
      else 
         echo "Installing Intel(R) CacheRiver" 
	 rpm -ihv ../common/$COMPATOS/$COMPATVER/CacheRiver-*.i586.rpm 
      fi; 

      #Install Appcore 2.0 
      if [ $APPCORE != "MISSING" ]; then 
         echo "Updating Intel(R) AppCore" 
	 rpm -Uhv ../common/$COMPATOS/$COMPATVER/APPCORE-*.i586.rpm 
      else 
         echo "Installing Intel(R) AppCore" 
	 rpm -ihv ../common/$COMPATOS/$COMPATVER/APPCORE-*.i586.rpm 
      fi
   
      export APPCORE_PATH=$ASCInstallPath/lib/erlang/lib/appcore-3.0/ebin

      #Install ASC 
      if [ $ASC != "MISSING" ]; then 
         echo "Updating Intel(R) Active System Console" 
	 rpm -Uhv $COMPATOS/$COMPATVER/ASC-*.i586.rpm 
      else 
	 echo "Installing Intel(R) Active System Console" 
	 rpm -ihv $COMPATOS/$COMPATVER/ASC-*.i586.rpm 

         #reset password	 
         setadmin 
      fi;

      if [ $ASC != "MISSING" ]; then 
         echo "Restoring data"
         mv -f "/var/tmp/asc/appcore.db" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin" 
         mv -f "/var/tmp/asc/appcore_https_server.crt" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin"
         mv -f "/var/tmp/asc/appcore_https_server.pem" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin"
         mv -f "/var/tmp/asc/mk.pem" "/usr/local/asc/lib/erlang/lib/appcore-3.0/ebin"
         mv -f "/var/tmp/asc/SMS.db" "/usr/local/asc/bin/."
         mv -f "/var/tmp/asc/lighttp.crt" "/etc/lighttpd/."
         mv -f "/var/tmp/asc/lighttp.pem" "/etc/lighttpd/."

		 configure_update_appcore $ASCInstallPath
		 
         # rm -rf "/var/tmp/asc"
      fi;

 
      # Now call the bmcreset once after installation 	 
      "$ASCInstallPath/bin/bmcresetter" 
	   
      # Now call bmcutil
      "$ASCInstallPath/bin/bmcutil"
		 
      startsvcs 
       
      #Add the script to startup tasks 
      addcronjob    
      #addbmcresetter  #Not required in the latest platform
      #(`$BROWSER "file://$ROOTdir/License/ASCReadMe.txt" 1>/dev/null 2>/dev/null `)
      echo -e "\033[31m!!Warning...!!!!\033[0m"
      echo -e "Please check DNS server setting or add the hostname into system file /etc/hosts in order for the Active System Console to do name resolution for the system name to avoid login fail issue,"
      echo -e "refer to the software Release Notes for details."
   else 
	echo "Can not locate Installation Files, make sure *i586.rpms exist." 
   fi; 
 
    
fi;
