--- alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/04/12 20:46:52 239 +++ 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.7 2005-04-12 20:45:55 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,123 +24,73 @@ 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 source /usr/lib/alxconfig-ng/functions/config_network source /usr/lib/alxconfig-ng/functions/config_printers source /usr/lib/alxconfig-ng/functions/config_sessions source /usr/lib/alxconfig-ng/functions/config_x11 +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 -validate_sessions(){ - - local x i all LOCAL_SESSIONS DB_SESSIONS SETTINGSPATH count - - #all arrays: - # -> session1 session2 ... sessionN - - - #no LOCAL_SESSIONS here, needs bubblesort - - #get settings from database - all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select session from cfg_sessions where serial='${ALX_SERIAL}'") - - #split'em up and put in an array (only if $all not zero) - declare -i i=0 - if [ -n "${all}" ] - then - for x in ${all} - do - DB_SESSIONS[${i}]=${x} - ((i++)) - done - count=${i} - else - count=0 - fi - - ## no compare here, can only done with bubblesort or s.th like that - # shows only the new sessions - declare -i i=0 - #count=${#DB_SESSIONS[*]} #---> not working gets always 1, why ? - - echo "Number of new sessions: ${count}" - for ((i=0; i < count; i++)) - do - echo "${i} - ${DB_SESSIONS[${i}]}" - done - - #update local configs - SETTINGSPATH=${SETTINGS_TEMPLATE}/menu - declare -i i=0 - - #count=${#DB_SESSIONS[*]} - - if [ ${count} -gt 0 ] - then - #create directory if not exist - [ ! -d ${SETTINGSPATH}/sessions ] && install -d ${SETTINGSPATH}/sessions - - #delete old sessions - echo -n > ${SETTINGSPATH}/sessions/sessions - - for ((i=0; i < count; i++)) - do - echo "${DB_SESSIONS[${i}]}" >> ${SETTINGSPATH}/sessions/sessions - done - - #set update flag - ALX_SESSION_SETUP=true - fi -} - - update_system_settings(){ echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} + # get the modules settings + # ! is the first thing that must be configured ! + config_modules + # imports network settings from db config_networking # imports x11 settings from db config_x11 - #echo - #echo "sessions" - #validate_sessions - #echo + # imports session settings from db config_sessions # imports printer settings from db config_printing + + # imports auth settings from db + config_auth + + # exchange ssh rsa keys + HOME=/root config_ssh_auth } get_system_serial(){ 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) @@ -148,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} ]" @@ -161,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, @@ -197,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 @@ -222,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 } @@ -253,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( @@ -291,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, @@ -308,30 +295,120 @@ '1024x768', '16', '0' - );"; + );"; ) + evaluate_retval # input - mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');";) + echo -e " Input settings ..." + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');" + evaluate_retval + + # auth + echo -e " Authentifcation settings ..." + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "insert into client_auth( + serial, + username, + shell, + vnc, + samba, + station + ) + values( + '${ALX_SERIAL}', + '${ALX_UNPRIV_USER}', + '', + '', + '', + '' + );" + evaluate_retval + + # exchange ssh rsa keys - the first boot needs this ! + # or no reboot will work via the webadmin + echo -e " SSH authentifcation settings ..." + HOME=/root config_ssh_auth + evaluate_retval + + # input + echo -e " Autostart settings ..." + mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ + "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');" + 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 @@ -341,25 +418,61 @@ 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 + [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox + install -d ${ALX_UNPRIV_HOME}/.fluxbox + + # now generate fluxbox config files + + # fluxbox main config + cat ${ALX_SKELETONS}/fluxbox/init \ + > ${ALX_UNPRIV_HOME}/.fluxbox/init + + # fluxbox menu header + cat ${ALX_SKELETONS}/fluxbox/menu.header \ + > ${ALX_UNPRIV_HOME}/.fluxbox/menu + + # add a newline (maybe there is no crlf in the header) + echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu + + # fluxbox menu footer + cat ${ALX_SKELETONS}/fluxbox/menu.footer \ + >> ${ALX_UNPRIV_HOME}/.fluxbox/menu + + # 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 @@ -379,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 @@ -409,24 +523,45 @@ 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 + # or the system cannot be rebooted after + # the first start via the alx-webadmin + 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 @@ -435,3 +570,4 @@ echo "Usage: $0 {start|stop} ..." ;; esac +