#!/bin/sh
#
# postinstall script for Java Desktop Server Environment
#

/usr/sbin/shareall -F nfs

# Add or modify DHCP services entry if needed

services=/etc/services
[ -f $services ] || {
        echo "$services does not exist"
        exit 1
}
 
trap "rm -f $services.$$" 0
 
nawk -f - $services > $services.$$ <<-FINIS
\$1 == "bootps"         { bootps="true" }
\$1 == "bootpc"         { bootpc="true" }
/BOOTP/			{ sub(/BOOTP/, "DHCP") }
                        { print }
END                     { if (! bootps)
                                print "bootps\t\t67/udp\t\t\t# DHCP Server"
                          if (! bootpc)
                                print "bootpc\t\t68/udp\t\t\t# DHCP Client"
                        }
FINIS
cp $services.$$ $services
rm -f $services.$$
 
trap 0

# Create links to /etc/init.d/dhcp if required (SUNWdhcsr will remove them when
# it gets removed)

for i in rc0.d/K34dhcp rc1.d/K34dhcp rc2.d/K34dhcp rc3.d/S34dhcp
do
        [ -f /etc/$i ] || {
                ln /etc/init.d/dhcp /etc/$i
	}
done

# Make sure DHCP directories present

PKG=/opt/SUNWjdse	# Is this a variable that can be set somewhere else?
LIB=$PKG/lib 
[ -f /etc/default/dhcp ] || {
	cp $LIB/etc.default.dhcp /etc/default/dhcp
	chmod 644 /etc/default/dhcp
	mkdir -p /var/dhcp
	chmod 755 /var/dhcp
}

# Make previously established configurations compatible with this one

/opt/SUNWjdse/bin/jdupdate

# Make sure the DHCP daemon is running and configured

ps -e | nawk '
/in.dhcpd/	{ running = 1; system("kill -HUP " $1) }
END		{ if (running)
			exit 0
		  else
			exit 1
		}
'
[ $? -eq 1 ] && /etc/init.d/dhcp start
exit 0
