#!/bin/sh -e
#
# Reads debian/dirs, creates the directories listed there there

PATH=debian:$PATH:/usr/lib/debhelper
. dh_lib

for PACKAGE in $DH_DOPACKAGES; do
	TMP=`tmpdir $PACKAGE`
	file=`pkgfile $PACKAGE dirs`

	if [ ! -d $TMP ]; then
		doit "install -d $TMP"
	fi

	dirs=""

	if [ "$file" ]; then
		dirs=`tr "\n" " " < $file`
	fi

	if [ \( "$PACKAGE" = "$DH_FIRSTPACKAGE" -o "$DH_PARAMS_ALL" \) \
	     -a "$*" ]; then
		dirs="$* $dirs"
	fi

	if [ "$dirs" ]; then
		# Check to see if any of the dirs are absolute.
		for dir in "$dirs" ; do
			if expr "$dir" : "/" >/dev/null ; then
				error "Absolute directory name \"$dir\" specified."
			fi
		done
		# Create dirs.
		olddir=`pwd`
		doit "cd $TMP"
		doit "install -d $dirs"
		doit "cd $olddir"
	fi
done
