#!/bin/sh
#
# Installation script for the RSA Authentication Agent 5.3 for PAM.
#
#
#********************************************************************************
#* COPYRIGHT (C) 2003  by RSA Security Inc.
#*      ---ALL RIGHTS RESERVED---
#********************************************************************************
#
echo_no_nl_mode="unknown"
UNAME=`uname`
UNAMER=`uname -r`
MODULE_DIR="/usr/lib/security"
PAM_AGENT_MODULE="pam_securid"

##############################################################################
# Trap
#       this will trap any escape characters, and allow the program to abort normally
#       by calling abort_installation
##############################################################################
trap 'trap "" 1 2 15; abort_installation' 1 2 15

##############################################################################
# abort_installation()
# This subroutine removes files that were recently installed and restores
# the previous installation files, if they existed.
##############################################################################
abort_installation()
{
#CP__need to fix this when done. Make sure to set values for each file placed somewhere
echo ""
  echo "Aborting Un-install"

  exit 1
}

##############################################################################
# echo_no_nl()
#       Echo a string with no carriage return (if possible).  Must set
#       $echo_no_nl to "unknown" before using for the first time.
##############################################################################
echo_no_nl()
{
  if [ "$echo_no_nl_mode" = "unknown" ] ; then
     echo_test=`echo \\\c`
     if [ "$echo_test" = "\c" ] ; then
        echo_no_nl_mode="-n"
     else
        echo_no_nl_mode="\c"
     fi
  fi

  if [ "$echo_no_nl_mode" = "\c" ] ; then
     echo $* \\c
  else
     echo -n $*
  fi
}

##############################################################################
# getyesorno()
# Gets either a "yes" or a "no" in the traditional (y/n) pattern
#               $1      The default value if user hits <Enter> (TRUE/FALSE)
#               $2      The string to print to prompt the user
# The variable $YESORNO is set in accordance to what the user entered.
##############################################################################
getyesorno()
{
#####################################################
# Set up line parameters as $1 and $2 are overwritten
#####################################################
  yesornodef=$1
  yesornoprompt=$2

  YESORNO=""
  until [ -n "$YESORNO" ] ;
  do
    echo ""
    echo_no_nl $yesornoprompt
    read YESORNO

    case "$YESORNO"
    in
      y|Y )  YESORNO=TRUE;;
      n|N )  YESORNO=FALSE;;
      ''  )  YESORNO=$yesornodef;;
      *   )  echo ""
             echo "Please enter 'y', 'n' or '<return>' "
             YESORNO="";;
    esac
  done

}

check_user()
{
#########################
# make sure user is root
#########################


if [ "$USER_NAME" != root ]; then
    echo "You Must be ROOT to uninstall this agent"
    abort_installation
fi
}

############################################################
# Check to see if this is a supported platform.
############################################################
check_platform()
{
case $UNAME
   in
     'SunOS'  )  SUN_VERS=`echo $UNAMER `
               case "$SUN_VERS" in
               * )
                    WHOAMISOL=`/usr/ucb/whoami`
                    OS_DIR="sol"
                    OS_EXT="so"
                    USER_NAME=`echo $WHOAMISOL`;;
		esac;;

     'Linux' ) LNX_VERS=`echo $UNAMER `
                case "$LNX_VERS" in
                * )
                    WHOAMILNX=`/usr/bin/whoami`
                    OS_DIR="lnxas3"
                    OS_EXT="so"
                    MODULE_DIR="/lib/security"
                    USER_NAME=`echo $WHOAMILNX`;;
                esac;;
     'HP-UX' ) HP_VERS=`echo $UNAMER`
               case "$HP_VERS" in
               * )
                   WHOAMIHP11=`/bin/whoami`
                   OS_DIR="hp11"
                   OS_EXT="1"
                   USER_NAME=`echo $WHOAMIHP11`;;
               esac;;
     'AIX' ) AIX_VERS=`uname -vr | awk '{print $2 * 1000 + $1}'`
                case "$AIX_VERS" in
                *)
                    OS_DIR="aix"
                    OS_EXT="so";
                    USER_NAME=`/usr/bin/whoami`
                esac;;
     *   )  echo ""
            echo "Sorry, $UNAME is not currently supported."
            echo ""
            abort_installation ;;
esac
}

uninstall()
{
    rm -r bin
    rm -r lib
    rm -r doc
    rm /etc/sd_pam.conf
if [ "$OS_DIR" = "sol"  ] ; then
    rm /usr/lib/security/pam_securid.so
elif [ "$OS_DIR" = "lnxas3" ] ; then
    rm /lib/security/pam_securid.so
elif [ "$OS_DIR" = "hp11" ] ; then
    rm /usr/lib/security/pam_securid.1
elif [ "$OS_DIR" = "aix" ] ; then
    rm /usr/lib/security/pam_securid.so
fi
}

getyesorno FALSE "Are you sure that you would like to uninstall the RSA Authentication Agent 5.3 for PAM? (y/n) [n]"
if [ "$YESORNO" = FALSE ] ; then
    echo "Exiting without uninstalling the agent"
    abort_installation
else
    check_platform
    check_user
    uninstall
    echo ""
    echo "**********************************************************************"
    echo "* You have successfully uninstalled RSA Authentication Agent 5.3 for PAM"
    echo "* Please make sure to remove this directory to complete the uninstall"
    echo "**********************************************************************"
    echo ""
fi


