#!/bin/bash # #%rlevels: 7:s 0:k 6:k #%start: 41 #%stop: 01 #deps #%needs: #%before: #%after: # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.12 2005-04-18 22:59:49 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 # # if client was valid it first will check if his settings against the server # if no changes are at server side they will be kept, if yes the get updated. # the server settings has higher priority. source /etc/sysconfig/rc source $rc_functions #mysql settings source /etc/alxconfig-ng/config.rc 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 ALX_HW_DETECT=false #unset vars which may kill us unset ALX_SERIAL ALX_STATE #setup needed directories [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state 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 # 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 config_ssh_auth } get_system_serial(){ local CUR_IP CUR_MAC CUR_MTIME #check if serial file exists if [ -f /etc/alxconfig-ng/serial ] then source /etc/alxconfig-ng/serial #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 $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 else #run hardware detection echo echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT} ALX_HW_DETECT=true /etc/init.d/hwdetect start #set hostname to alx_default_hostname [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx HOSTNAME="${ALX_DEFAULT_HOSTNAME}" #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) 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) 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}'") if [ "${ALX_SERIAL}" != NULL ] then #nice serial output $CURS_UP $SET_WCOL echo "[ SN: ${ALX_SERIAL} ]" #set ALX_STATE to ok so everybody that everything was ok ALX_STATE=ok 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) evaluate_retval #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 $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/alxconfig-ng/state/state } check_is_configured() { if [ -f /etc/alxconfig-ng/state/configured ] then export ALX_CONFIGURED=true else export ALX_CONFIGURED=false fi } # 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 [ -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}"Importing detected settings to database"${COLDEFAULT} #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' );" evaluate_retval #xserver echo -e " Graphic settings ..." #xserver general ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ "insert into cfg_graphic( serial, module, resolution, depth, monitorid ) values( '${ALX_SERIAL}', '${XMODULE}', '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 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 # 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/alxconfig-ng/state/configured ] then #get module name module=$(cat ${SETTINGSPATH}/modules) modprobe ${module} else #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 source /etc/sysconfig/hwsetup/knoppix modprobe ${NETCARD_DRIVER} fi case $1 in start) # keeping like always safe: # no network should be startet here, # so we can delete all pid files if one exists if ps -A|grep dhcpcd > /dev/null then echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT} dhcpcd -k sleep 1 else rm -f /var/run/dhcpcd-eth?.pid fi echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} dhcpcd &> /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 ;; stop) echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT} ifconfig eth0 down if ps -A|grep dhcpcd > /dev/null then dhcpcd -z &> /dev/null fi evaluate_retval ;; *) echo "Usage: preliminary_network {start|stop}" ;; esac } case $1 in start) #retrieve or validate current serial get_system_serial if [ "${ALX_HW_DETECT}" == "true" ] then import_settings_to_db 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() [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings #stop at last the preliminary networking (dhcp) preliminary_network stop ;; stop) #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 ;; *) echo "Usage: $0 {start|stop} ..." ;; esac