#!/bin/ksh

#
# set up internal parameters
#

SHOPSITE_DIRECTORY=$1
SHOPPING_CART_DIRECTORY=$2
SHOPSITE_IMAGE_DIR=$3
UNIX_WEB_USER_ID=$4
UNIX_WEB_GROUP_ID=$5
DEBUG_LOG_DIRECTORY=$6
DEBUG_LOG_FILE=$7
LOG_DEBUG=$8

#
# Functions
#



#
# print debug string to appropriate location
#
# $1=debug string to be printed
#
print_debug()
{
  ./debug_handler.ksh "$0" "mall" "$1" "$DEBUG_LOG_DIRECTORY" "$DEBUG_LOG_FILE" "$LOG_DEBUG"
}


#  Set correct file permissions on ShopSite directory files.
if test $SHOPSITE_DIRECTORY/start.cgi
then
    #  Set UNIX web user and group ids on all files.
    if ! chown -Rh $UNIX_WEB_USER_ID:$UNIX_WEB_GROUP_ID $SHOPSITE_DIRECTORY
    then
        print_debug "Warning: Could not change ownership to $UNIX_WEB_USER_ID:$UNIX_WEB_GROUP_ID"
        print_debug "         on or in the following directory:"
        print_debug "         $SHOPSITE_DIRECTORY"
        print_debug
    fi
    if ! chmod -R 774 $SHOPSITE_DIRECTORY
    then
        print_debug "Warning: Could not change permissions to 750"
        print_debug "         on or in the following directory:"
        print_debug "         $SHOPSITE_DIRECTORY"
        print_debug
    fi
#    There aren't any *.html files in the ShopSite directory!
#    if ! chmod 640 $SHOPSITE_DIRECTORY/*.html
#    then
#        print_debug "Warning: Could not change permissions to 640"
#        print_debug "         on the following files:"
#        print_debug "         $SHOPSITE_DIRECTORY/*.html"
#        print_debug
#    fi
    if ! chmod 640 $SHOPSITE_DIRECTORY/*.aa
    then
        print_debug "Warning: Could not change permissions to 640"
        print_debug "         on the following files:"
        print_debug "         $SHOPSITE_DIRECTORY/*.aa"
        print_debug
    fi
else
    print_debug "Warning: The following is not a valid ShopSite directory:"
    print_debug "         $SHOPSITE_DIRECTORY"
    print_debug
fi

if test -e $SHOPPING_CART_DIRECTORY/thankyou.cgi
then
    if ! chown -Rh $UNIX_WEB_USER_ID:$UNIX_WEB_GROUP_ID $SHOPPING_CART_DIRECTORY
    then
        print_debug "Warning: Could not change ownership to $UNIX_WEB_USER_ID:$UNIX_WEB_GROUP_ID"
        print_debug "         on or in the following directory:"
        print_debug "         $SHOPPING_CART_DIRECTORY"
        print_debug
    fi
    if ! chmod -R 774 $SHOPPING_CART_DIRECTORY
    then
        print_debug "Warning: Could not change permissions to 750"
        print_debug "         on or in the following directory:"
        print_debug "         $SHOPPING_CART_DIRECTORY"
        print_debug
    fi
    if ! chmod 640 $SHOPPING_CART_DIRECTORY/*.new
    then
        print_debug "Warning: Could not change permissions to 640"
        print_debug "         on the following files:"
        print_debug "         $SHOPPING_CART_DIRECTORY/*.new"
        print_debug
    fi
else
    print_debug "The following is not a valid Shopping Cart directory:"
    print_debug "         $SHOPPING_CART_DIRECTORY"
    print_debug
fi
