#!/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/index.html 

# SCC-release:	1.9.28
# 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	bin, doc and man
#	software/var/opt/scc	conf, data, newconfig and tmp
#
# After using this program, the directory contains one file:
#
#	scc-<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.9.28"
ls | grep -v file-list >file-list

mkdir scc-${scc_release}
mv software/* scc-${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-${scc_release}/pinstall.sh
chmod 500 scc-${scc_release}/pinstall.sh

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

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

find scc-${scc_release} | xargs chgrp root

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

rm -rf scc-${scc_release}.tar scc-${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
