#!/bin/sh
#
# Postinstall script written by Ron Record (rr@sco.com) for use with my
# UnixWare/OpenUNIX packaging of Squid.
# 

PATH=/usr/gnu/bin:$PATH
export PATH

ME="`basename $0`"
ISL_FILE="/etc/inst/scripts/postreboot.sh"
SUCCESS=0; FAIL=1; INTR=3
trap "exit $INTR" 2 3 15
[ -f $ISL_FILE ] && exec 1>>/var/adm/log/$PKGINST.out
[ -f $ISL_FILE ] && exec 2>>/var/adm/log/$PKGINST.err

# location of the packaging information files during this phase of installation
INSTALL_DIR="/var/sadm/pkg/$PKGINST/install/$PKGINST"

#############################################################################
#
# host_set
#         fixup the HOST name and IP in any configuration files
#
#############################################################################
host_set()
{
  if [ -f /etc/inst/scripts/postreboot.sh ]
  then
    HOST=`grep TCP_DOMAIN_NAME /isl/ifile`
    HOSTNAME=`uname -n`.`echo $HOST | sed -e "s/^.*=\"\(.*\)\"$/\1/p"`
  else
    HOSTPROG=/usr/ucb/hostname
    if [ -x $HOSTPROG ] 
    then
      HOSTNAME=`$HOSTPROG`
    else
      HOSTNAME=localhost
    fi
  fi
  [ "$HOSTNAME" ] || HOSTNAME=localhost
  HOST_FILES="/usr/lib/squid/etc/squid.conf"

  for i in $HOST_FILES
  do
  [ -f $i ] && {
    sed -e "s/rincon.pdev.ca.caldera.com/$HOSTNAME/g" < $i > /tmp/_ccs$$
    mv /tmp/_ccs$$ $i
    rm -f /tmp/_ccs$$ /tmp/_ccs_ip$$
    chown root:sys $i
  }
  done
}

#############################################################################
#
# main
#
#############################################################################

# edit configuration files
host_set

# Initialize the cache
echo "
Initializing the Squid cache - please be patient"
/usr/lib/squid/bin/squid -z > /dev/null 2>&1
/etc/init.d/squid stop

# Configure DocView for use with Squid's documentation
#
LOGFILE=/var/sadm/install/logs/SquidDoc.log
doctool --add HelpTopics/INThome/INTgroup/SquidDoc.desktop >> $LOGFILE 2>&1

# Enable the preconfigured services, as a default.
# This creates the symbolic links in /etc/rc?.d to start
# the daemons when the system goes multi-user.
# 
#[ -x /etc/init.d/squid ] && /etc/init.d/squid enable > /dev/null 2>&1

echo "
Squid is pre-configured to act as a cacheing proxy server. 
As such, it runs on port 3128. These parameters can be configured by editing
/usr/lib/squid/etc/squid.conf.

To run Squid automatically at boot time, issue the command (as root):
	# /etc/init.d/squid enable
To start Squid manually, issue the command (as root):
	# /etc/init.d/squid start
To stop Squid manually, issue the command (as root):
	# /etc/init.d/squid stop
"

# done
exit $SUCCESS
