--- alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/03/08 20:49:14 221 +++ alx-src/trunk/alxconfig-ng/init.d/alxsettings 2005/08/17 21:19:52 282 @@ -11,6 +11,8 @@ #%before: #%after: +# $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 # these settings will be used for client setup @@ -19,810 +21,87 @@ # if no changes are at server side they will be kept, if yes the get updated. # the server settings has higher priority. -# +-----+ -# |start| -# +-----+ -# | -# | -# start_preliminary_network -# | -# | n -# serial_check -------> get_new_serial -# | | -# y| | -# | n | -# check_is_configured ----> run_hw_detection -# | | -# y| | -# n | | -# +--------cfg_equal_to_db import_settings_to_db -# | | | -# update_from_db y| | -# | | | -# set_is_configured | set_is_configured -# +-----------------| | -# +----------------------+ -# | -# | -# stop_preliminary_network -# | -# | -# +----+ -# |done| -# +----+ -# | -# | -# normal_system_bootup -# | -# . -# . -# . -# -# -# - source /etc/sysconfig/rc source $rc_functions -#mysql settings -source /etc/alx-config/config.rc -source /opt/alx-config/functions/mysqlfunctions -source /opt/alx-config/functions/alx-mysql-functions +# mysql settings +source /etc/alxconfig-ng/config.rc -#check if mysql is available +# 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 [ -x /usr/bin/mysql ] && MYSQL_ALX=true -#other needed vars +# other needed vars ALX_HW_DETECT=false -ALX_NETWORK_SETUP=false -ALX_XSERVER_SETUP=false -ALX_SESSION_SETUP=false -ALX_PRINTER_SETUP=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 -[ ! -d /etc/alx-config/state ] && install -d /etc/alx-config/state +# setup needed directories +[ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state -# still a need to implement this ? -# #needed to detect usb/livecd boot -# if [ -e /.bootdev ] -# then -# source /.bootdev -# else -# echo "Couldn't find /.bootdev. Aborting." -# exit 1 -# fi - -# still a need to implement this ? --> media-check ? -settings_import() { - if [ "${FSTYPE}" == "vfat" ] - then - if [ -e /mnt/cdrom/settings/system ] - then - echo -e ${COLOREDSTAR}"Importing old alx-settings ..." - ( cp -R /mnt/cdrom/settings/system/* /etc/alx-config/settings/menu && - source /etc/alx-config/config.rc && - source /opt/alx-config/Configurator/config_functions.sh && - setup_xfree > /dev/null 2>&1 && - setup_modules > /dev/null 2>&1 && - setup_network > /dev/null 2>&1 && - #setup_printers > /dev/null 2>&1 && - setup_sessions > /dev/null 2>&1 && - touch /etc/alx-config/imported ) - evaluate_retval - fi - fi -} - - -# this thingy needs an complete rewrite. -# first get all settings from db server, -# than check against local system settings, -# if there are any differences, update the local settings, -# as the server has a higher priority. -# Important: write local settings only if they make sense, -# to have a fallback in case the server is down! -#get_settings_from_server(){ -# #some needed arrays -# #ARRAY_NETWORK #module domain networking netmask dns gateway -# #SESSION # -# #GRAFIK # -# -# echo "Importing now old Settings ..." -# -# local serial module domain networking netmask dns gateway i x all -# -# declare -i i=0 -# -# #get hostname from database -# MY_HOSTNAME=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select hostname from cfg_serial where id='${ALX_SERIAL}'") -# -# #get network settings from database -# all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select module, -# domain, -# networking, -# netmask, -# dns, -# gateway, -# broadcast, -# ip -# from cfg_network where serial='${ALX_SERIAL}'") -# #split'em up and put in array -# for x in ${all} -# do -# ARRAY_NETWORK[${i}]=${x} -# ((i++)) -# done -# echo " Network:" -# echo " MODULE: ${ARRAY_NETWORK[0]}" -# echo " IP: ${ARRAY_NETWORK[7]}" -# echo " HOSTNAME: ${MY_HOSTNAME}" -# echo " DOMAIN: ${ARRAY_NETWORK[1]}" -# echo " NETWORKING: ${ARRAY_NETWORK[2]}" -# echo " NETMASK: ${ARRAY_NETWORK[3]}" -# echo " DNS: ${ARRAY_NETWORK[4]}" -# echo " GATEWAY: ${ARRAY_NETWORK[5]}" -# echo " BROADCAST: ${ARRAY_NETWORK[6]}" -# echo -# -# #get x settings from database -# local module resolution -# -# #reset i -# declare -i i=0 -# all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select module, -# resolution -# from cfg_grafik where serial='${ALX_SERIAL}'") -# #split'em up and put in array -# for x in ${all} -# do -# ARRAY_GRAFIK[${i}]=${x} -# ((i++)) -# done -# -# echo " VGA:" -# echo " MODULE: ${ARRAY_GRAFIK[0]}" -# echo " RESOLUTION: ${ARRAY_GRAFIK[1]}" -# echo -# -# #get ica-sessions from database -# ARRAY_SESSIONS=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select session from cfg_session where serial='${ALX_SERIAL}'") -# -# echo " SESSIONS:" -# declare -i i=0 -# for x in ${ARRAY_SESSIONS} -# do -# ((i++)) -# echo " SESSION${i}: ${x}" -# done -# echo -# -# #now write these settings -# local SETTINGSPATH -# -# #network -# -# #settings must be also set on system, so we put this to menu -# SETTINGSPATH=${SETTINGS_TEMPLATE}/menu -# -# [ ! -d ${SETTINGSPATH}/modules ] && install -d ${SETTINGSPATH}/modules -# echo "${ARRAY_NETWORK[0]}" > ${SETTINGSPATH}/modules/modules -# -# [ ! -d ${SETTINGSPATH}/network ] && install -d ${SETTINGSPATH}/network -# echo "${MY_HOSTNAME}" > ${SETTINGSPATH}/network/hostname -# echo "${ARRAY_NETWORK[1]}" > ${SETTINGSPATH}/network/domain -# echo "${ARRAY_NETWORK[2]}" > ${SETTINGSPATH}/network/networking -# [ -n "${ARRAY_NETWORK[3]}" ] && echo "${ARRAY_NETWORK[3]}" > ${SETTINGSPATH}/network/netmask -# [ -n "${ARRAY_NETWORK[4]}" ] && echo "${ARRAY_NETWORK[4]}" > ${SETTINGSPATH}/network/dns -# [ -n "${ARRAY_NETWORK[5]}" ] && echo "${ARRAY_NETWORK[5]}" > ${SETTINGSPATH}/network/gateway -# [ -n "${ARRAY_NETWORK[6]}" ] && echo "${ARRAY_NETWORK[6]}" > ${SETTINGSPATH}/network/broadcast -# [ -n "${ARRAY_NETWORK[7]}" ] && echo "${ARRAY_NETWORK[7]}" > ${SETTINGSPATH}/network/ip - - -validate_networking(){ - #source /opt/alx-config/Configurator/config_functions.sh - - local x i all LOCAL_NETWORK DB_NETWORK SETTINGSPATH - - #all arrays: - # -> hostname modules domain networking ip netmask dns gateway broadcast - - #networking - #get settings from local system - SETTINGSPATH=${SETTINGS_TEMPLATE}/system - declare -i i=0 - for x in network/hostname \ - modules/modules \ - network/domain \ - network/networking \ - network/ip \ - network/netmask \ - network/dns \ - network/gateway \ - network/broadcast - do - if [ -f ${SETTINGSPATH}/${x} ] - then - #file exist, then use content - LOCAL_NETWORK[${i}]="$(< ${SETTINGSPATH}/${x})" - else - LOCAL_NETWORK[${i}]="" - fi - ((i++)) - done - - #get settings from database -# DB_NETWORK[0]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select hostname from cfg_network where serial='${ALX_SERIAL}'") - - all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select hostname, - module, - domain, - networking, - ip, - netmask, - dns, - gateway, - broadcast - from cfg_network where serial='${ALX_SERIAL}'") - - #split'em up and put in an array - declare -i i=0 - for x in ${all} - do - DB_NETWORK[${i}]=${x} - ((i++)) - done - - #needed by the small hotfix - local FIX_ME - FIX_ME="${DB_NETWORK[2]}" - - - #now compare this stuff if they are equal - for ((i=0; i < 9; i++)) - do - if [ "${DB_NETWORK[${i}]}" = "${LOCAL_NETWORK[${i}]}" ] - then - echo "${i}: ${DB_NETWORK[${i}]} == ${LOCAL_NETWORK[${i}]}" - - #delete equal stuff from DB_NETWORK - DB_NETWORK[${i}]="*NULL*" - - else - echo "${i}: ${DB_NETWORK[${i}]} != ${LOCAL_NETWORK[${i}]}" - fi - done - - - #update configs - SETTINGSPATH=${SETTINGS_TEMPLATE}/menu - declare -i i=0 - for x in network/hostname \ - modules/modules \ - network/domain \ - network/networking \ - network/ip \ - network/netmask \ - network/dns \ - network/gateway \ - network/broadcast - do - #update only staff wich wasn't overwritten - if [ "${DB_NETWORK[${i}]}" != "*NULL*" ] - then - #create directory if not exist - if [ ! -d $(dirname ${SETTINGSPATH}/${x}) ] - then - install -d $(dirname ${SETTINGSPATH}/${x}) - fi - echo "${DB_NETWORK[${i}]}" > ${SETTINGSPATH}/${x} - - # theses fucking config functions: - # network gets only updated, - # if ${SETTINGS_TEMPLATE}/menu/network/networking exist - # so we force an update here - if [ ! -f ${SETTINGSPATH}/network/networking ] - then - [ ! -d ${SETTINGSPATH}/network ] && install -d ${SETTINGSPATH}/network - echo "${FIX_ME}" > ${SETTINGSPATH}/network/networking - fi - - #set update flag - ALX_NETWORK_SETUP=true - fi - ((i++)) - done -} +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 -validate_xserver(){ - #source /opt/alx-config/Configurator/config_functions.sh - - local x i all LOCAL_XSERVER DB_XSERVER SETTINGSPATH - - #all arrays: - # -> xmodule resolution depth mouse monvendor monmodel hsync vref - - #xserver - #get settings from local system - #vga - SETTINGSPATH=${SETTINGS_TEMPLATE}/system - declare -i i=0 - for x in vga/vga \ - vga/vgares \ - vga/vgadepth - do - if [ -f ${SETTINGSPATH}/${x} ] - then - #file exist, then use content - LOCAL_XSERVER[${i}]="$(< ${SETTINGSPATH}/${x})" - else - LOCAL_XSERVER[${i}]="" - fi - ((i++)) - done - - #mouse - if [ -f ${SETTINGSPATH}/mouse/mouse ] - then - #file exist, then use content - LOCAL_XSERVER[3]="$(< ${SETTINGSPATH}/mouse/mouse)" - else - LOCAL_XSERVER[3]="" - fi - - #monitor - local myvendor mymodel hsync vref - if [ -f ${SETTINGSPATH}/monitor/monitor ] - then - source ${SETTINGSPATH}/monitor/monitor - - declare -i i=4 - for x in "${myvendor}" \ - "${mymodel}" \ - "${hsync}" \ - "${vref}" - do - LOCAL_XSERVER[${i}]="${x}" - ((i++)) - done - else - LOCAL_XSERVER[4]="" - LOCAL_XSERVER[5]="" - LOCAL_XSERVER[6]="" - LOCAL_XSERVER[7]="" - fi - - - #get settings from database - all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select module, - resolution, - depth - from cfg_graphic where serial='${ALX_SERIAL}'") - - #split'em up and put in an array - declare -i i=0 - for x in ${all} - do - DB_XSERVER[${i}]=${x} - ((i++)) - done - - # read mouse - DB_XSERVER[3]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select mouse from cfg_input where serial='${ALX_SERIAL}'") - - #monitors -# all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select vendor, -# model, -# hsync, -# vrefresh -# from cfg_monitor where serial='${ALX_SERIAL}'") - - all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select vendor, - model, - hsync, - vrefresh - from list_monitors - inner join cfg_graphic - on cfg_graphic.monitorid=list_monitors.id;") - - #split'em up and put in an array - declare -i i=4 - for x in ${all} - do - DB_XSERVER[${i}]=${x} - ((i++)) - done - -# #now compare this stuff if they are equal -# for ((i=0; i < 8; i++)) -# do -# if [ "${DB_XSERVER[${i}]}" = "${LOCAL_XSERVER[${i}]}" ] -# then -# echo "${i}: ${DB_XSERVER[${i}]} == ${LOCAL_XSERVER[${i}]}" -# -# #delete equal stuff from DB_NETWORK -# DB_XSERVER[${i}]="*NULL*" -# -# else -# echo "${i}: ${DB_XSERVER[${i}]} != ${LOCAL_XSERVER[${i}]}" -# fi -# done -# -# -# #update configs -# SETTINGSPATH=${SETTINGS_TEMPLATE}/menu -# #xserver general -# declare -i i=0 -# for x in vga/vga \ -# vga/vgares \ -# vga/vgadepth \ -# mouse/mouse -# do -# #update only staff wich wasn't overwritten -# if [ "${DB_XSERVER[${i}]}" != "*NULL*" ] -# then -# #create directory if not exist -# if [ ! -d $(dirname ${SETTINGSPATH}/${x}) ] -# then -# install -d $(dirname ${SETTINGSPATH}/${x}) -# fi -# echo "${DB_XSERVER[${i}]}" > ${SETTINGSPATH}/${x} -# #set update flag -# ALX_XSERVER_SETUP=true -# fi -# ((i++)) -# done -# -# #xserver monitors -# if [ "${DB_XSERVER[4]}" != "*NULL*" \ -# -o "${DB_XSERVER[5]}" != "*NULL*" \ -# -o "${DB_XSERVER[6]}" != "*NULL*" \ -# -o "${DB_XSERVER[7]}" != "*NULL*" ] -# then -# if [ ! -d ${SETTINGSPATH}/monitor ] -# then -# install -d ${SETTINGSPATH}/monitor -# fi -# echo "myvendor=\"${DB_XSERVER[4]}\"" > ${SETTINGSPATH}/monitor/monitor -# echo "mymodel=\"${DB_XSERVER[5]}\"" >> ${SETTINGSPATH}/monitor/monitor -# echo "hsync=\"${DB_XSERVER[6]}\"" >> ${SETTINGSPATH}/monitor/monitor -# echo "vref=\"${DB_XSERVER[7]}\"" >> ${SETTINGSPATH}/monitor/monitor -# -# #set update flag -# ALX_XSERVER_SETUP=true -# fi - - # - damn fucking setup_xfree routine need to rewrite this fucking stuff - - # setup_xfree will only run - # if ${SETTINGS_TEMPLATE}/menu/vga/vga exist - # so we must *always* update *all* settings if something has changed - - #now compare this stuff if they are equal - for ((i=0; i < 8; i++)) - do - if [ "${DB_XSERVER[${i}]}" = "${LOCAL_XSERVER[${i}]}" ] - then - echo "${i}: ${DB_XSERVER[${i}]} == ${LOCAL_XSERVER[${i}]}" - - #delete equal stuff from DB_NETWORK - #DB_XSERVER[${i}]="*NULL*" - - else - echo "${i}: ${DB_XSERVER[${i}]} != ${LOCAL_XSERVER[${i}]}" - fi - done + # imports x11 settings from db + config_x11 - SETTINGSPATH=${SETTINGS_TEMPLATE}/menu - if [ "${DB_XSERVER[0]}" != "*NULL*" \ - -o "${DB_XSERVER[1]}" != "*NULL*" \ - -o "${DB_XSERVER[2]}" != "*NULL*" \ - -o "${DB_XSERVER[3]}" != "*NULL*" \ - -o "${DB_XSERVER[4]}" != "*NULL*" \ - -o "${DB_XSERVER[5]}" != "*NULL*" \ - -o "${DB_XSERVER[6]}" != "*NULL*" \ - -o "${DB_XSERVER[7]}" != "*NULL*" ] - then - [ ! -d ${SETTINGSPATH}/vga ] && install -d ${SETTINGSPATH}/vga - [ ! -d ${SETTINGSPATH}/mouse ] && install -d ${SETTINGSPATH}/mouse - [ ! -d ${SETTINGSPATH}/monitor ] && install -d ${SETTINGSPATH}/monitor - - echo "${DB_XSERVER[0]}" > ${SETTINGSPATH}/vga/vga - echo "${DB_XSERVER[1]}" > ${SETTINGSPATH}/vga/vgares - echo "${DB_XSERVER[2]}" > ${SETTINGSPATH}/vga/vgadepth - echo "${DB_XSERVER[3]}" > ${SETTINGSPATH}/mouse/mouse - - echo "myvendor=\"${DB_XSERVER[4]}\"" > ${SETTINGSPATH}/monitor/monitor - echo "mymodel=\"${DB_XSERVER[5]}\"" >> ${SETTINGSPATH}/monitor/monitor - echo "hsync=\"${DB_XSERVER[6]}\"" >> ${SETTINGSPATH}/monitor/monitor - echo "vref=\"${DB_XSERVER[7]}\"" >> ${SETTINGSPATH}/monitor/monitor - - #set update flag - ALX_XSERVER_SETUP=true - fi -} + # imports session settings from db + config_sessions + # imports printer settings from db + config_printing -validate_sessions(){ - #source /opt/alx-config/Configurator/config_functions.sh + # imports auth settings from db + config_auth - 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 -} - - -validate_printing(){ - #source /opt/alx-config/Configurator/config_functions.sh - - local x i k all LOCAL_PRINTER DB_PRINTER SETTINGSPATH count - - #all arrays: [2 dimensions !] - # -> name1 name2 ... nameN - # -> name1 printingport ip share - - #later on, for now -> name1 port1 ip1 share1 name2 .... - # seperator is 4 - - #local PRINTERNAME PRINTING IP SHARE - - # update *always* printers from database; - # compare with local settings cannot be done yet - - #get settings from database - all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "select printer_name, - port, - ip, - share - from cfg_printers where serial='${ALX_SERIAL}'") - - #split'em up and put in an array - declare -i i=0 - declare -i k=0 - - if [ -n "${all}" ] - then - for x in ${all} - do - ((k++)) - DB_PRINTER[${i}]="${DB_PRINTER[${i}]} ${x}" - if [ ${k} -eq 4 ] - then - ((i++)) - #reset $k - declare -i k=0 - fi - done - count=${i} - else - count=0 - fi - - #echo settings - echo "Number of new printers: ${count}" - for ((i=0; i < count; i++)) - do - echo "${i} printer:" - for x in ${DB_PRINTER[${i}]} - do - echo " ${x}" - done - done - - #import settings (only if counter > 0) - local prnset - - #delete all printers (*always*) - if [ -d ${SETTINGS_TEMPLATE}/system/printing ] - then - SETTINGSPATH=${SETTINGS_TEMPLATE}/menu - [ -d ${SETTINGSPATH}/delete ] && rm -rf ${SETTINGSPATH}/delete - install -d ${SETTINGSPATH}/delete - mv -f ${SETTINGS_TEMPLATE}/system/printing/* ${SETTINGSPATH}/delete - rm -rf ${SETTINGS_TEMPLATE}/system/printing - - #set update flag (*always*) - ALX_PRINTER_SETUP=true - fi - - if [ ${count} -gt 0 ] - then - SETTINGSPATH=${SETTINGS_TEMPLATE}/menu - - [ ! -d ${SETTINGSPATH}/printing ] && install -d ${SETTINGSPATH}/printing - for ((i=0; i < count; i++)) - do - declare -i k=0 - for x in ${DB_PRINTER[${i}]} - do - prnset[${k}]=${x} - ((k++)) - done - - echo "PRINTERNAME=${prnset[0]}" > ${SETTINGSPATH}/printing/${prnset[0]} - echo "PRINTING=${prnset[1]}" >> ${SETTINGSPATH}/printing/${prnset[0]} - echo "IP=${prnset[2]}" >> ${SETTINGSPATH}/printing/${prnset[0]} - echo "SHARE=${prnset[3]}" >> ${SETTINGSPATH}/printing/${prnset[0]} - done - - #set update flag (*always*) - ALX_PRINTER_SETUP=true - fi - -} - -update_system_settings(){ - source /opt/alx-config/Configurator/config_functions.sh - - echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} - - echo - echo "network" - validate_networking - echo - echo "xserver" - validate_xserver - echo - echo "sessions" - validate_sessions - echo - #echo "printers" - #validate_printing - #echo - - if [ "${ALX_NETWORK_SETUP}" == "true" ] - then - echo -e ${COLMAGENTA}"Updating network settings"${COLDEFAULT} - setup_modules - setup_network - fi - - if [ "${ALX_XSERVER_SETUP}" == "true" ] - then - echo -e ${COLMAGENTA}"Updating xserver settings"${COLDEFAULT} - setup_xfree - fi - - if [ "${ALX_SESSION_SETUP}" == "true" ] - then - echo -e ${COLMAGENTA}"Updating session settings"${COLDEFAULT} - setup_sessions - fi - - #if [ "${ALX_PRINTER_SETUP}" == "true" ] - #then - # echo -e ${COLMAGENTA}"Updating printer settings"${COLDEFAULT} - # setup_printers - #fi - - #clean up temp files - local SETTINGSPATH - SETTINGSPATH=${SETTINGS_TEMPLATE}/menu - #[ -d ${SETTINGSPATH} ] && rm -rf ${SETTINGSPATH} + # 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/alx-config/serial ] + # check if serial file exists + if [ -f /etc/alxconfig-ng/serial ] && [ ! -f /hardware-auto-detection ] then - source /etc/alx-config/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) - preliminary_network start - + source /etc/alxconfig-ng/serial + + # 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) 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} ]" - -# #is this system outdated ? -# #MY_HOSTNAME=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# # "select hostname from cfg_serial where id='${ALX_SERIAL}'") -# -# #we do this now with the date instead of the hostname -# local MY_ALX_REG_DATE -# MY_ALX_REG_DATE=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ -# "select mtime from client_serial where serial='${ALX_SERIAL}'") -# -# #if [ "${MY_HOSTNAME}" == "${HOSTNAME}" ] -# if [ "${MY_ALX_REG_DATE}" == "${ALX_REG_DATE}" ] -# then -# #set ALX_STATE to ok so everybody that everything was ok -# ALX_STATE=ok -# -# evaluate_retval -# else -# #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 -# ALX_STATE=error -# fi if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" then @@ -832,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 - echo "HOSTNAME=${HOSTNAME}" > /etc/hostname - - #start preliminary networking (dhcp) + + # update the hostname on the system for sure + echo "${HOSTNAME}" > /etc/hostname + + # 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)" - - #we're using the mtime now (better for vaildating the serial) + + # 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, @@ -867,57 +183,53 @@ '${CUR_MTIME}', '${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 then one serial number than ### - - #not 100% working may get more than *one* id - #ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - # "select id from cfg_serial where datum='${ALX_REG_DATE}' and hostname='${HOSTNAME}'") - - #select highest id only (added max) + ### 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}'") 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/alx-config/serial - echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alx-config/serial - + + echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial + echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial + 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 - echo "ALX_STATE=${ALX_STATE}" > /etc/alx-config/state/state + + # write current state to temp file + echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state } check_is_configured() { - if [ -f /etc/alx-config/state/configured ] + if [ -f /etc/alxconfig-ng/state/configured ] then export ALX_CONFIGURED=true else @@ -928,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 - - #to be safe, we do some sanity checks + # 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 [ -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( @@ -965,125 +277,206 @@ 'dhcp' );" 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, module, resolution, - depth + depth, + monitorid ) values( '${ALX_SERIAL}', '${XMODULE}', '1024x768', - '16' - );"; - #xserver monitor - mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "insert into cfg_monitor( + '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, - vendor, - model, - hsync, - vrefresh + username, + shell, + vnc, + samba, + station ) values( '${ALX_SERIAL}', - 'Aamazing', - 'CM-1528-FS', - '28-64', - '47-104' - );"; - + '${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 - mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ - "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');";) + 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 local system resolved by the hardware detection -import_settings_local(){ - #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 +# 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 + + # 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 local system"${COLDEFAULT} + echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT} - - #allready configured, no update needed so we put it to system - SETTINGSPATH=${SETTINGS_TEMPLATE}/system - - - #network + # network echo -e " Network settings ..." - [ ! -d ${SETTINGSPATH}/modules ] && install -d ${SETTINGSPATH}/modules - echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules/modules - - [ ! -d ${SETTINGSPATH}/network ] && install -d ${SETTINGSPATH}/network - ( echo "${ALX_DEFAULT_HOSTNAME}" > ${SETTINGSPATH}/network/hostname; - echo "${ALX_DEFAULT_DOMAIN}" > ${SETTINGSPATH}/network/domain; - echo "dhcp" > ${SETTINGSPATH}/network/networking ) + 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 + + # xserver echo -e " Graphic settings ..." - - [ ! -d ${SETTINGSPATH}/vga ] && install -d ${SETTINGSPATH}/vga - [ ! -d ${SETTINGSPATH}/mouse ] && install -d ${SETTINGSPATH}/mouse - [ ! -d ${SETTINGSPATH}/monitor ] && install -d ${SETTINGSPATH}/monitor - ( echo "${XMODULE}" > ${SETTINGSPATH}/vga/vga; - echo "16" > ${SETTINGSPATH}/vga/vgadepth; - echo "1024x768" > ${SETTINGSPATH}/vga/vgares; - echo "${XMOUSETYPE}" > ${SETTINGSPATH}/mouse/mouse; - echo "myvendor=\"Aamazing\"" > ${SETTINGSPATH}/monitor/monitor; - echo "mymodel=\"CM-1528-FS\"" >> ${SETTINGSPATH}/monitor/monitor; - echo "hsync=\"28-64\"" >> ${SETTINGSPATH}/monitor/monitor; - echo "vref=\"47-104\"" >> ${SETTINGSPATH}/monitor/monitor;) + # 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 - - #set system state to 'already configured' - touch /etc/alx-config/state/configured } -#start|stop +# 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 + + # 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 + + echo + echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT} + + [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} + echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules + evaluate_retval + + # 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 preliminary_network(){ local module - - if [ -f /etc/alx-config/state/configured ] + + if [ -f /etc/alxconfig-ng/state/configured ] then - #get module name - module=$(cat ${SETTINGS_TEMPLATE}/system/modules/modules) + # 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 - + case $1 in start) # keeping like always safe: @@ -1097,28 +490,31 @@ else rm -f /var/run/dhcpcd-eth?.pid fi - + echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} - #dhcpcd &> /dev/null #&& echo "ok" || echo "false" - + # -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 + #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 ;; + stop) echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT} ifconfig eth0 down if ps -A|grep dhcpcd > /dev/null then - #echo -en ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT} dhcpcd -z &> /dev/null fi evaluate_retval ;; + *) echo "Usage: preliminary_network {start|stop}" ;; @@ -1127,29 +523,51 @@ 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/alx-config/state/state ] && rm /etc/alx-config/state/state + [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state sleep 0.1 ;; *) echo "Usage: $0 {start|stop} ..." ;; esac +