#!/bin/sh
################################################################################
# $Id: create_union_rpm 158 2006-05-01 19:58:06Z makia $
################################################################################
#  Copyright (C) 2004 The Regents of the University of California.
#  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
#  Written by Makia Minich <makia@llnl.gov>
#  UCRL-CODE-155916
#  
#  This file is part of GeDI, a diskless image management tool.
#  For details, see <http://www.llnl.gov/linux/gedi/>.
#  
#  GeDI is free software; you can redistribute it and/or modify it under
#  the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
#  
#  GeDI 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 GeDI; if not, write to the Free Software Foundation, Inc.,
#  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
################################################################################

# Source function library.
. /etc/sysconfig/gedi

usage () {
   echo "usage: $(basename $0) <kernel version>"
   echo ""
   echo "       (ex: $(basename $0) 2.6.9-34.EL)"
   exit 1
}

[ $# -ne 1 ] && usage
KVERS=$1

if [ ! -d /lib/modules/${KVERS}/build ] ; then
   echo "${KVERS} sources are not available; exiting"
   exit
fi

cp ${UNIONDIR}/unionfs-${UNIONFSVER}* /usr/src/redhat/SOURCES
sed -e "s/#UNION#/${UNIONFSVER}/ ; \
        s/#KERNEL#/${KVERS}/" ${UNIONDIR}/unionfs.spec > \
   /usr/src/redhat/SPECS/unionfs.spec

rpmbuild -bb /usr/src/redhat/SPECS/unionfs.spec

RPM=$(find /usr/src/redhat/RPMS -name "unionfs-${UNIONFSVER}*rpm")
[ -n "${RPM}" ] && rpm -Uvh ${RPM} --force

rm -rf /usr/src/redhat/BUILD/unionfs*
rm -rf /usr/src/redhat/SPECS/unionfs*
rm -rf /usr/src/redhat/SOURCES/unionfs*
rm -rf /usr/src/redhat/RPMS/noarch/unionfs*
