#!/bin/bash
#
#  The pkgbuild build engine
#
#  Copyright (C) 2004, 2005 Sun Microsystems, Inc.
#
#  pkgbuild is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License 
#  version 2 published by the Free Software Foundation.
#
#  pkgbuild is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#  As a special exception to the GNU General Public License, if you
#  distribute this file as part of a program that contains a
#  configuration script generated by Autoconf, you may include it under
#  the same distribution terms that you use for the rest of that program.
#
#  Authors:  Laszlo Peter  <laca@sun.com>
#

if [ "`uname -s`" = "SunOS" ]
then
    /usr/bin/id | /usr/bin/grep '^uid=0(' > /dev/null 2>&1
    if [ $? = 0 ]
    then
	echo "Building as root is dangerous and is no longer supported."
	echo "Please use a non-privileged account for running pkgtool."
	echo "When using pkgtool modes that involve package installation, you need an"
	echo "account with the 'Software Installation' profile.  See the user_attr(4)"
	echo "and profiles(1) man pages for more details."
	exit 1
    fi
fi

pkgbuild_prefix="/usr"
pkgbuild_libdir="/usr/lib/pkgbuild-1.3.104"
pkgbuild_bindir="${pkgbuild_prefix}/bin"
pkgbuild_wrapper="${pkgbuild_bindir}/pkgbuild"
pkgtool_implementation="${pkgbuild_libdir}/pkgtool.pl"

if [ ! -d "${pkgbuild_prefix}" -o \
     ! -d "${pkgbuild_libdir}" -o \
     ! -d "${pkgbuild_bindir}" -o \
     ! -x "${pkgbuild_wrapper}" -o \
     ! -f "${pkgtool_implementation}" ]
then
    echo "${0}: FATAL ERROR - pkgbuild implementation not found." 1>&2
    exit 1
fi

# Pass in the full path to the pkgbuild wrapper as the first command line argument
exec "/usr/bin/perl" -I "${pkgbuild_libdir}" "${pkgtool_implementation}" "${pkgbuild_wrapper}" "${@}"
