#!/bin/bash
# Features common to all the Dell update scripts
# Set SRCDIR in the parent script (you'll have to anyways to reference this include)
#################################################

if [ -z "$SRCDIR" ]; then
 echo "Have to set SRCDIR before sourcing this script"
 exit 1
fi

# Scan for SL release version
RELEASE=0
grep Beryllium /etc/redhat-release &> /dev/null
if [ $? -eq 0 ]; then
    RELEASE=4
fi
grep Boron /etc/redhat-release &> /dev/null
if [ $? -eq 0 ]; then
    RELEASE=5
fi
grep Carbon /etc/redhat-release &> /dev/null
if [ $? -eq 0 ]; then
    RELEASE=6
fi
if [ $RELEASE -lt 5 ]; then
    echo " This OS release not supported!"
    exit 2
fi

if [ "$1" !=  "" ]; then
  if [ -d "$1" ]; then
    SRCDIR="$1"
  else
    echo " Unable to find passed dirctory..stopping"
    exit 1
  fi
fi
echo " SRCDIR = $SRCDIR"

# Setup redhat-release
RHREL=/etc/redhat-release
RHREL_TMP=/etc/redhat-release.fw_up
echo "Mangling /etc/redhat-release" | tee -a /root/dell-updates.out
cp $RHREL $RHREL_TMP
# IF SL5 replace with RHEL5 needed string
sed -i 's/Boron/Tikanga/' /etc/redhat-release
# IF SL6 replace with RHEL6 needed string
sed -i 's/Carbon/Santiago/' /etc/redhat-release

echo "Stopping srvadmin-services..."
srvadmin-services.sh stop

# Unalias some things
unalias ls
unalias rm

# function to apply update and output
update() {
echo "Updating $1 ..." | tee -a /root/dell-updates.out
sh $SRCDIR/$2 -q | tee -a /root/dell-updates.out
}