#!/bin/sh
#
# installDir - install the directory
#
# SYNOPSIS: 
#      installDir [-m mode] [-o owner] [-g group] dest_dir
#

# Note LOG is from env - see isntallTreeps

MODE_ARG="755"
OWNER_ARG=
GROUP_ARG=
DEST=

while [ "$#" -gt "0" ]
do
        case $1 in

            -m ) MODE_ARG="$2" ; shift ; shift  ;;

            -o ) OWNER_ARG="$2" ; shift ; shift ;;

            -g ) GROUP_ARG="$2" ; shift ; shift ;;

             * ) break ;;
        esac
done

if [ $# != "1" ]
then
	exit 1
else
	DEST="$1"
fi

DIR_PATH="$DEST"

if [ ! -z "$PREFIX" ]
then
        DEST="$PREFIX$DEST"
fi

if [ ! -z "$INSTALL_ROOT" ]
then
        DEST="$INSTALL_ROOT$DEST"
fi

# Should check for creating other parts of the path above $DEST and
# ensure they have proper permissions(i.e. a bad umask can screw this up).

# Create dir, and set permissions

mkdir -p "$DEST"

if [ ! -z "$MODE_ARG" ]
then
    chmod "$MODE_ARG" "$DEST"
fi

if [ ! -z "$OWNER_ARG" ]
then
    chown "$OWNER_ARG" "$DEST"
fi

if [ ! -z "$GROUP_ARG" ]
then
    chgrp "$GROUP_ARG" "$DEST"
fi

mkInstallEntry -d $DIR_PATH >> $LOG

echo "$DEST"

