#!/bin/ksh
#
# Script for creating dot directory containing a package signature file.
#
# For rps2, this script must reside in the rps2/bin directory.
# For OPS, this script must reside in the OPS/bin/rps2 directory.
#
#
# Usage:  make_dotdir.sh <dot dir parent> <package name> [<package alias>]
#

script_path=`whence $0` >/dev/null 2>&1
script_home=`dirname $script_path`

dotdir_parent=$1
package_name=$2
dotdir=${dotdir_parent}/.${package_name}

package_alias=$3
if [ -z "$package_alias" ]
    then package_alias=$package_name
fi

if [ ! -a $dotdir ] ; then
   echo Creating $dotdir"..."
   mkdir $dotdir
   cp $script_home/${package_name}_dotdir_signature $dotdir
else if [ ! -d $dotdir ] ; then
        echo =========================================
        echo $package_alias installation failed.
        echo Could not over write the file $dotdir.
	echo Remove $dotdir before installing $package_alias
        echo =========================================
	exit 1
     else if [ -a $dotdir/${package_name}_dotdir_signature ] ; then
             diff $script_home/${package_name}_dotdir_signature $dotdir > /dev/null
             if [ "$?" != "0" ] ; then
                echo =========================================
                echo $package_alias installation failed.
                echo $dotdir not created for $package_alias.
		echo Remove $dotdir before installing $package_alias
                echo =========================================
	        exit 1
             fi
          else
             echo ========================================
             echo $package_alias installation failed.
             echo $dotdir not created for $package_alias.
	     echo Remove $dotdir before installing $package_alias
             echo =========================================
	     exit 1
          fi
     fi
fi
