#!/bin/sh## Install file for TestDrive 2004 release 2#### Define perforce Variables#perforce_fileid="$Id: //apps/sap/tools/Linux/testdrive/09_2004/install.sh#6 $"revision="$Revision: #6 $"revdate="$Date: 2004/09/21 $"## Define local Variables#alias_name=""fake_hostname="nw4host"ip_address=""ip_pool="195.155.155.1 198.168.155.1 196.155.168.1 193.168.155.1"sap_rpm1=sapj2ee-srv-sapdb-6.40-2.i386.rpmsap_rpm2=sapdb-7.5-2.i386.rpmsap_rpm3=sapdb-db-log-7.5-2.i386.rpmsap_rpm4=sapdb-db-files-7.5-2.i386.rpm# sap_rpm5=sapj2ee-start-sapdb-640-1.i386.rpmplatin_rpm=PlatinGUI-Linux-6.30-4.i386.rpmsap_client="${platin_rpm}"sap_server_rpm_all="${sap_rpm1} ${sap_rpm2} ${sap_rpm3} ${sap_rpm4} ${sap_rpm5}"sap_client_rpm_all="${platin_rpm} "dvd_dist_dir=server/RPMS/i386dvd_dist_dir_client=client/RPMS/i386supported_string="SuSE 9.0 / RH Fedora Core 1"# Global Distribution Directoryrpm_dist_dir=""vendor_name=""log_file=""installed_jdk_home=""## End Define### Define ERRORS section#ERR_invalid_args=1ERR_no_suid=2ERR_nor_rpms_found=3ERR_unknown_vendor=4ERR_no_ip_free=5ERR_no_jdk_found=6ERR_sap_no_eula=7ERR_sap_eula_refused=8ERR_create_xuser_failed=9ERR_rpm_install=10ERR_last=11err_message[0]="Ok"err_message[1]="Invalid Arguments."err_message[2]="You should be root to start this program."err_message[3]="No sap RPMs found."err_message[4]="This installation support only ${supported_string}"err_message[5]="No free IP Address found using the following list : ${ip_pool}"err_message[6]="No Java Runtime found."err_message[7]="No SAPEULA License found."err_message[8]="License terms refused."err_message[9]="Creation of .XUSER.62 failed."err_message[10]="RPM Error."err_message[11]=""## End Define ERROR section### Functions#log() {log_value=$1if [ -z "${log_file}" ]; then log_file=./install.logfiecho -e "${log_value}" >> ${log_file}}do_exit() { exit_code=$1 if [ ${exit_code} -le ${ERR_last} ]; then echo -e "${err_message[${exit_code}]}" fi exit ${exit_code}}add_to_file() { line_to_add=$1 filename=$2 _res=`grep -v "${line_to_add}" ${filename} | grep "${line_to_add}"` if [ -z "${_res}" ]; then echo -e "${line_to_add}" >> ${filename} fi}show_help() { cat << EOFUsage: install.shDESCRIPTION: The install script will install the SAP WebAS 6.40 on your Linux. To install just call install.sh. You should be root to start this programm. EOFdo_exit ${ERR_invalid_args}}check_vendor () { cat /etc/*release | grep -i 'suse' # # TO-DO Check Version if [ $? -eq 0 ]; then vendor_name=suse else vendor_name=rh fi # TO-DO exit ${ERR_unknown_vendor}}## Check the distribution Directory# All files to be installed must be present#check_dist () { drive=${1} dirname=${drive}/${dvd_dist_dir} for name in ${sap_server_rpm_all} do if [ ! -r ${dirname}/${name} ]; then echo -e "File ${dirname}/${name} not found." do_exit ${ERR_nor_rpms_found} fi done rpm_dist_dir=${dirname} dirname=${drive}/${dvd_dist_dir_client} for name in ${sap_client_rpm_all} do if [ ! -r ${dirname}/${name} ]; then echo -e "File ${dirname}/${name} not found." do_exit ${ERR_nor_rpms_found} fi done rpm_dist_dir_client=${dirname}}## Update the necessary information in sysctl.conf to start SAPWebAS 6.40#update_sysctl() { # # Check vendor name and set the relative values # if [ "${vendor_name}" = "suse" ]; then varlist="kernel.shmmax=2313682943 kernel.msgmni=1024 fs.file-max=8192 vm.heap-stack-gap=256" else varlist="kernel.shmmax=2313682943 kernel.msgmni=1024 fs.file-max=8192" fi # # Update of sysctl.conf # # Every entry is a pair <value_name/key>=<value> # The routin search every key in /etc/sysctl.conf # if the key doesn't exist the pair is inserted in echo_args. # if the key exist but the value of this are less than the requested value, # then pair is inserted in sed_args. # The two list echo_args and sed_args represents the "to-do" actions for the following routines. # # If a change of /etc/sysctl.conf are maked a original copy is saved as /etc/sysctl.conf.testdrive proc_sys_path=/proc/sys sysctlpath=/etc/sysctl.conf act=0 backup_file_created=0; sed_args="" echo_args="" [ ! -e ${sysctlpath} ] && touch ${sysctlpath} for i in ${varlist} do varname=`echo ${i} | cut --delimiter='=' --fields=1` varvalue=`echo ${i} | cut --delimiter='=' --fields=2` varname_path=`echo -e "${varname}" | sed -e 's@\.@/@g'` if [ -e "${proc_sys_path}/${varname_path}" ]; then ff=`grep "${varname}" ${sysctlpath}` if [ $? -eq 0 ]; then ll=`grep "${varname}" ${sysctlpath} | cut --delimiter='=' --fields=2` if [ ${ll} -lt ${varvalue} ]; then sed_args="${sed_args}-e 's/${ff}/${varname}=${varvalue}/g' " fi else echo_args="${echo_args} ${varname}=${varvalue} " fi else echo -e "" fi done if [ -n "${sed_args}" ]; then act=1 mv -f ${sysctlpath} ${sysctlpath}.testdrive cmd="sed ${sed_args} ${sysctlpath}.testdrive >> ${sysctlpath}" eval ${cmd} fi if [ -n "${echo_args}" ]; then if [ ! -r ${sysctlpath}.testdrive ]; then mv -f ${sysctlpath} ${sysctlpath}.testdrive fi for ii in ${echo_args} do echo -e ${ii} >> ${sysctlpath} done act=1 fi if [ ${act} -gt 0 ]; then if [ "${vendor_name}" = "suse" ]; then # Add to Runlevel 1 3 and 5 by reboot the `sysctrl -p` _return_val=`insserv /etc/init.d/boot.sysctl,start=1,3,5` fi # check return value of insserv sysctl -p fi}## search for a free IP address to use with a fake interface#search_free_ip_address () { for i in ${ip_pool} do l=`netstat -ei | grep "${i}"` if [ -z "${l}" ]; then ip_address=${i} break fi done if [ -z "${ip_address}" ]; then do_exit ${ERR_no_ip_free} fi}## Search for a free alias device name for the fake interface (ex. eth0:1)#search_free_alias() { NN=$1 for i in `seq 0 10` do alias="${NN}:${i}" l=`netstat -ei | grep "^${alias}"` if [ -z "${l}" ]; then alias_name=${alias} set +x break fi done}## Activate in the differen distributions (SuSE , RedHat) the fake interface by reboot# and call ifconfig to activate it immediately.#activate_network_alias() { #echo "ifconfig ${alias_name} ${ip_address} up" pairs="BOOTPROTO=static DEVICE=${alias_name} IPADDR=${ip_address} NETMASK=255.255.255.0" _res=`ifconfig ${alias_name} ${ip_address} up ` if [ "${vendor_name}" = "rh" ]; then directory=/etc/sysconfig/network-scripts pairs="${pairs} ONBOOT=yes" else directory=/etc/sysconfig/network pairs="${pairs} STARTMODE=onboot" fi filename=${directory}/ifcfg-${alias_name} for i in ${pairs} do echo -e "${i}" >> ${filename} done text=`grep '${fake_hostname}' /etc/hosts` if [ $? -eq 0 ]; then `echo -e "${text}" | grep ${ip_address}` if [ $? -ne 0 ]; then echo -e "Hostname ${fake_hostname} used with a different address as ${ip_address}." echo -e "Please change it and restart the installation." fi else echo -e "${ip_address}\t${fake_hostname}" >> /etc/hosts fi}check_fake_interface() { text=`grep "${fake_hostname}" /etc/hosts | head -n 1` if [ $? -eq 0 ]; then # nw4host exist ip_a=`echo -e "${text}" | awk '{ print $1}' | head -n 1` if [ -n "${ip_a}" ]; then _res=`LANG=C netstat -ei | grep -vi 'kernel' | grep -vi '^iface' | grep -vi '^lo' | grep -B1 ${ip_a}` if [ -n "${_res}" ]; then if_dev=`echo -e "${_res}" | awk '{ print $1 }'` echo -e "Device ${if_dev} used for hostname ${fake_hostname}" to_be_created=1 fi fi else # nw4host doesn't exist to_be_created=0 fi}## This function create a fake network interface to be used with the # sap system the name of this fake interface are dynamically get.# The hostname assigned at thi interface are nw4host#create_fake_interface () { to_be_created=0 check_fake_interface if [ ${to_be_created} -eq 0 ]; then # head make sure that only the 1.st line are readed. _val=`LANG=C netstat -ei | grep -vi 'kernel' | grep -vi '^iface' | grep -vi '^lo' | head -n 1` interface_name=`echo ${_val} | awk '{ print $1}'` search_free_alias ${interface_name} search_free_ip_address echo "Found interface: ${interface_name} . Alias is ${alias_name}" echo "ifconfig ${alias_name} ${ip_address} up" activate_network_alias else echo -e "Hostname ${fake_hostname} already configured." fi}do_redhat_specific () { if [ "${vendor_name}" = "rh" ]; then add_to_file "setenv LD_ASSUME_KERNEL 2.2.5" ~nw4adm/.cshrc fi}search_rpm_installed_jdk() { jdk_val="" to_se="j2sdk sdk jdk jre" for val in ${to_se} do vv=`rpm -qa | grep "${val}"` if [ -n "${vv}" ]; then cnt=`echo -e "${vv}" | wc -l` for i in `seq 1 ${cnt}` do pack_name=`echo -e "${vv}" | head -n ${i}` _jdk_installed=`rpm -ql ${pack_name} | grep 'bin/javac$' | head -n 1` if [ -n "${_jdk_installed}" ]; then jdk_val=${_jdk_installed} break fi _jdk_installed=`rpm -ql ${pack_name} | grep 'bin/java$' | head -n 1` if [ -n "${_jdk_installed}" ]; then jdk_val=${_jdk_installed} break fi done fi if [ -n "${jdk_val}" ]; then break fi done}get_installed_java_info () { if [ -n "${JAVA_ROOT}" -a -d "${JAVA_ROOT}" ]; then jdk_val=${JAVA_ROOT} elif [ -n "${JAVA_HOME}" -a -d "${JAVA_HOME}" ]; then if [ -x "${JAVA_HOME}/bin/java" ]; then jdk_val=${JAVA_HOME}/bin/java fi elif [ -n "${JAVA_BINDIR}" -a -d "${JAVA_HOME}" ]; then if [ -x "${JAVA_BINDIR}/java" ]; then jdk_val=${JAVA_BINDIR}/java fi else jdk_val=`which javac 2> /dev/null` if [ $? -ne 0 ]; then jdk_val=`which java 2> /dev/null` if [ $? -ne 0 ]; then search_rpm_installed_jdk if [ -z "${jdk_val}" ]; then do_exit ${ERR_no_jdk_found} fi fi fi fi # # if the value of installed_jdk_home point to a link resolve the link # installed_jdk_home=`echo -e "${jdk_val}" | sed -e "s@/bin/javac@@g" -e "s@/bin/java@@g"` llnk=`readlink -f ${installed_jdk_home}` if [ $? -eq 0 ]; then installed_jdk_home=${llnk} fi if [ ! -d /usr/lib/java ]; then _res=`ln -fs "${installed_jdk_home}" /usr/lib/java` else # if the existen link point to a different directory # the link target will be resetted link=`readlink -f /usr/lib/java` if [ "${link}" != "${installed_jdk_home}" ]; then rm -f /usr/lib/java _res=`ln -s ${installed_jdk_home} /usr/lib/java` fi fi}## Update startup informations in .cshrc#update_cshrc () { do_redhat_specific vv=`find ${installed_jdk_home} -name 'libjvm.so'` if [ -n "${vv}" ]; then vv1=`echo -e "${vv}" | grep 'server/libjvm.so$'` if [ -z "${vv1}" ]; then vv1=`echo -e ${vv} | head -n 1` fi vv2=`echo -e ${vv1} | sed -e 's@/server/libjvm.so$@@g'` vv3=`echo -e ${vv1} | sed -e 's@/libjvm.so$@@g'` add_to_file "setenv LD_LIBRARY_PATH \${LD_LIBRARY_PATH}:${vv2}:${vv3}" ~nw4adm/.cshrc else echo "" # to-do error no libjvm.so found / inconsistent JVM installation fi add_to_file "setenv LD_ASSUME_KERNEL 2.4.1" ~nw4adm/.cshrc}## Update the /etc/services #update_service_file () { lot[0]="sapmsNW4 3600/tcp # SAP System Message Port" lot[1]="sapdp00 3200/tcp # SAP System Dispatcher Port" lot[2]="sapdp00s 4700/tcp # SAP System Dispatcher Security Port" lot[3]="sapgw00 3300/tcp # SAP System Gateway Central Instance Port" lot[4]="sapgw00s 4800/tcp # SAP System Gateway Security Port" lot[5]="sapdbni72 7269/tcp" lot[6]="sapdp01 3201/tcp # SAP System Dispatcher Port" lot[7]="sapdp01s 4701/tcp # SAP System Dispatcher Security Port" lot[8]="sapgw01 3301/tcp # SAP System Gateway Port" lot[9]="sapgw01s 4801/tcp # SAP System Gateway Security Port" lot[10]="sql6 7210/tcp # SAP DB" lot[11]="sql30 7200/tcp # SAP DB" _service_file=/etc/services to_deactivate="" let "lot_len = ${#lot[@]} - 1" for i in `seq 0 ${lot_len}` do _port=`echo "${lot[$i]}" | awk '{ print $2 }'` _oo=`grep "${_port}" ${_service_file} | grep -v "^#" | awk '{print $1}'` if [ -z "${_oo}" ]; then echo -e "${lot[$i]}" >> ${_service_file} else col_1=`echo "${lot[$i]}" | awk '{print $1}'` if [ "${_oo}" != "${col_1}" ]; then to_deactivate="${to_deactivate}-e 's/${_oo}/#&/g' " echo -e "Service ${_oo} on port ${_port} was deactivated... " echo -e "${lot[$i]}" >> ${_service_file} fi fi done if [ -n "${to_deactivate}" ]; then mv -f ${_service_file} ${_service_file}.testdrive cmd="sed ${to_deactivate} ${_service_file}.testdrive >> ${_service_file} " eval ${cmd} fi}## Install the .XUSER.62 file necessary for sap to access in the database#create_db_user_file() { _user=nw4adm temp_file=/tmp/.XUSER.${_user}cat > ${temp_file} << EOF3DEFAULTSAPNW4SAPNW4nw4hostSAPR3-100c_J2EECONTROLCONTROLNW4nw4host-1-1-1wSUPERDBASUPERDBANW4nw4host-1-1-1cCONTROLCONTROLNW4nw4host-1-1-1EOF3 if [ $? -eq 0 ]; then _o=`su -c "rm -f .XUSER.62; /sapdb/programs/bin/xuser -b ${temp_file}; [ -r .XUSER.62 ] && echo OK" - ${_user} | awk '/OK$/{printf("OK")} /ERR$/{printf("ERR")}'` if [ "$_o" != "OK" ]; then echo "could not write db password file for ${_user}" do_exit ${ERR_create_xuser_failed} fi else echo "could not create file ${temp_file}" do_exit ${ERR_create_xuser_failed} fi rm -f ${temp_file}_user=sqdnw4temp_file=/tmp/.XUSER.${_user} cat > ${temp_file} << EOF2DEFAULTSAPNW4sapNW4nw4hostSAPR3-100cCONTROLCONTROLNW4nw4host-1-1-1c_J2EECONTROLCONTROLNW4nw4host-1-1-1wSUPERDBAADMINNW4nw4host-1-1-1EOF2 if [ $? -eq 0 ]; then _o=`su -c "rm -f .XUSER.62; /sapdb/programs/bin/xuser -b ${temp_file}; [ -r .XUSER.62 ] && echo OK" - ${_user} | awk '/OK$/{printf("OK")} /ERR$/{printf("ERR")}'` if [ "$_o" != "OK" ]; then echo "could not write db password file for ${_user}" do_exit ${ERR_create_xuser_failed} fi else echo "could not create file ${temp_file}" do_exit ${ERR_create_xuser_failed} fi rm -f ${temp_file}}## Install a rpm file#install_rpm() { rpm_filepath=${1} rpm_filename=`basename ${rpm_filepath}` packname=`echo ${rpm_filename} | sed -e 's/\.i386\.rpm//g'` rpm -qi ${packname} >> /dev/null if [ $? -ne 0 ]; then echo -e "Installing ${packname} ...." cmdline="rpm -Uvh --force --nodeps ${rpm_filepath}" eval ${cmdline} if [ $? -ne 0 ]; then echo "Error installing ${rpm_filepath}" do_exit ${ERR_rpm_install} fi else echo "The package ${packname} is already installed." fi}server_pre_install() { get_installed_java_info}client_pre_install () { echo ""}## Install main routine for the SAP WebAS Server#server_install () { server_pre_install for rpm_file in ${sap_server_rpm_all} do install_rpm ${rpm_dist_dir}/${rpm_file} done # create the fake network interface and the hostname nw4host create_fake_interface update_service_file # call update sysctl update_sysctl update_cshrc create_db_user_file}## Install main routine for the SAP PlatinGUI#client_install() { client_pre_install for rpm_file in ${sap_client_rpm_all} do echo "${rpm_dist_dir_client}/${rpm_file}" install_rpm ${rpm_dist_dir_client}/${rpm_file} done}show_license () { a=0; sap_eula_path=/mnt/SAP/SAPEULA dialog --textbox ${sap_eula_path} 600 400 &> /dev/null if [ $? -ne 0 ]; then dialog --textbox ${sap_eula_path} 25 80 if [ $? -ne 0 ]; then clear do_exit ${ERR_sap_no_eula} fi dialog --yesno "Do you agree to the above license terms ?" 10 50 if [ $? -ne 0 ]; then clear do_exit ${ERR_sap_eula_refused} fi else dialog --yesno "Do you agree to the above license terms ?" 10 50 if [ $? -ne 0 ]; then clear do_exit ${ERR_sap_eula_refused} fi fi}## End Functions############################################################### Main#############################################################argc=$#dvd_drive=`dirname ${0}`inst_type=server#if [ ${argc} -lt 1 ]; then# show_help;#elif [ ${argc} -eq 1 ]; then inst_type=${1}fi## Check for root#if [ `id -u` != "0" ]; then #echo -e "You should be root to start this program" do_exit ${ERR_no_suid} ficheck_dist ${dvd_drive}check_vendorshow_licensecase ${inst_type} in all | All | ALL ) server_install ${dvd_drive} client_install ${dvd_drive} ;; client | Client | CLIENT ) client_install ${dvd_drive} ;; * ) server_install ${dvd_drive} ;;esacdo_exit 0############################################################