#!/bin/sh
#require id
#require makefiletop
#phase init
#after init_id
#phase makefile
#after makefile_makefiletop
case $PHASE in
	init)
		dispn "Creating installation script..."
		$ECHO "#!/bin/sh
FILENAME="\$2/\`basename \$1\`"
mkdir -p \$2
cp -f \$1 \$FILENAME
chown \$3:\$4 \$FILENAME
chmod \$5 \$FILENAME" > copy.sh
		chmod 0755 copy.sh
		INSTALL="./copy.sh"
		disp "done"

		dispn "Checking for installation username..."
		INSTALL_GROUP=`$ID -ng root`
		if test "$?" = "0"; then
			INSTALL_USER=root
			disp "found, \"root\""
		else
			disp "none found, aborting"
			exit 1
		fi

		dispn "Checking for installation group name..."
		if test "$INSTALL_GROUP" = ""; then
			disp "none found, aborting"
			exit 1
		else
			disp "found, \"$INSTALL_GROUP\""
		fi

		;;
	makefile)
		dispn "Writing install entry..."
		$ECHO -n "install:"
		if module binaries; then
			$ECHO -n " install_binaries"
		fi
		if module libraries; then
			$ECHO -n " install_libraries"
		fi
		if module man; then
			$ECHO -n " install_man"
		fi
		if module headers; then
			$ECHO -n " install_headers"
		fi
		if module conf; then
			$ECHO -n " install_conf"
		fi
		$ECHO
		$ECHO
		disp "done"

		dispn "Writing install cleanup entry..."
		$ECHO "clean_install:"
		$ECHO "	rm -f $INSTALL"
		$ECHO
		disp "done"
		;;
esac
