#
# This script is executed after the patch is backed out
#
#################################################################################
# Exit codes for installation scripts 
#################################################################################

e_ok=0	       # script completed successfully.
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on. 
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
               # To be added to one of the single-digit exit code above
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit code above

LS="/bin/ls"
RM="/bin/rm"
LN="/bin/ln"
WC="/bin/wc"
TR="/bin/tr"
AWK="/bin/awk"
NAWK="/bin/nawk"
SED="/bin/sed"
CUT="/bin/cut"
ECHO="/bin/echo"
GREP="/bin/grep"
CHOWN="/bin/chown"
SORT="/bin/sort"
HEAD="/bin/head"
TAIL="/bin/tail"
PKGPARAM="/bin/pkgparam"
UNAME="/bin/uname"


PKG="SUNWics5"
BASEDIR=`pkgparam -R $ROOTDIR $PKG BASEDIR`

#Root directory
PKG_INSTALL_ROOT="$ROOTDIR"
if [ "$PKG_INSTALL_ROOT" = "/" ]; then
  PKG_INSTALL_ROOT=""
fi

BASEINSTALL="$PKG_INSTALL_ROOT$BASEDIR/$PKG/cal/"

# Removes the directory that were added by the patch
DIRS_TO_REMOVE="config-template/de config-template/en config-template/es config-template/fr config-template/ja config-template/ko config-template/zh config-template/zh_TW config-template/schema config-template"

for DIR in $DIRS_TO_REMOVE
do
  cur_dir=$BASEINSTALL$DIR
  if [ -d $cur_dir ]
  then
    # Count the number of entries in each directory to remove
    # the backout of the patch should have taken care of removing 
    # every entries in these directories, so just check there empty
    # before removing them
    dir_size=0
    dir_list=`ls $cur_dir` 
    for dir_entry in $dir_list;
    do
      dir_size=`expr $dir_size + 1`
    done

    if [ $dir_size -eq 0 ] 
    then
      echo "Removing $cur_dir"
      rm -rf $cur_dir
    fi
  fi
done