#!/bin/sh
#
# Build a binary RPM package.  (RedHat Package Management)
#
# One RPM is built for each program group. 
#
# Invocation:      sh/build-rpm  GROUP
#
# GROUP is one of the program groups.  See `grp' for a list of
# groups. 
#
# More info on RPM at <http://www.rpm.org/>. 
#
# All files for this group must be built. 
#

. sh/temp-dir.sh
. sh/version-number.sh
. sh/tools.sh
. sh/verbose.sh
. sh/web-site.sh

if [ -z "$1" ]
then
    echo "$0:  *** error:  missing group name."
    echo "Invocation:   $0 GROUP"
    exit 1
fi

#if [ "$install_locally" ]
#then
#    echo "$0:  *** error:  \$install_locally must not be defined."
#    exit 1
#fi

group="$1"
groups=$group
# set $groups to just this one group. 

echo 1>&4 "Building RPM of group $group."

#sh/clean

tmp="$temp_dir/baby$group-$version_number-1.spec"

install_root="$temp_dir/baby-buildroot-${$}"
install_dir=/usr

skip_home=t

export groups install_root skip_home install_dir

sh/install

{
    grep '^Summary:' "grp/$group"
    echo "Name:  baby$group"
    echo "Version:  $version_number"
    echo "Release:  1"
    echo "Copyright:  GPL"
    grep '^Group:'  "grp/$group"
    echo "Source:  $web_site"
    echo "BuildRoot: $install_root"
    echo

    echo "%description"
    cat "grp/$group.description"
    echo

    echo "%prep"
    echo 

    echo "%build"
    echo

    echo "%install"
    echo

    echo "%clean"
    echo "rm -fr \$RPM_BUILD_ROOT"
    echo

    echo "%files"
    find "$install_root/" -not -type d \
    | $sed 's|^/[^ /]*/[^ /]*\(.*\)$|\1|' \
    | {
	while read file
	do
	    if echo $file | grep '/baby_[a-z_0-9]*' >/dev/null
	    then
		echo '%defattr(755,root,root)'
	    else
		echo '%defattr(644,root,root)'
	    fi
	    echo \"$file\"
	done
    }
    

    echo

} >"$tmp"

sh/do rpm -bb "$tmp" 

sh/do cp /usr/src/RPM/RPMS/i586/baby$group-$version_number-1.i586.rpm bin/baby$group-$version_number-1.rpm 

exit 0
