#!/bin/bash

COMMONUTILS=/usr/sbin/vpxd_commonutils

. $COMMONUTILS

# Utilities
VPXD_ODBCCONFIG=/usr/sbin/vpxd_odbcconfig
AWK=/bin/awk
CP=/bin/cp
RM=/bin/rm
SERVICE=/sbin/service
HOSTNAME=/bin/hostname
OPENSSL=/usr/bin/openssl
MKDIR=/bin/mkdir
CHMOD=/bin/chmod
CHOWN=/bin/chown
CHKCONFIG=/sbin/chkconfig
LIBVPXDIR=/usr/lib/vmware-vpx

echo "Setting up subsequent boot script"
echo "test -x /usr/sbin/vpxdva_subsequentboot && /usr/sbin/vpxdva_subsequentboot" >> /etc/init.d/boot.local

# first check if the cd is readable, because mount takes 15 seconds to fail
if dd if=/dev/cdrom of=/dev/null bs=1 count=1 &>/dev/null; then
   TMP_DIR=`mktemp -d`
   if mount /dev/cdrom "$TMP_DIR"; then
      CFG_FILE="$TMP_DIR/vcva.cfg"
      if [ -f "$CFG_FILE" ]; then
         HASH_MARKER="rootPwdHashMD5="
         HASH_LINE=`grep "$HASH_MARKER" "$CFG_FILE" 2>/dev/null`
         if [ "$?" = "0" ]; then
            echo "Setting root and GRUB passwords."
            HASH=`echo "$HASH_LINE" | cut -b $((${#HASH_MARKER}+1))-`
            passwd -d root > /dev/null
            sed -e "s:^root\:\::root\:$HASH\::g" -i /etc/shadow
            sed -e "s:^password --md5 .\+:password --md5 $HASH:g" -i /boot/grub/menu.lst
         else
            echo "root password hash not found in vcva.cfg. Using default."
         fi
      else
         echo "vcva.cfg not found on CD. Skipping configuration."
      fi
   else
      echo "Error: CD device contains a readable image that cannot be mounted."
   fi
   umount "$TMP_DIR"
   rmdir "$TMP_DIR"
fi

#PR #2008303: Increase ring buffer size during first and subsequent boots
/usr/sbin/ethtool -G eth0 rx 4096 rx-jumbo 4096 tx 4096
