#!/bin/sh

# Generate pet-file to install scc by means of petget.
# Copyright (C) 2007-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

# SCC-release:	1.7.5
# file-version:	$Revision: 1.4 $

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

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

scc_release="1.7.5"
ls | grep -v file-list >file-list

mkdir scc-srv-${scc_release}
mv software/* scc-srv-${scc_release}

# The postinstall checks for a lock-file from the pre-install.
# As petget does not support a pre-install, we should not exit
# when the lock-file is absent. Remove the exit from the general postinstal.
sed -e '/exit 2/d' < install/postinstall >scc-srv-${scc_release}/pinstall.sh
chmod 500 scc-srv-${scc_release}/pinstall.sh

cp install/postremove scc-srv-${scc_release}/puninstall.sh
chmod 500 scc-srv-${scc_release}/puninstall.sh

{
	echo "PETMENUDESCR='System Configuration Collector Server'"
	echo "PETOFFICIALDEPS=''"
	echo "PETREGISTER='yes'"
} >scc-srv-${scc_release}/scc-srv-${scc_release}.pet.specs

find scc-srv-${scc_release} | xargs chgrp root

tar cf scc-srv-${scc_release}.tar scc-srv-${scc_release}
gzip <scc-srv-${scc_release}.tar >scc-srv-${scc_release}.pet

rm -rf scc-srv-${scc_release}.tar scc-srv-${scc_release}

# Cleanup of the all files except the produced pet-file.
while read entry
do
	if [ -f "${entry}" -o -d "${entry}" ]
	then
		rm -rf ${entry}
	fi
done <file-list
rm -f file-list

exit 0
