--- alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/09/01 18:30:28 319 +++ alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/09/22 22:14:38 337 @@ -11,7 +11,7 @@ #%before: #%after: -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.21 2005-09-01 18:30:28 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.22 2005-09-22 22:14:38 niro Exp $ # checks first if the client was already configured and if it has an valid serial # if not it runs the autoconfiguration script @@ -44,6 +44,8 @@ # other needed vars ALX_HW_DETECT=false ALX_FORCED_RECHECK=false +ALX_RESET_SETTINGS=false +ALX_CONFD_NETWORKING=false # unset vars which may kill us unset ALX_SERIAL ALX_STATE @@ -53,7 +55,21 @@ [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state -update_system_settings(){ +# read_cmdline ${item} +read_cmdline() +{ + local i + + for i in $(< /proc/cmdline) + do + [[ ${i} = $1 ]] && return 0 + done + + return 1 +} + +update_system_settings() +{ echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} # get the modules settings @@ -79,12 +95,13 @@ HOME=/root config_ssh_auth } -get_system_serial(){ +get_system_serial() +{ local CUR_IP CUR_MAC CUR_MTIME # check if serial file exists - if [ -f /etc/alxconfig-ng/serial ] && [ ! -f /hardware-auto-detection ] + if [ -f /etc/alxconfig-ng/serial ] && [[ ${ALX_FORCED_RECHECK} = false ]] then source /etc/alxconfig-ng/serial @@ -124,7 +141,7 @@ else # run hardware detection echo - if [ -f /hardware-auto-detection ] + if [[ ${ALX_FORCED_RECHECK} = true ]] then echo -e ${COLMAGENTA}"Hardware autodetection forced by system-administrator"${COLDEFAULT} else @@ -135,7 +152,7 @@ # set hostname to alx_default_hostname # use old hostname if this is a forced re-check - [ -f /hardware-auto-detection ] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)" + [[ ${ALX_FORCED_RECHECK} = true ]] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)" [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx HOSTNAME="${ALX_DEFAULT_HOSTNAME}" @@ -158,7 +175,7 @@ CUR_MTIME=$(date +%s) # abort now if this is a forced re-check - if [ -f /hardware-auto-detection ] + if [[ ${ALX_FORCED_RECHECK} = true ]] then # but first check the serial source /etc/alxconfig-ng/serial @@ -183,7 +200,7 @@ # write current state to temp file echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state - rm /hardware-auto-detection + [ -f /hardware-auto-detection ] && rm /hardware-auto-detection # now export ALX_FORCED_RECHECK=true # that the setting will be updated not inserted ! @@ -193,36 +210,12 @@ echo -e ${COLOREDSTAR} "Trying to get new serial ..." - # request new serial - # ALX_REG_DATE="$(date +%F)" - - # we're using the mtime now (better for validating the serial) -# mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "insert into client_serials( -# mtime, -# mac -# ) -# values( -# '${CUR_MTIME}', -# '${CUR_MAC}' -# );" -# -# # then validate and retrieve serial -# -# ### warning must be changed that only the LAST ID will be fetched, ### -# ### or you get error if the computer name and date are the same ### -# ### you have more than one serial number then ### -# -# # select highest id only (added max) -# ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'") - # request a new serial; one command now (cause must be done in the same session) ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}'); select last_insert_id();") - if [ "${ALX_SERIAL}" != NULL ] + if [[ ${ALX_SERIAL} != NULL ]] then # nice serial output $CURS_UP @@ -256,7 +249,8 @@ } -check_is_configured() { +check_is_configured() +{ if [ -f /etc/alxconfig-ng/state/configured ] then export ALX_CONFIGURED=true @@ -267,7 +261,8 @@ # imports current settings to the database resolved by the hardware detection -import_settings_to_db() { +import_settings_to_db() +{ # note: networking is always 'dhcp' if hw was autodetected # note: default_domain/hostname is set in config.rc @@ -289,21 +284,85 @@ # network echo -e " Network settings ..." - mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "insert into cfg_network( - hostname, - serial, - module, - domain, - networking - ) - values( - '${ALX_DEFAULT_HOSTNAME}', - '${ALX_SERIAL}', - '${NETCARD_DRIVER}', - '${ALX_DEFAULT_DOMAIN}', - 'dhcp' - );" + if [[ ${ALX_CONFD_NETWORKING} = true ]] + then + # get settings + #source ${rc_base}/init.d/network &> /dev/null + for iface in $(onboot_interface_list ${network_settings}/net.*) + do + [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue + echo "WARNING: only importing settings for interface [ ${iface} ] !" + source ${network_settings}/net.${iface} || exit 1 + NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)" + + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "insert into cfg_network( + hostname, + serial, + module, + domain, + networking, + netmask, + dns, + gateway, + broadcast, + ip, + forcemacto, + wireless_bitrate, + wireless_channel, + wireless_essid, + wireless_frequency, + wireless_mode, + wireless_nick, + wireless_auth_mode, + wireless_key_length, + wireless_key, + wireless_key_ascii + ) + values( + '${ALX_DEFAULT_HOSTNAME}', + '${ALX_SERIAL}', + '${NETCARD_DRIVER}', + '${ALX_DEFAULT_DOMAIN}', + '${NETWORKING}', + '${NETMASK}', + '${NAMESERVER}', + '${GATEWAY}', + '${BROADCAST}', + '${IP}', + '${FORCE_MAC_TO}', + '${WIRELESS_BITRATE}', + '${WIRELESS_CHANNEL}', + '${WIRELESS_ESSID}', + '${WIRELESS_FREQUENCY}', + '${WIRELESS_MODE}', + '${WIRELESS_NICK}', + '${WIRELESS_AUTH_MODE}', + '${WIRELESS_KEY_LENGTH}', + '${WIRELESS_KEY}', + '${WIRELESS_KEY_ASCII}' + );" + + # only insert the *FIRST* iface + break + done + else + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "insert into cfg_network( + hostname, + serial, + module, + domain, + networking + ) + values( + '${ALX_DEFAULT_HOSTNAME}', + '${ALX_SERIAL}', + '${NETCARD_DRIVER}', + '${ALX_DEFAULT_DOMAIN}', + 'dhcp' + );" + fi evaluate_retval # xserver @@ -367,7 +426,8 @@ } # imports current settings to the database resolved by the hardware detection -update_settings_in_db() { +update_settings_in_db() +{ # note: networking is always 'dhcp' if hw was autodetected # note: default_domain/hostname is set in config.rc or exported # note: we updating only hardware settings here ! @@ -390,14 +450,53 @@ # network echo -e " Network settings ..." - - mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "update cfg_network set - hostname='${ALX_DEFAULT_HOSTNAME}', - module='${NETCARD_DRIVER}', - domain='${ALX_DEFAULT_DOMAIN}', - networking='dhcp' - where serial=${ALX_SERIAL};" + if [[ ${ALX_CONFD_NETWORKING} = true ]] + then + # get settings + #source ${rc_base}/init.d/network &> /dev/null + for iface in $(onboot_interface_list ${network_settings}/net.*) + do + [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue + echo "WARNING: only importing settings for interface [ ${iface} ] !" + source ${network_settings}/net.${iface} || exit 1 + NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)" + + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "update cfg_network set + hostname='${ALX_DEFAULT_HOSTNAME}', + module='${NETCARD_DRIVER}', + domain='${ALX_DEFAULT_DOMAIN}', + networking='${NETWORKING}', + netmask='${NETMASK}', + dns='${NAMESERVER}', + gateway='${GATEWAY}', + broadcast='${BROADCAST}', + ip='${IP}', + forcemacto='${FORCE_MAC_TO}', + wireless_bitrate='${WIRELESS_BITRATE}', + wireless_channel='${WIRELESS_CHANNEL}', + wireless_essid='${WIRELESS_ESSID}', + wireless_frequency='${WIRELESS_FREQUENCY}', + wireless_mode='${WIRELESS_MODE}', + wireless_nick='${WIRELESS_NICK}', + wireless_auth_mode='${WIRELESS_AUTH_MODE}', + wireless_key_length='${WIRELESS_KEY_LENGTH}', + wireless_key='${WIRELESS_KEY}', + wireless_key_ascii='${WIRELESS_KEY_ASCII}' + where serial=${ALX_SERIAL};" + + # only insert the *FIRST* iface + break + done + else + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "update cfg_network set + hostname='${ALX_DEFAULT_HOSTNAME}', + module='${NETCARD_DRIVER}', + domain='${ALX_DEFAULT_DOMAIN}', + networking='dhcp' + where serial=${ALX_SERIAL};" + fi evaluate_retval # xserver @@ -422,8 +521,9 @@ } # imports current settings to the local system resolved by the hardware detection -# we only need the network settings -import_settings_local(){ +# we only need the network settings +import_settings_local() +{ # note: networking is always 'dhcp' if hw was autodetected # note: default_domain/hostname is set in config.rc @@ -442,9 +542,19 @@ echo echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT} - [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} - echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules - evaluate_retval + if [[ ${ALX_CONFD_NETWORKING} = false ]] + then + #[ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} + #echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules + + # set an device alias for modprobe.conf + [ ! -d /etc/modules.d ] && install -d /etc/modules.d + echo "alias eth0 ${NETCARD_DRIVER}" > /etc/modules.d/net.eth0 + + # regenerate modprobe.conf + [ -x $(which modules-update) ] && modules-update || echo "cannot regen modprobe.conf" + evaluate_retval + fi # set system state to 'already configured' touch /etc/alxconfig-ng/state/configured @@ -534,14 +644,19 @@ } # start|stop -preliminary_network(){ +preliminary_network() +{ local module if [ -f /etc/alxconfig-ng/state/configured ] then - # get module name - module=$(cat ${SETTINGSPATH}/modules) - modprobe ${module} + # compat for old clients + if [ -f ${SETTINGSPATH}/modules ] + then + # get module name + module=$(cat ${SETTINGSPATH}/modules) + modprobe ${module} + fi else # vars used by hwdetect local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME @@ -565,24 +680,32 @@ else rm -f /var/run/dhcpcd-eth?.pid fi + [[ ${ALX_CONFD_NETWORKING} = true ]] && ${rc_base}/init.d/network stop - echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} - # -t 10 timeout of 10 secs - dhcpcd -t 10 &> /dev/null - - # aka_fix ######################################## - #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up - #route del default gw 128.20.50.13 &> /dev/null - #route add default gw 128.20.50.21 &> /dev/null - #echo "nameserver 128.20.50.21" > /etc/resolv.conf - ################################################## - evaluate_retval + echo -e ${COLMAGENTA}"Starting preliminary networking ... "${COLDEFAULT} + + # start network configured from /etc/conf.d + if [[ ${ALX_CONFD_NETWORKING} = true ]] + then + ${rc_base}/init.d/network start + else + echo -e ${COLOREDSTAR}"Starting default dhcp based networking ... "${COLDEFAULT} + # -t 10 timeout of 10 secs + dhcpcd -t 10 &> /dev/null + evaluate_retval + fi ;; stop) - echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT} - ifconfig eth0 down + echo -e ${COLMAGENTA}"Stopping preliminary networking ... "${COLDEFAULT} + if [[ ${ALX_CONFD_NETWORKING} = true ]] + then + ${rc_base}/init.d/network stop + else + echo -e ${COLOREDSTAR}"Stopping default dhcp based networking ... "${COLDEFAULT} + ifconfig eth0 down + fi if ps -A|grep dhcpcd > /dev/null then dhcpcd -z &> /dev/null @@ -596,8 +719,129 @@ esac } +reset_system_settings() +{ + # force load of de kbdkeys + loadkeys -q de + echo + echo -en ${COLRED} + echo -n "*** Warning: you are about to reset *all* local settings on this system!" + echo -e ${COLDEFAULT} + echo "*** Do you really want to continue ?" + echo -n "*** Enter 'yes' to continue, anything else to abort: " + read kbinsert + if [[ ${kbinsert} = yes ]] + then + echo -en ${COLRED} + echo -n "*** OK, you really want it ... killing all settings: " + for i in 3 2 1 now + do + echo -n " ${i}" + sleep 1 + done + echo -e ${COLDEFAULT} + + ## reset all settings: + rm -rf ${SETTINGSPATH}/* + rm -f /etc/alxconfig-ng/serial + rm -rf /etc/alxconfig-ng/state + + echo "I am done now, press [Enter] to reboot system ..." + read + reboot + fi +} + +onboot_interface_list() +{ + local file + local devices + local iface + + # get list of all devices + for file in $@ + do + if [[ $(read_value ONBOOT ${file}) = yes ]] + then + iface="$(basename ${file} | sed s/net.//)" + # exclude backup files + case "${iface}" in + *~) ;; + *) devices="${devices} $(basename ${file} | sed s/net.//)" ;; + esac + fi + done + + echo "${devices}" +} + +# read values from files +read_value() +{ + local var="$1" + local file="$2" + local value + + # local all possible vars + # global + local ONBOOT + local NETWORKING + + # static + local IP + local NETMASK + local BROADCAST + local NETWORKING + local FORCE_MAC_TO + + # dhcp + local DHCP_PROG + local DHCP_START + local DHCP_STOP + + # default gw + local GATEWAY + local GATEWAY_IF + + # wireless extensions + local WIRELESS_AP + local WIRELESS_AUTH_MODE + local WIRELESS_BITRATE + local WIRELESS_CHANNEL + local WIRELESS_DEFAULT_KEY + local WIRELESS_ESSID + local WIRELESS_FREQUENCY + local WIRELESS_KEY + local WIRELESS_KEY_ASCII + local WIRELESS_KEY_0 + local WIRELESS_KEY_1 + local WIRELESS_KEY_2 + local WIRELESS_KEY_3 + local WIRELESS_KEY_LENGTH + local WIRELESS_MODE + local WIRELESS_NICK + local WIRELESS_NWID + local WIRELESS_POWER + + source ${file} + eval value=\$$(echo ${var}) + echo "${value}" +} + case $1 in start) + # check for global overrides + [ -f ${SETTINGSPATH}/confd-networking ] && ALX_CONFD_NETWORKING=true + [ -f /hardware-auto-detection ] && ALX_FORCED_RECHECK=true + read_cmdline hardware-auto-detection && ALX_FORCED_RECHECK=true + read_cmdline alx-reset-settings && ALX_RESET_SETTINGS=true + + # kill all settings if requested + if [[ ${ALX_RESET_SETTINGS} = true ]] + then + reset_system_settings + fi + # retrieve or validate current serial get_system_serial if [[ ${ALX_HW_DETECT} = true ]]