#!/bin/sh

# Generate RPM-file to install scc by means of rpm.
# Copyright (C) 2001-2004 Open Challenge B.V.
# Copyright (C) 2004-2005 OpenEyeT Professional Services.
# Copyright (C) 2005-2009 QNH.
#
# This program 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, or (at your option)
# any later version.
#
# This program 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; see the file COPYING.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Contact information: http://scc.qnh-infrastructure.nl/index.html 

# SCC-release:	1.9.28
# file-version:	$Revision: 1.24 $

# This program requires to be called in a directory with the following hierarchy:
#
#	install			pre/post install scripts
#	software/opt/scc	bin, doc and man
#	software/var/opt/scc	conf, data, newconfig and tmp
#
# After using this program, the directory contains one file:
#
#	scc-<release>.noarch.rpm
#

TESTING="testing"
x="$(echo "${TESTING}" 2>/dev/null)"
if [ "${x}" != "${TESTING}" ]
then
	exec /bin/ksh ${0} "$@"

	echo "${0}: cannot find ksh" >&2
	exit 2
fi

ProgName=${0##*/};			export ProgName

exe="$(which rpmbuild 2>/dev/null)"
if [ ! -x "${exe}" ]
then
	echo "${ProgName}: cannot find rpmbuild" >&2
	exit 2
fi

for f in *
do
	if [ -f "${f}" ]
	then
		echo "${f}"
	fi
done >file_list

start_dir=$(pwd)

scc_release="1.9.28"
version=${scc_release%.*}		# Ignore the path-level
patch=${scc_release##*.}

umask 077

sed	-e "s/^Version:.*/Version: ${version}/"	\
	-e "s/^Release:.*/Release: ${patch}/"	\
		<rpm-scc.spec		\
		>tmp.spec
mv -f tmp.spec rpm-scc.spec

BUILD_DIR=/tmp/ScC_BuIlD
rm -rf ${BUILD_DIR} 2>/dev/null
mkdir ${BUILD_DIR} 2>/dev/null
mv software rpm-scc.spec ${BUILD_DIR}

cd ${BUILD_DIR}/software
mkdir -p /tmp/RPMS/noarch
rpmbuild	--define='_rpmdir /tmp/RPMS'		\
		-bb					\
		../rpm-scc.spec

cd "${start_dir}"
mv /tmp/RPMS/noarch/scc-${version}-${patch}.noarch.rpm .
chmod 444 ./scc-${version}-${patch}.noarch.rpm

rm -rf ${BUILD_DIR} /tmp/RPMS
rm -rf install $(cat file_list)

exit 0
