--- alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/03/09 00:17:49 230 +++ alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/08/31 21:31:09 313 @@ -11,7 +11,7 @@ #%before: #%after: -# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.5 2005-03-09 00:17:49 niro Exp $ +# $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.19 2005-08-31 21:31:09 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,133 +24,88 @@ 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 - # if system is already configured, it *has* a hostname. - # so we take the hostname of this system here - source /etc/hostname - - #start preliminary networking (dhcp) + # 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 + 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) echo -e ${COLOREDSTAR} "Trying to validate my serial ..." - #nice serial output + # nice serial output $CURS_UP $SET_WCOL echo "[ SN: ${ALX_SERIAL} ]" @@ -159,64 +114,122 @@ then ALX_STATE="ok" else + # abort on non valid serial ALX_STATE="invalid serial" + echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state + show_invalid_serial_msg + exit 1 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 autodetection 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 + # check if mysql server is reachable + # if not abort this script + if ! reach_mysql_server + then + preliminary_network stop + exit 1 + fi + 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 + # abort on non valid serial + ALX_STATE="invalid serial" + echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state + show_invalid_serial_msg + exit 1 + 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) - 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 ### + # 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}'") - #select highest id only (added max) + # 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} \ - "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'") + "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}'); + select last_insert_id() + 1;") 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 @@ -224,21 +237,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 } @@ -255,26 +268,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( @@ -293,9 +306,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, @@ -310,30 +323,120 @@ '1024x768', '16', '0' - );"; + );"; ) + evaluate_retval + + # input + 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 - 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} \ + "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 @@ -343,25 +446,104 @@ 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 + + # if only an recheck was forced than abort now + [[ ${ALX_FORCED_RECHECK} = true ]] && return 0 + + # 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 + + # now fix it with proper messages :P + local ver="$(< /etc/mageversion)" + sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \ + ${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 + + + # setup some standart icons (sysinfo.lnk) + # basic config + cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc + + # clean desktop icon location + [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop + install -d ${ALX_UNPRIV_HOME}/.xtdesktop + + # last but not least gen a icon with some sys informations + local sysinfo + local osversion + local xres + local yres + + osversion="$(< /etc/mageversion)" + sysinfo="Hostname: ${ALX_DEFAULT_HOSTNAME} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)" + + # at first boot we got always a resolution of 1024x768-16@60 + # middle of the screen + # (no txt - length required, xtdesk manage that itself) + xres="$((1024 / 2))" + # default y pos (full yres -22 !) + yres="$((768 - 22 ))" + + generate_icon \ + --name "${sysinfo}" \ + --command "exit 0" \ + --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \ + --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \ + --xres "${xres}" \ + --yres "${yres}" \ + --icon-width "1" \ + --icon-height "1" + + # 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}/.xtdesktop + chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc + + # 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 @@ -381,7 +563,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 @@ -411,24 +594,34 @@ case $1 in start) - #retrieve or validate current serial + # 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 @@ -437,3 +630,4 @@ echo "Usage: $0 {start|stop} ..." ;; esac +