#!/bin/sh

# Generate Slackware package to install scc by means of installpkg.
# Copyright (C) 2006-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.7 $

# 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
#
# It uses the following programs:
#
#	tar
#	gzip
#
# After using this program, the directory contains one file:
#
#	scc-1.9.28-noarch-1.tgz
#

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"
version=${scc_release%.*}		# Ignore the patch-level
patch=${scc_release##*.}

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

mkdir -p software/install
mv install/doinst.sh software/install
chmod 500 software/install/doinst.sh

{
	# 11 lines for proper formatting.
	echo "scc: System Configuration Collector"
	echo "scc:"
	echo "scc: SCC collects configuration data from Unix/Linux/*BSD systems."
	echo "scc: Changes in the configuration are detected and added to a logbook."
	echo "scc:"
	echo "scc: Homepage: http://scc.qnh-infrastructure.nl/index.html"
	echo "scc:"
	echo "scc:"
	echo "scc:"
	echo "scc:"
	echo "scc:"
} >software/install/slack-desc

cd software
# Slackware installpkg forces the ownership and permissions from our
# directories and files upon the directories and files that are already
# present on the system. Avoid that directories like /opt and /var/opt
# are not accessible for ordinary users.
find . -type f | xargs chown root:root
find . -type d | xargs chown root:root
chmod 755 opt
chmod 755 var var/opt

tar cf ../scc-${version}.${patch}-noarch-1.tar .
cd ..
gzip scc-${version}.${patch}-noarch-1.tar
mv scc-${version}.${patch}-noarch-1.tar.gz scc-${version}.${patch}-noarch-1.tgz

rm -rf software  install $(cat file_list)

exit 0
