#!/bin/sh
#############################################################################
#
# Licensed Materials - Property of IBM
#
# 5648-B90
# (C) COPYRIGHT International Business Machines Corp. 1993, 2000
#
# 5648-B91
# (C) COPYRIGHT International Business Machines Corp. 1993, 2000
#
# 5648-B95
# (C) COPYRIGHT International Business Machines Corp. 1993, 2000
#
# 5648-B97
# (C) COPYRIGHT International Business Machines Corp. 1993, 2000
#
# 5648-B99
# (C) COPYRIGHT International Business Machines Corp. 1993, 2000
#
# All Rights Reserved
# US Government Users Restricted Rights - Use, duplication or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
#############################################################################
#
# Filename      : db2_deinstall
# Type          : sh (Bourne shell)
# Function      : Generic script that calls platform specific script
#
########################################################################

#############################################################
##       Start of Variable and Constant definitions        ##
#############################################################

# Constants are set at beginning of execution and do no change (UPPSECASE)
# First get the OS and set up a number of commands
if [ -x /usr/bin/awk ]; then
    CMD_AWK="/usr/bin/awk"
elif [ -x /bin/awk ]; then
    CMD_AWK="/bin/awk"
fi

OSM=""
OSN=""
OSR=""

if [ -x /usr/bin/uname ]; then
    OSN=`/usr/bin/uname |  ${CMD_AWK?} '{print $1}'`
elif [ -x /bin/uname ]; then
    OSN=`/bin/uname | ${CMD_AWK?} '{print $1}'`
else
    while :
    do
        echo "Command 'uname' not found !  Please Specify OS :

                1) AIX
                2) SunOS
                3) HP-UX
                4) Linux 2.4
		5) Linux 2.6
                6) Linux IA64
                7) Linux OS/390
                8) Linux OS/390x
                9) Linux PPC\n"
        echo "Please Enter OS number :"
        read osNum
        case "${osNum?}" in
            1)  OSN="AIX"
                break ;;
            2)  OSN="SunOS"
                break ;;
            3)  OSN="HP-UX"
                break ;;
            4)  OSN="Linux"
                break ;;
            5)  OSN="Linux26"
                break ;;
            6)  OSN="Linux64"
                break ;;
            7)  OSN="Linux390"
                break ;;
            8)  OSN="Linux390x"
                break;;
            9)  OSN="LinuxPPC"
                break ;;
            *)  echo "\nInvalid number entered ... please try again" ;;
        esac
    done
fi

case ${OSN?} in
    "Linux"* ) BINDIR="" ;;
    *        ) BINDIR="/usr/bin/" ;;
esac


if [ "X${OSN?}" = "XLinux" ]; then
    OSM=`${BINDIR?}uname -m | ${BINDIR?}awk '{print $1}'`
    OSR=`${BINDIR?}uname -r | ${BINDIR?}awk '{print $1}' | cut -f1,2 -d.`
    if [ "X${OSR?}" = "X2.6" ]; then
        OSN="Linux26"
    fi
    if [ "X${OSM?}" = "Xs390" ]; then
        OSN="Linux390"
    elif [ "X${OSM?}" = "Xs390x" ]; then
        OSN="Linux390x"
    elif [ "X${OSM?}" = "Xppc64" ]; then
        OSN="LinuxPPC"
    elif [ "X${OSM?}" = "Xia64" ]; then
        OSN="Linux64"
    fi
fi  

CMD_BASENAME="${BINDIR?}basename"
CMD_DIRNAME="${BINDIR?}dirname"
CMD_PWD="${BINDIR?}pwd"
CMD_ECHO="${BINDIR?}echo"
CMD_LS="${BINDIR?}ls"

# Set the directory name where this file is located; cd into CURDIR
MYNAME=`${CMD_BASENAME?} $0`
CURDIR=`${CMD_PWD?}`
PROGDIR=`${CMD_DIRNAME?} $0`
cd ${PROGDIR?}
PROGDIR=`${CMD_PWD?}`
cd ${CURDIR?}

