#!/bin/sh
# vim:set sw=4 ts=4:
#
# $Id: make_etc_hosts,v 1.11 2005/04/14 18:36:45 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_etc_hosts
# Configures the /etc/hosts file
#
# Sections: network (was etc.hosts)
# Tags:     SET_ETC_HOSTS, ETC_HOSTS
#
test -n "$alice_dir" || alice_dir="/usr/lib/alice2/"
export alice_dir
usage()
{
   cat <<EOF
usage: $0 -h | --help | -?
       $0 -fqhn hostname

EOF
}

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_etc_hosts=/etc/hosts
#
############################################################################
#
GET_CONFIGURATION --require network $CFG_DEBUG
if [ "$SET_ETC_HOSTS" = "yes" ]
then
     if [ -n "$ETC_HOSTS" ]
     then
        echo "$ETC_HOSTS" > ${std_etc_hosts}.alice
     else
#	cat << END_OF_HOSTS_FILE > ${std_etc_hosts}.alice
	cat > ${std_etc_hosts}.alice << END_OF_HOSTS_FILE 
#
# /etc/hosts
# generated by ALICE
#
# Syntax:
#
# IP-Address  Full-Qualified-Hostname  Short-Hostname
#

127.0.0.1       localhost

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet

ff00::0         ipv6-mcastprefix
ff02::1         ipv6-allnodes
ff02::2         ipv6-allrouters
ff02::3         ipv6-allhosts
${IPADDR_0}     ${FQHOSTNAME} ${FQHOSTNAME%%.*}
END_OF_HOSTS_FILE
   fi
   #
   # create a backup if the file has been changed
   #
   CHANGED ${std_etc_hosts} || {
	BACKUP --error ${std_etc_hosts} 
        mv ${std_etc_hosts}.alice ${std_etc_hosts}
   }
fi
#
############################################################################
# Thats all
GOOD_BYE 

