#!/bin/bash
#
# Usage: processWBFile.sh "BCOPY" <banner path/BannerFile.txt>
#                     or
#        processWBFile.sh "BREMOVE"
#                     or
#        processWBFile.sh "BCLEAN" <banner path/BannerFile.txt>
#                     or
#        processWBFile.sh "WCLEAN" <welcome path/WelcomeFile.txt>
#
# BCOPY command copies new banner file to /opt/hsc/data/ssh/ssh_banner.
# BREMOVE removes the /opt/hsc/data/ssh/ssh_banner file.
# BCLEAN removes the user's BannerFile.txt file.
# WCLEAN removes the user's WelcomeFile.txt file.
#
# Banner file must be name "BannerFile.txt".
# Welcome file must be name "WelcomeFile.txt".
#

validateBannerName() {
   if [ -e "$1" ]; then
      filename=`/bin/basename $1`
      if [ "$filename" != "BannerFile.txt" ]; then
         echo "Banner File must be named BannerFile.txt."
         exit 1
      fi
   else
      echo "Banner file was not specified or does not exist."
      exit 1
   fi
}

validateWelcomeName() {
   if [ -e "$1" ]; then
      filename=`/bin/basename $1`
      if [ "$filename" != "WelcomeFile.txt" ]; then
         echo "Welcome File must be named WelcomeFile.txt."
         exit 1
      fi
   else
      echo "Welcome file was not specified or does not exist."
      exit 1
   fi
}

if [ "$1" == "BCOPY" ]; then
   validateBannerName $2
   /bin/cp $2 /opt/hsc/data/ssh/ssh_banner
elif [ "$1" == "BREMOVE" ]; then
   /bin/rm -f /opt/hsc/data/ssh/ssh_banner
elif [ "$1" == "BCLEAN" ]; then
   validateBannerName $2
   /bin/rm -f $2
elif [ "$1" == "WCLEAN" ]; then
   validateWelcomeName $2
   /bin/rm -f $2
else
   echo "Invalid command. Use either BCOPY, BREMOVE, BCLEAN, or WCLEAN."
   exit 1
fi

exit 0
