#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: make_inetd,v 1.16 2005/06/14 14:08:16 fabian Exp $
#
#############################################################################
#
# ALICE
# Automatic Linux Installation and Configuration Environment
#
# Copyright (c) 2000-2002 SuSE Linux Solutions AG, Eschborn, Germany
#               2002-2004 SuSE Linux AG, Eschborn, Germany
#               2005      SUSE GmbH, Nuernberg, Germany
#
# 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 of the License, 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; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#############################################################################
#
# Author: Fabian Herschel
#
############################################################################
#
# make_inetd
# Configures the xinetd or inetd
#
# Sections: inetd
# Tags:     XINETD_CONF , XINETD_SRV_INLINE, XINETD_SRV_EXTERNAL, XINETD_SRV_<service>
# Tags:     INETDLIST (if configure the inetd instead of xinetd)
#
############################################################################
#
# Notes:
#    - A service could not be named "INLINE" or "EXTERNAL"
#

test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir

while [ $# -gt 0 ]
do
   case $1 in
       -h | --help | -? ) usage
                          exit 1
                          ;;
       -fqhn ) export fqhn=$2; shift
            ;;

   esac
   shift
done   

. $alice_dir/lib/alicerc

WELCOME

std_inetd_conf=/etc/inetd.conf
std_xinetd_conf=/etc/xinetd.conf
std_xinetd_dir=/etc/xinetd.d
#
############################################################################
#
# Try to guess wether to configure inetd or xinetd :-)
#
if rpm -q xinetd
then
    #
    # xinetd is installed
    #
    #
    ############################################################################
    #
    # save the old configuration
    #
    test -f ${std_xinetd_conf} && BACKUP --error ${std_xinetd_conf} 
    test -d ${std_xinetd_dir} && BACKUP  --error ${std_xinetd_dir} 
    GET_CONFIGURATION --require inetd $CFG_DEBUG 
    #
    if [ -z "$XINETD_CONF" ]
    then
	MESSAGE NOVALUE XINETD_CONF " "
        GOOD_BYE
    fi
    (
	echo "$XINETD_CONF"
    ) > ${std_xinetd_conf}
    #
    # now add xinetd services INLINE
    #
    for XinetdService in $XINETD_SRV_INLINE
    do
	(
	    echo
	    eval echo \"\$XINETD_SRV_$XinetdService\" 
	    echo
	) >> ${std_xinetd_conf}
    done
    #
    # now add xinetd services EXTERNAL
    #
    rm -rf ${std_xinetd_dir}
    mkdir -p ${std_xinetd_dir}
    for XinetdService in $XINETD_SRV_EXTERNAL
    do
	eval echo \"\$XINETD_SRV_$XinetdService\" > ${std_xinetd_dir}/$XinetdService
    done
    rcxinetd restart
    #
elif rpm -q inetd
then
    #
    # inetd is installed
    #
    ############################################################################
    #
    # save the old configuration
    #
    test -f ${std_inetd_conf} && BACKUP --error ${std_inetd_conf} 
    #
    # First priority is on a special inetd.con file
    #
    #config_file=$(get_config_file inetd.conf) || FATAL NOCFG inetd.conf
    #. ${config_file}
    GET_CONFIGURATION --require inetd $CFG_DEBUG 
    if [ -z "$INETDLIST" ]
    then
	MESSAGE NOVALUE INETDLIST " "
	GOOD_BYE
    fi
    (
	echo "# ${std_inetd_conf}"
	echo "# generated by alice"   
	echo "${INETDLIST}" 
    )> ${std_inetd_conf}.alice
    CHANGED ${std_inetd_conf} || {
	BACKUP ${std_inetd_conf}
	mv ${std_inetd_conf}.alice ${std_inetd_conf} 
       #
       # Now we invite inetd to reload the information
       #
       if [ -x $rc_d_dir/inetd ]
       then
	  if [ "$($rc_d_dir/inetd status)" = "INET up" ]
	  then
	     $rc_d_dir/inetd reload
	  fi
       else
	  MESSAGE NOEXE $rc_d_dir/inetd    
       fi
    }
    # end configure inetd
else
    MESSAGE FREETXT "Neither inetd nor xinetd rpm are installed"
fi
############################################################################
# Thats all
GOOD_BYE 
