#!/bin/bash

if ! [ -f options ]; then 
  echo "Must run configure 1st"
  exit 1
fi

. options


# create the package
echo "Creating package."
eval `pkgsend open $pkgname`

pushd $basedir

# create/add directories
echo "Creating directories..."
for file in `find $contentdir -d`; do
  pkgsend add dir mode=0555 owner=root group=bin path="/$file"
done

# create/add all files
echo "Adding files..."
for file in `find $contentdir -type f`; do
  pkgsend add file $file
done

# set attribs for binary files
echo "Setting attributes for executable files..."
for file in `find $contentdir -perm /u=x -type f`; do
  pkgsend add file "$file" mode=0755 owner=root group=bin path="$file"
done

# set attribs for data files
echo "Setting attributes for data files..."
for file in `find $contentdir -perm /u=x -type f`; do
  pkgsend add file "$file" mode=0644 owner=root group=bin path="$file"
done

# add dependencies


# set pkg stuff
echo "Setting package info..."
pkgsend add set name=description value="$description"
pkgsend add set name=maintainer value="$maintainer"

echo "Closing transaction."
pkgsend close
