#!/bin/sh

# Shell script to run before the install of the scc software.
# Copyright (C) 2001-2004 Open Challenge B.V.
# Copyright (C) 2004-2005 OpenEyeT Professional Services.
#
# 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: www.OpenEyeT.nl/scc/index.html 

# SCC-release:	1.6.26
# file-version:	$Revision: 1.3 $

# Do not use POSIX features in this script as it can be sourced by a non-POSIX system shell!

SCC_BIN=/opt/scc/bin
SCC_TOP=/var/opt/scc
export SCC_BIN SCC_TOP

SCC_DATA=${SCC_TOP}/data
SCC_TMP=${SCC_TOP}/tmp
SCC_CONF=/etc/opt/scc/conf
export SCC_DATA SCC_TMP SCC_CONF

# Avoid too strict permissions for newly created /var/opt directory.
# Otherwise scc-srv will not work correctly.
umask 022
mkdir -p ${SCC_TOP} 2>/dev/null

umask 077
mkdir -p ${SCC_DATA} ${SCC_TMP} 2>/dev/null

name=`uname -n | sed -e 's/\..*//'`

# Just before the install we run the current version to detect any changes
# in the configuration of the system. After the install we remove the current
# snapshot to avoid comparison of the snapshots. This enables us to change
# the format of the snapshots without flooding the log files with differences.
if [ -x ${SCC_BIN}/scc-log ]
then
	echo "NOTE:    Running scc to create a snapshot with the current"
	echo "NOTE:    version of the software. This may take some minutes."

	if [ -f ${SCC_DATA}/scc.${name}.lock ]
	then
		echo "ERROR:   install aborted, another instance of scc"
		echo "ERROR:   is active."
		exit 2
	else
		# During installs on HP-UX stm often hangs; do not run it.
		SCC_IGNORE_STM="yes";			export SCC_IGNORE_STM

		# During installs, rpm is locked; indicate the installation phase:
		SCC_INSTALL_PHASE="preinstall";		export SCC_INSTALL_PHASE

		${SCC_BIN}/scc-log
	fi
fi

# Avoid that scc is started between the pre- and the post-install.
# We create the lock-file for scc-log together with a file indicating to 
# the postinstall that the install is running.
touch ${SCC_DATA}/scc.${name}.lock ${SCC_DATA}/scc.${name}.install

exit 0
