#----------------------------------------------------------------------------
# /etc/rc.d/rc001.base
# was file /etc/config.sh
#
# Creation:         13.04.2000  fm
# Last Update:  $Id: rc001.base 10354 2005-11-18 12:41:51Z jw5 $
#
# Copyright (c) 2000-2001 Frank Meyer
#----------------------------------------------------------------------------

begin_script RC001_BASE "creating /etc/resolv.conf and /etc/hosts ..."

write_resolv_conf ()
{
    echo "writing /etc/resolv.conf ..."

    if [ "$OPT_DNS" = "no" ]
    then
        ipaddr="$DNS_FORWARDERS"
    else
        ipaddr=127.0.0.1
    fi

    {
        cat <<EOF 
#----------------------------------------------------------------------------
# /etc/resolv.conf
# automatically created by rc001.base
#----------------------------------------------------------------------------
search $DOMAIN_NAME
EOF
        for j in $ipaddr
        do
            echo "nameserver $j"
        done
    } >/etc/resolv.conf
}

write_etc_hosts ()
{
    echo "writing /etc/hosts ..."

    {
        cat <<EOF
#----------------------------------------------------------------------------
# /etc/hosts
# automatically created by rc001.base
#----------------------------------------------------------------------------
127.0.0.1 localhost
EOF

        [ 0$HOSTS_N -eq 0 ] || for i in `seq 1 $HOSTS_N`
        do
            eval hostname='$HOST_'$i'_NAME'
            if [ "$hostname" = "HOSTNAME" ]
            then
                hostname=$HOSTNAME
            fi

            eval alias_n='$HOST_'$i'_ALIAS_N'
            aliases=''
            [ 0"$alias_n" -eq 0 ] || for j in `seq 1 $alias_n`
            do
		eval alias='$HOST_'$i'_ALIAS_'$j
		aliases="$aliases $alias"
            done

            eval translate_ip_net '$HOST_'$i'_IP'
            if ! is_error
            then
                echo "$res $hostname $hostname.$DOMAIN_NAME $aliases"
		eval HOST_${i}_IP="$res"
            fi
        done
	
        echo "# hostnames for every interface"
        [ 0$IP_NET_N -eq 0 ] || for i in `seq 1 $IP_NET_N`
        do
            eval dev='$IP_NET_'$i'_DEV'
	    dev=`echo $dev | sed -e 's/\./-vlan-/;s/:/-alias-/'`
            eval net='$IP_NET_'$i''
            ipaddr=`echo $net | sed 's/\/.*//'`
            echo "$ipaddr $HOSTNAME-$dev $HOSTNAME-$dev.$DOMAIN_NAME"
        done
	
    } >/etc/hosts 
}

if [ ! -f /etc/resolv.conf ]        # already existing?
then                                # yes, don't overwrite
    write_resolv_conf
fi

if [ ! -f /etc/hosts ]              # already existing?
then                                # yes, don't overwrite
    write_etc_hosts
fi

ip_up_events=yes

end_script
