--- alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/08/17 03:35:10 281 +++ alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/08/17 21:19:52 282 @@ -11,7 +11,7 @@ #%before: #%after: -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.14 2005-07-10 17:55:03 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.15 2005-08-17 21:19:52 niro Exp $ # checks first if the client was already configured and if it has an valid serial # if not it runs the autoconfiguration script @@ -24,8 +24,10 @@ source /etc/sysconfig/rc source $rc_functions -#mysql settings +# mysql settings source /etc/alxconfig-ng/config.rc + +# helper functions source /usr/lib/alxconfig-ng/functions/mysqlfunctions source /usr/lib/alxconfig-ng/functions/serial_functions source /usr/lib/alxconfig-ng/functions/config_modules @@ -36,17 +38,18 @@ source /usr/lib/alxconfig-ng/functions/config_auth source /usr/lib/alxconfig-ng/functions/config_ssh_auth -#check if mysql is available +# check if mysql is available [ -x /usr/bin/mysql ] && MYSQL_ALX=true -#other needed vars +# other needed vars ALX_HW_DETECT=false +ALX_FORCED_RECHECK=false -#unset vars which may kill us +# unset vars which may kill us unset ALX_SERIAL ALX_STATE -#setup needed directories +# setup needed directories [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state @@ -80,13 +83,14 @@ local CUR_IP CUR_MAC CUR_MTIME - #check if serial file exists - if [ -f /etc/alxconfig-ng/serial ] + # check if serial file exists + if [ -f /etc/alxconfig-ng/serial ] && [ ! -f /hardware-auto-detection ] then source /etc/alxconfig-ng/serial - #start preliminary networking (dhcp) - preliminary_network start + # doing this now before this function gets called + # start preliminary networking (dhcp) + # preliminary_network start CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) @@ -94,7 +98,7 @@ echo -e ${COLOREDSTAR} "Trying to validate my serial ..." - #nice serial output + # nice serial output $CURS_UP $SET_WCOL echo "[ SN: ${ALX_SERIAL} ]" @@ -107,32 +111,69 @@ fi else - #run hardware detection + # run hardware detection echo - echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT} + if [ -f /hardware-auto-detection ] + then + echo -e ${COLMAGENTA}"Hardware-Auto-Detection forced by system-administrator"${COLDEFAULT} + else + echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT} + fi ALX_HW_DETECT=true /etc/init.d/hwdetect start - #set hostname to alx_default_hostname + # 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)" [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx HOSTNAME="${ALX_DEFAULT_HOSTNAME}" - #update the hostname on the system for sure + # update the hostname on the system for sure echo "${HOSTNAME}" > /etc/hostname - #start preliminary networking (dhcp) + # start preliminary networking (dhcp) preliminary_network start CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) CUR_MTIME=$(date +%s) + # abort now if this is a forced re-check + if [ -f /hardware-auto-detection ] + then + # but first check the serial + source /etc/alxconfig-ng/serial + + echo -e ${COLOREDSTAR} "Trying to validate my serial ..." + + # nice serial output + $CURS_UP + $SET_WCOL + echo "[ SN: ${ALX_SERIAL} ]" + + if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" + then + ALX_STATE="ok" + else + ALX_STATE="invalid serial" + fi + + # write current state to temp file + echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state + rm /hardware-auto-detection + + # now export ALX_FORCED_RECHECK=true + # that the setting will be updated not inserted ! + export ALX_FORCED_RECHECK=true + return 0 + fi + echo -e ${COLOREDSTAR} "Trying to get new serial ..." - #request new serial - #ALX_REG_DATE="$(date +%F)" + # request new serial + # ALX_REG_DATE="$(date +%F)" - #we're using the mtime now (better for vaildating the serial) + # we're using the mtime now (better for vaildating the serial) mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "insert into client_serials( mtime, @@ -143,24 +184,24 @@ '${CUR_MAC}' );" - #then validate and retrieve serial + # 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) + # 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}'") if [ "${ALX_SERIAL}" != NULL ] then - #nice serial output + # nice serial output $CURS_UP $SET_WCOL echo "[ SN: ${ALX_SERIAL} ]" - #set ALX_STATE to ok so everybody that everything was ok + # set ALX_STATE to ok so everybody that everything was ok ALX_STATE=ok echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial @@ -168,21 +209,21 @@ evaluate_retval else - #print false (works only if this is the first statement here) + # print false (works only if this is the first statement here) evaluate_retval - #set ALX_STATE to error so everybody sees there was an error + # set ALX_STATE to error so everybody sees there was an error ALX_STATE=error - #show an error that no new serial was found - #nice serial output + # show an error that no new serial was found + # nice serial output $CURS_UP $SET_WCOL echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]" fi fi - #write current state to temp file + # write current state to temp file echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state } @@ -199,26 +240,26 @@ # imports current settings to the database resolved by the hardware detection import_settings_to_db() { - #note: networking is always 'dhcp' if hw was autodetected - #note: default_domain/hostname is set in config.rc + # note: networking is always 'dhcp' if hw was autodetected + # note: default_domain/hostname is set in config.rc - #to be safe, we do some sanity checks + # to be safe, we do some sanity checks [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx - #vars used by hwdetect + # vars used by hwdetect local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER local MOUSETYPE XMOUSETYPE FULLNAME DEVICE - #get setting from hwdetect + # get setting from hwdetect source /etc/sysconfig/hwsetup/knoppix source /etc/sysconfig/hwsetup/mouse echo echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT} - #network + # network echo -e " Network settings ..." mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "insert into cfg_network( @@ -237,9 +278,9 @@ );" evaluate_retval - #xserver + # xserver echo -e " Graphic settings ..." - #xserver general + # xserver general ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "insert into cfg_graphic( serial, @@ -297,22 +338,77 @@ evaluate_retval } +# imports current settings to the database resolved by the hardware detection +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 ! + + # to be safe, we do some sanity checks + [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain + [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx + + # vars used by hwdetect + local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME + local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER + local MOUSETYPE XMOUSETYPE FULLNAME DEVICE + + # get setting from hwdetect + source /etc/sysconfig/hwsetup/knoppix + source /etc/sysconfig/hwsetup/mouse + + echo + echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT} + + # 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};" + evaluate_retval + + # xserver + echo -e " Graphic settings ..." + # xserver general + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "update cfg_graphic set + module='${XMODULE}', + resolution='1024x768', + depth='16', + monitorid='0' + where serial=${ALX_SERIAL};" + evaluate_retval + + # input + echo -e " Input settings ..." + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "update cfg_input set + mouse='${XMOUSETYPE}' + where serial=${ALX_SERIAL};" + evaluate_retval +} + # imports current settings to the local system resolved by the hardware detection # 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 + # note: networking is always 'dhcp' if hw was autodetected + # note: default_domain/hostname is set in config.rc - #to be safe, we do some sanity checks + # to be safe, we do some sanity checks [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx - #vars used by hwdetect + # vars used by hwdetect local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER local MOUSETYPE XMOUSETYPE FULLNAME DEVICE - #get setting from hwdetect + # get setting from hwdetect source /etc/sysconfig/hwsetup/knoppix echo @@ -322,7 +418,7 @@ echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules evaluate_retval - #set system state to 'already configured' + # set system state to 'already configured' touch /etc/alxconfig-ng/state/configured # create a fresh fluxbox directory @@ -349,27 +445,34 @@ # add a newline (maybe there is no crlf in the footer) echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu + # set correct permissions + chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME} + chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox + chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox + chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop + chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc + # default passwords are bad #usermod -p $(perl -e "printf(crypt('foobar','AD'))") root #usermod -p $(perl -e "printf(crypt('foobar','AD'))") ${ALX_UNPRIV_USER} #smbpasswd -a root foobar } -#start|stop +# start|stop preliminary_network(){ local module if [ -f /etc/alxconfig-ng/state/configured ] then - #get module name + # get module name module=$(cat ${SETTINGSPATH}/modules) modprobe ${module} else - #vars used by hwdetect + # vars used by hwdetect local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER - #get setting from hwdetect + # get setting from hwdetect source /etc/sysconfig/hwsetup/knoppix modprobe ${NETCARD_DRIVER} fi @@ -389,7 +492,8 @@ fi echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} - dhcpcd &> /dev/null + # -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 @@ -419,11 +523,27 @@ case $1 in start) - #retrieve or validate current serial + # start preliminary networking (dhcp) + preliminary_network start + + # check if mysql server is reachable + # if not abort this script + if ! reach_mysql_server + then + preliminary_network stop + exit 1 + fi + + # retrieve or validate current serial get_system_serial - if [ "${ALX_HW_DETECT}" == "true" ] + if [[ ${ALX_HW_DETECT} = true ]] then - import_settings_to_db + if [[ ${ALX_FORCED_RECHECK} = true ]] + then + update_settings_in_db + else + import_settings_to_db + fi import_settings_local # here we should also exchange the ssh keys @@ -432,16 +552,16 @@ config_ssh_auth fi - #now setup system configuration - #alx_setup_or_whatever_it_will_be_called() + # now setup system configuration + # alx_setup_or_whatever_it_will_be_called() [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings - #stop at last the preliminary networking (dhcp) + # stop at last the preliminary networking (dhcp) preliminary_network stop ;; - + stop) - #unset_alx_connected #--> now in alxsetstate-rc6 + # unset_alx_connected #--> now in alxsetstate-rc6 # ! important !: del systemstate [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state sleep 0.1