#!/bin/sh

. /usr/lib/linuxconf/install/rpm-identdist.sh

echo "#### /usr/lib/linuxconf/install/rpm-postinst.sh" >>/tmp/linuxconf-rpminstall.log
date >>/tmp/linuxconf-rpminstall.log

log(){
	echo $* >>/tmp/linuxconf-rpminstall.log
	$*
}

# Things to do after installing

# This script is handed a 1 if it is a new install
# and a 2 if it is an upgrade

# Touch the various log files, so we get no logrotate errors...
if [ ! -f /var/log/htmlaccess.log ] ; then
	log touch /var/log/htmlaccess.log
fi

if [ ! -f /var/log/boot.log ] ; then
	log touch /var/log/boot.log
fi

if [ ! -f /var/log/netconf.log ] ; then
	log touch /var/log/netconf.log
fi

# Fix Screwups from prior versions :-)
if [ -f /sbin/linuxconf ] ; then
	log rm -f /sbin/linuxconf
fi

if [ -f /bin/askrunlevel ] ; then
	log rm -f /bin/askrunlevel
fi

if [ -f /bin/dnsconf ] ; then
	log rm -f /bin/dnsconf
fi

if [ -f /bin/fixperm ] ; then
	log rm -f /bin/fixperm
fi

if [ -f /bin/mailconf ] ; then
	log rm -f /bin/mailconf
fi

# Is this the first install?
if [ ! -f /usr/lib/linuxconf/uninstall/options ] ; then
	touch /usr/lib/linuxconf/uninstall/options
	chmod 550 /usr/lib/linuxconf/uninstall/options
	echo FIRST INSTALL >> /usr/lib/linuxconf/uninstall/options
	echo Originally Installed `date` >> /usr/lib/linuxconf/uninstall/options
	echo Original : Linuxconf-1.9r26.2-1 >> /usr/lib/linuxconf/uninstall/options
	echo Any files listed here were not installed by the Linuxconf RPM >> /usr/lib/linuxconf/uninstall/options
else
	echo Upgraded to Linuxconf `date` >> /usr/lib/linuxconf/uninstall/options
fi

# Update /etc/inetd.conf
if [ `grep linuxconf /etc/inetd.conf | wc -l` = 0 ] ; then
	echo >> /etc/inetd.conf
	echo linuxconf stream tcp wait root /bin/linuxconf linuxconf --http >> /etc/inetd.conf
	if [ -f /var/run/inetd.pid ] ; then
		kill -HUP `cat /var/run/inetd.pid`
	fi
fi

# Update /etc/services
if [ `grep linuxconf /etc/services | wc -l` = 0 ] ; then
	
	echo "linuxconf	98/tcp		# added by linuxconf RPM" >> /etc/services
fi

# Put in the /etc/conf.linuxconf
if [ ! -f /etc/conf.linuxconf ] ; then
	if [ ! -f /etc/conf.linuxconf-installed ] ; then
		log cp /usr/lib/linuxconf/install/$SPCCONF /etc/conf.linuxconf
	else
		log mv /etc/conf.linuxconf-installed /etc/conf.linuxconf

		log /usr/lib/linuxconf/lib/checkdist.sh $CHECKDIST
	fi
fi

# Remove The FIRST INSTALL line from uninstall options
if [ ! `grep FIRST /usr/lib/linuxconf/uninstall/options | wc -l` = 0 ] ; then
	grep -v FIRST /usr/lib/linuxconf/uninstall/options > /usr/lib/linuxconf/uninstall/options.tmp
	mv -f /usr/lib/linuxconf/uninstall/options.tmp /usr/lib/linuxconf/uninstall/options
fi