TRUE=0
FALSE=1
NULL='/dev/null'

#############################################################
##               Start of function definitions             ##
#############################################################

display_msg_lnx()
{
    unset support_kernel current_kernel
    support_kernel="$1"
    current_kernel="$2"
    ${CMD_ECHO?} "ERROR: There has been an attempt to uninstall DB2 with
the db2_deinstall in the DB2 image supported for the kernel 
level ${support_kernel?} that does not match the current kernel 
level ${current_kernel?} on which DB2 is being uninstalled.

User Response:

Uninstall DB2 using the db2_deinstall command in
the DB2 install image that corresponds with the 
current kernel level ${current_kernel?}.

Please check the following IBM web site for platforms and
kernel level officially supported by IBM DB2 Universal
Database for Linux:

http://www.ibm.com/software/data/db2/linux/validate/
    "

} # end of display_msg_lnx()
#############################################################
##                End of function definitions              ##
#############################################################


INSTALLDIR=${PROGDIR?}/db2
if [ ! -f "${INSTALLDIR?}/db2_deinstall" ]; then
    case ${OSN?} in
        "AIX")
            INSTALLDIR="${PROGDIR?}/db2/aix"      ;;
        "SunOS")
            INSTALLDIR="${PROGDIR?}/db2/solaris"  ;;
        "HP-UX")
         OSM=`${BINDIR?}uname -m`                         
          case ${OSM?} in                                
            "ia64") INSTALLDIR="${PROGDIR?}/db2/hpipf" ;;
                 *) INSTALLDIR="${PROGDIR?}/db2/hpux" ;; 
          esac                                           
          ;;                                             
        "UnixWare")
            INSTALLDIR="${PROGDIR?}/db2/scouw"    ;;
        "IRIX"|"IRIX64")
            INSTALLDIR="${PROGDIR?}/db2/sgi"      ;;
        "Linux")
            INSTALLDIR="${PROGDIR?}/db2/linux"    ;;
	"Linux26")
            INSTALLDIR="${PROGDIR?}/db2/linux26"    ;;
        "Linux390")
            INSTALLDIR="${PROGDIR?}/db2/linux390" ;;
        "Linux390x")
            INSTALLDIR="${PROGDIR?}/db2/linux390x" ;;
        "LinuxPPC")
            INSTALLDIR="${PROGDIR?}/db2/linuxppc" ;;    
        "Linux64")
            INSTALLDIR="${PROGDIR?}/db2/linux64"  ;;    
        *)
            ${CMD_ECHO?} "Error: Operating System not Supported."
            exit 1                                        ;;
    esac
    case ${OSN?} in
        "Linux")
           if [ -d "${PROGDIR?}/db2/linux26" ]; then
               display_msg_lnx "2.6" "${OSR?}"
               exit 1
           fi
           ;;
        "Linux26")
           if [ -d "${PROGDIR?}/db2/linux" ]; then
               display_msg_lnx "2.4" "${OSR?}"
               exit 1
           fi
           ;;
    esac

fi

if [ ${OSN?} = "Linux390x" ]; then
    ${CMD_LS?} -1 ${PROGDIR?}/db2/linux390/IBM_db2rtsg*  1>/dev/null 2>/dev/null
    SIGEXISTS=$?
    if [ ${SIGEXISTS?} -eq 0 ]; then
        INSTALLDIR="${PROGDIR?}/db2/linux390"
    fi
fi

if [ ! -f "${INSTALLDIR?}/db2_deinstall" ]; then
    ${CMD_ECHO?} "Error: Platform Specific Installer not Found."
    exit 1
fi

# If platform specific installer checks out, run it.
INSTALLER="db2_deinstall $*"
exec ${INSTALLDIR?}/${INSTALLER?}
