--- alx-src/trunk/tinyalxconfig-ng/functions/config_network.sh 2008/06/04 18:07:24 392 +++ alx-src/trunk/tinyalxconfig-ng/functions/config_network.sh 2008/06/05 19:08:36 454 @@ -1,67 +1,98 @@ -# $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_network.sh,v 1.2 2008-06-04 18:07:24 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/tinyalxconfig-ng/functions/config_network.sh,v 1.8 2008-06-05 19:08:36 niro Exp $ # configures networkin on the host via mysql db settings -get_network_settings() +get_network_settings_old() { - local x i all DB_NETWORK + local all_ifaces + local iface + local x + + # get a list of all interfaces + all_ifaces=$(mysqldo "select iface from cfg_interface where serial='${ALX_SERIAL}'") - # all arrays: - # -> hostname modules domain networking ip netmask dns gateway broadcast + # retrieve hostname and domain information + evaluate_table cfg_network + export ALX_HOSTNAME="${cfg_network_hostname}" + export ALX_DOMAIN="${cfg_network_domain}" - all=$(mysqldo "select iface, - hostname, - module, - domain, - networking, - ip, - netmask, - dns, - gateway, - broadcast - from cfg_network where serial='${ALX_SERIAL}'") - - # split'em up and put 'em in an array - declare -i i=0 - for x in ${all} + # now build a multi-ranged "array" for all interface settings + declare -i x=0 + + for iface in ${all_ifaces} do - DB_NETWORK[${i}]="${x}" - ((i++)) - done + evaluate_table + all=$(mysqldo "select iface, + hostname, + module, + domain, + networking, + ip, + netmask, + dns, + gateway, + broadcast + from cfg_network where serial='${ALX_SERIAL}'") + + # split'em up and put 'em in an array + declare -i i=0 + for x in ${all} + do + DB_NETWORK[${i}]="${x}" + ((i++)) + done + + # and now put in usable var names and export them systemwide + export ALX_IFACE="${DB_NETWORK[0]:=NULL}" + export ALX_HOSTNAME="${DB_NETWORK[1]:=NULL}" + export ALX_MODULE="${DB_NETWORK[2]:=NULL}" + export ALX_DOMAIN="${DB_NETWORK[3]:=NULL}" + export ALX_NETWORKING="${DB_NETWORK[4]:=NULL}" + export ALX_IP="${DB_NETWORK[5]:=NULL}" + export ALX_NETMASK="${DB_NETWORK[6]:=NULL}" + export ALX_DNS="${DB_NETWORK[7]:=NULL}" + export ALX_GATEWAY="${DB_NETWORK[8]:=NULL}" + export ALX_BROADCAST="${DB_NETWORK[9]:=NULL}" + + # the new mac address hack + export ALX_FORCEMACTO=$(mysqldo "select forcemacto from cfg_network where serial='${ALX_SERIAL}'") + + # wireless extensions + export ALX_WIRELESS_BITRATE=$(mysqldo "select wireless_bitrate from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_CHANNEL=$(mysqldo "select wireless_channel from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_ESSID=$(mysqldo "select wireless_essid from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_FREQUENCY=$(mysqldo "select wireless_frequency from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_MODE=$(mysqldo "select wireless_mode from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_NICK=$(mysqldo "select wireless_nick from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_AUTH_MODE=$(mysqldo "select wireless_auth_mode from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_KEY_LENGTH=$(mysqldo "select wireless_key_length from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_KEY=$(mysqldo "select wireless_key from cfg_network where serial='${ALX_SERIAL}'") + export ALX_WIRELESS_KEY_ASCII=$(mysqldo "select wireless_key_ascii from cfg_network where serial='${ALX_SERIAL}'") - # and now put in usable var names and export them systemwide - export ALX_IFACE="${DB_NETWORK[0]:=NULL}" - export ALX_HOSTNAME="${DB_NETWORK[1]:=NULL}" - export ALX_MODULE="${DB_NETWORK[2]:=NULL}" - export ALX_DOMAIN="${DB_NETWORK[3]:=NULL}" - export ALX_NETWORKING="${DB_NETWORK[4]:=NULL}" - export ALX_IP="${DB_NETWORK[5]:=NULL}" - export ALX_NETMASK="${DB_NETWORK[6]:=NULL}" - export ALX_DNS="${DB_NETWORK[7]:=NULL}" - export ALX_GATEWAY="${DB_NETWORK[8]:=NULL}" - export ALX_BROADCAST="${DB_NETWORK[9]:=NULL}" + done +} - # the new mac address hack - export ALX_FORCEMACTO=$(mysqldo "select forcemacto from cfg_network where serial='${ALX_SERIAL}'") +check_network_settings_old() +{ + # sanity checks + [[ ${ALX_IFACE} = NULL ]] && return 1 + [[ ${ALX_HOSTNAME} = NULL ]] && return 1 + [[ ${ALX_NETWORKING} = NULL ]] && return 1 - # wireless extensions - export ALX_WIRELESS_BITRATE=$(mysqldo "select wireless_bitrate from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_CHANNEL=$(mysqldo "select wireless_channel from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_ESSID=$(mysqldo "select wireless_essid from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_FREQUENCY=$(mysqldo "select wireless_frequency from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_MODE=$(mysqldo "select wireless_mode from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_NICK=$(mysqldo "select wireless_nick from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_AUTH_MODE=$(mysqldo "select wireless_auth_mode from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_KEY_LENGTH=$(mysqldo "select wireless_key_length from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_KEY=$(mysqldo "select wireless_key from cfg_network where serial='${ALX_SERIAL}'") - export ALX_WIRELESS_KEY_ASCII=$(mysqldo "select wireless_key_ascii from cfg_network where serial='${ALX_SERIAL}'") + # if we get here, everything is ok + return 0 } -config_networking() +config_networking_old() { local iface # first of all get the vars get_network_settings + if ! check_network_settings + then + echo -e "${COLYELLOW}Could not retrieve network settings, doing nothing ...${COLDEFAULT}" + return 1 + fi # get the right nic if [[ -z ${ALX_IFACE} ]] || [[ ${ALX_IFACE} = NULL ]] @@ -74,17 +105,6 @@ # remove all old nics and modules configs find /etc/conf.d -type f -name 'net.*' | xargs rm - find /etc/modules.d -type f -name 'net.*' | xargs rm - - # update the preliminary network - # set an device alias for modprobe.conf - [ ! -d /etc/modules.d ] && install -d /etc/modules.d - # update only if not the same (to speed up bootprocess - no depmod) - if [ ! -f /etc/modules.d/net.${iface} ] || - [[ ${iface} != $(cat /etc/modules.d/net.${iface} | cut -d' ' -f2) ]] - then - echo "alias ${iface} ${ALX_MODULE}" > /etc/modules.d/net.${iface} - fi # update confd-networking default iface [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} @@ -135,14 +155,6 @@ echo "nameserver ${ALX_DNS}" > /etc/resolv.conf fi - # setup smb.conf (little sed magic:) - # first get smb version ! - local smbconf - [[ $(smbd --version | cut -d' ' -f2) > 2.999 ]] && smbconf=smb3.conf || smbconf=smb.conf - - cat ${ALX_SKELETONS}/samba/${smbconf} > /etc/samba/smb.conf - sed -i -e "s:\(workgroup = \).*:\1${ALX_DOMAIN}:" /etc/samba/smb.conf - # wireless extensions local value local var @@ -199,3 +211,121 @@ unset ALX_WIRELESS_KEY_ASCII } +# needs exported iface variable! +add_iface_cfg() +{ + echo "$@" >> /etc/conf.d/net.${iface} +} + +config_networking() +{ + local iface + + # retrieve informations about hostname and co + evaluate_table cfg_network + + # configure hostname and domain settings: + echo "${cfg_network_hostanme}" > /etc/hostname + echo -e "127.0.0.1\tlocalhost.${cfg_network_domain}\tlocalhost\t${cfg_network_hostname}" > /etc/hosts + +# if ! check_network_settings +# then +# echo -e "${COLYELLOW}Could not retrieve network settings, doing nothing ...${COLDEFAULT}" +# return 1 +# fi + + # remove all old nics and modules configs + find /etc/conf.d -type f -name 'net.*' | xargs rm + +# # update confd-networking default iface +# [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} +# echo "${iface}" > ${SETTINGSPATH}/confd-networking + + # configure all available interfaces but activate only the default_iface! + iface_list=$(mysqldo "select iface from cfg_interfaces where serial='${ALX_SERIAL}'") + + for iface in ${iface_list} + do + # initialize the config + :> /etc/conf.d/net.${iface} + + # retrieve information from mysql + evaluate_table cfg_interfaces "where serial='${ALX_SERIAL}' and iface='${iface}'" + + if [[ ${iface} = ${cfg_network_default_iface} ]] + then + add_iface_cfg "ONBOOT=yes" + else + add_iface_cfg "ONBOOT=no" + fi + + add_iface_cfg NETWORKING=${cfg_interfaces_networking} + + case ${cfg_interfaces_networking} in + dhcp|DHCP) + add_iface_cfg "DHCP_PROG=/sbin/udhcpc" + # timeout after 10 seconds and quit after retrieving a lease + add_iface_cfg 'DHCP_START="-t 10 -q"' + ;; + + static|STATIC) + # add hostname with valid ip to hosts + echo -e "${cfg_interfaces_ip}\t${cfg_interfaces_hostname}.${cfg_interfaces_domain}\t${cfg_interfaces_hostname}" >> /etc/hosts + add_iface_cfg "IP=${cfg_interfaces_ip}" + add_iface_cfg "NETMASK=${cfg_interfaces_netmask}" + add_iface_cfg "BROADCAST=${cfg_interfaces_broadcast}" + ;; + esac + + # gateway or gateway overrides + if [[ ${cfg_interfaces_gateway} != NULL ]] + then + add_iface_cfg "GATEWAY=${cfg_interfaces_gateway}" + fi + + # nameserver or nameserver overrides + if [[ ${cfg_interfaces_dns} != NULL ]] + then + add_iface_cfg "NAMESERVER="${cfg_interfaces_dns}"" + fi + + # force mac address override + if [[ ${cfg_interfaces_forcemacto} != NULL ]] + then + add_iface_cfg FORCE_MAC_TO=${cfg_interfaces_forcemacto} + fi + + # wireless extensions + local value + local var + for var in cfg_interfaces_wireless_bitrate \ + cfg_interfaces_wireless_channel \ + cfg_interfaces_wireless_essid \ + cfg_interfaces_wireless_frequency \ + cfg_interfaces_wireless_mode \ + cfg_interfaces_wireless_nick \ + cfg_interfaces_wireless_auth_mode \ + cfg_interfaces_wireless_key_length \ + cfg_interfaces_wireless_key \ + cfg_interfaces_wireless_key_ascii + do + # get the value of $var + eval value=\$$(echo ${var}) + + # write it only if not empty + if [[ -n ${value} ]] && [[ ${value} != NULL ]] + then + # remove cfg_interfaces_from var and convert to upcase + add_iface_cfg "$(echo ${var/cfg_network_/} | tr '[:lower:]' '[:upper:]')=${value}" + fi + + # clear value + unset value + done + + # setup wpa-driver (only zydas atm) + case ${cfg_interfaces_module} in + zd1211) add_iface_cfg "WIRELESS_WPA_DRIVER=zydas" ;; + esac + done +}