Magellan Linux

Diff of /alx-src/branches/alxconf-060/init.d/alxsettings

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 226 by niro, Wed Mar 9 00:04:18 2005 UTC revision 348 by niro, Sun Oct 9 21:38:14 2005 UTC
# Line 11  Line 11 
11  #%before:  #%before:
12  #%after:  #%after:
13    
14    # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.23 2005-10-09 21:38:14 niro Exp $
15    
16  # checks first if the client was already configured and if it has an valid serial  # checks first if the client was already configured and if it has an valid serial
17  # if not it runs the autoconfiguration script  # if not it runs the autoconfiguration script
18  # these settings will be used for client setup  # these settings will be used for client setup
# Line 22  Line 24 
24  source /etc/sysconfig/rc  source /etc/sysconfig/rc
25  source $rc_functions  source $rc_functions
26    
27  #mysql settings  # mysql settings
28  source /etc/alxconfig-ng/config.rc  source /etc/alxconfig-ng/config.rc
29    
30    # helper functions
31  source /usr/lib/alxconfig-ng/functions/mysqlfunctions  source /usr/lib/alxconfig-ng/functions/mysqlfunctions
32  source /usr/lib/alxconfig-ng/functions/mysqlfunctions  source /usr/lib/alxconfig-ng/functions/serial_functions
33    source /usr/lib/alxconfig-ng/functions/config_modules
34  source /usr/lib/alxconfig-ng/functions/config_network  source /usr/lib/alxconfig-ng/functions/config_network
35  source /usr/lib/alxconfig-ng/functions/config_printers  source /usr/lib/alxconfig-ng/functions/config_printers
36    source /usr/lib/alxconfig-ng/functions/config_sessions
37  source /usr/lib/alxconfig-ng/functions/config_x11  source /usr/lib/alxconfig-ng/functions/config_x11
38    source /usr/lib/alxconfig-ng/functions/config_auth
39    source /usr/lib/alxconfig-ng/functions/config_ssh_auth
40    
41  #check if mysql is available  # check if mysql is available
42  [ -x /usr/bin/mysql ] && MYSQL_ALX=true  [ -x /usr/bin/mysql ] && MYSQL_ALX=true
43    
44  #other needed vars  # other needed vars
45  ALX_HW_DETECT=false  ALX_HW_DETECT=false
46    ALX_FORCED_RECHECK=false
47    ALX_RESET_SETTINGS=false
48    ALX_CONFD_NETWORKING=false
49    
50  #unset vars which may kill us  # unset vars which may kill us
51  unset ALX_SERIAL ALX_STATE  unset ALX_SERIAL ALX_STATE
52    
53    
54  #setup needed directories  # setup needed directories
55  [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state  [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
56    
57    
58  validate_sessions(){  # read_cmdline ${item}
59    read_cmdline()
60    {
61     local i
62    
63   local x i all LOCAL_SESSIONS DB_SESSIONS SETTINGSPATH count   for i in $(< /proc/cmdline)
   
  #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++))  
64   do   do
65   echo "${i} - ${DB_SESSIONS[${i}]}"   [[ ${i} = $1 ]] && return 0
66   done   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  
 }  
67    
68     return 1
69    }
70    
71  update_system_settings(){  update_system_settings()
72    {
73   echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}   echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
74    
75     # get the modules settings
76     # ! is the first thing that must be configured !
77     config_modules
78    
79   # imports network settings from db   # imports network settings from db
80   config_networking   config_networking
81    
82   # imports x11 settings from db   # imports x11 settings from db
83   config_x11   config_x11
84    
85   #echo   # imports session settings from db
86   #echo "sessions"   config_sessions
  #validate_sessions  
  #echo  
87    
88   # imports printer settings from db   # imports printer settings from db
89   config_printing   config_printing
 }  
   
 # 1.serial 2.mtime 3.mac  
 validate_serial()  
 {  
  local serial  
  local db_serial  
  local mtime  
  local mac  
90    
91   # abort if params are missing   # imports auth settings from db
92   [ $# -ne 3 ] && return 1   config_auth
93    
94   serial=$1   # exchange ssh rsa keys
95   mtime=$2   HOME=/root config_ssh_auth
  mac=$3  
   
  db_serial=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \  
  "select serial from client_serials where mtime='${mtime}' and mac='${mac}'" )  
   
  if [[ ${db_serial} = ${serial} ]]  
  then  
  return 0  
  else  
  return 1  
  fi  
96  }  }
97    
98  get_system_serial(){  get_system_serial()
99    {
100   local CUR_IP CUR_MAC CUR_MTIME   local CUR_IP CUR_MAC CUR_MTIME
101    
102   #check if serial file exists   # check if serial file exists
103   if [ -f /etc/alxconfig-ng/serial ]   if [ -f /etc/alxconfig-ng/serial ] && [[ ${ALX_FORCED_RECHECK} = false ]]
104   then   then
105   source /etc/alxconfig-ng/serial   source /etc/alxconfig-ng/serial
106    
107   # if system is already configured, it *has* a hostname.   # start preliminary networking (dhcp)
  # so we take the hostname of this system here  
  source /etc/hostname  
   
  #start preliminary networking (dhcp)  
108   preliminary_network start   preliminary_network start
109    
110   CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')   # check if mysql server is reachable
111   CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)   # if not abort this script
112     if ! reach_mysql_server
113     then
114     preliminary_network stop
115     exit 1
116     fi
117    
118     CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
119     CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
120   CUR_MTIME=$(date +%s)   CUR_MTIME=$(date +%s)
121    
122   echo -e ${COLOREDSTAR} "Trying to validate my serial ..."   echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
123    
124   #nice serial output   # nice serial output
125   $CURS_UP   $CURS_UP
126   $SET_WCOL   $SET_WCOL
127   echo "[ SN: ${ALX_SERIAL} ]"   echo "[ SN: ${ALX_SERIAL} ]"
# Line 183  get_system_serial(){ Line 130  get_system_serial(){
130   then   then
131   ALX_STATE="ok"   ALX_STATE="ok"
132   else   else
133     # abort on non valid serial
134   ALX_STATE="invalid serial"   ALX_STATE="invalid serial"
135     echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
136     show_invalid_serial_msg
137     exit 1
138   fi   fi
139    
140   else   else
141   #run hardware detection   # run hardware detection
142   echo   echo
143   echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}   if [[ ${ALX_FORCED_RECHECK} = true ]]
144     then
145     echo -e ${COLMAGENTA}"Hardware autodetection forced by system-administrator"${COLDEFAULT}
146     else
147     echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}
148     fi
149   ALX_HW_DETECT=true   ALX_HW_DETECT=true
150   /etc/init.d/hwdetect start   /etc/init.d/hwdetect start
151    
152   #set hostname to alx_default_hostname   # set hostname to alx_default_hostname
153     # use old hostname if this is a forced re-check
154     [[ ${ALX_FORCED_RECHECK} = true ]] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)"
155   [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx   [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
156   HOSTNAME="${ALX_DEFAULT_HOSTNAME}"   HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
157    
158   #update the hostname on the system for sure   # update the hostname on the system for sure
159   echo "HOSTNAME=${HOSTNAME}" > /etc/hostname   echo "${HOSTNAME}" > /etc/hostname
160    
161   #start preliminary networking (dhcp)   # start preliminary networking (dhcp)
162   preliminary_network start   preliminary_network start
163    
164     # check if mysql server is reachable
165     # if not abort this script
166     if ! reach_mysql_server
167     then
168     preliminary_network stop
169     exit 1
170     fi
171    
172   CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')   CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
173   CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)   CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
174   CUR_MTIME=$(date +%s)   CUR_MTIME=$(date +%s)
175    
176   echo -e ${COLOREDSTAR} "Trying to get new serial ..."   # abort now if this is a forced re-check
177     if [[ ${ALX_FORCED_RECHECK} = true ]]
178     then
179     # but first check the serial
180     source /etc/alxconfig-ng/serial
181    
182   #request new serial   echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
  #ALX_REG_DATE="$(date +%F)"  
183    
184   #we're using the mtime now (better for vaildating the serial)   # nice serial output
185   mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   $CURS_UP
186   "insert into client_serials(   $SET_WCOL
187   mtime,   echo "[ SN: ${ALX_SERIAL} ]"
  mac  
  )  
  values(  
  '${CUR_MTIME}',  
  '${CUR_MAC}'  
  );"  
188    
189   #then validate and retrieve serial   if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
190     then
191     ALX_STATE="ok"
192     else
193     # abort on non valid serial
194     ALX_STATE="invalid serial"
195     echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
196     show_invalid_serial_msg
197     exit 1
198     fi
199    
200   ### warning must be changed that only the LAST ID will be fetched,  ###   # write current state to temp file
201   ### or you get error if the computer name and date are the same     ###   echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
202   ### you have more than one serial number then                       ###   [ -f /hardware-auto-detection ] && rm /hardware-auto-detection
203    
204     # now export ALX_FORCED_RECHECK=true
205     # that the setting will be updated not inserted !
206     export ALX_FORCED_RECHECK=true
207     return 0
208     fi
209    
210     echo -e ${COLOREDSTAR} "Trying to get new serial ..."
211    
212   #select highest id only (added max)   # request a new serial; one command now (cause must be done in the same session)
213   ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ALX_SERIAL=$(mysqldo "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}');
214   "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'")   select last_insert_id();")
215    
216   if [ "${ALX_SERIAL}" != NULL ]   if [[ ${ALX_SERIAL} != NULL ]]
217   then   then
218   #nice serial output   # nice serial output
219   $CURS_UP   $CURS_UP
220   $SET_WCOL   $SET_WCOL
221   echo "[ SN: ${ALX_SERIAL} ]"   echo "[ SN: ${ALX_SERIAL} ]"
222    
223   #set ALX_STATE to ok so everybody that everything was ok   # set ALX_STATE to ok so everybody knows that everything was ok
224   ALX_STATE=ok   ALX_STATE=ok
225    
226   echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial   echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
# Line 248  get_system_serial(){ Line 228  get_system_serial(){
228    
229   evaluate_retval   evaluate_retval
230   else   else
231   #print false (works only if this is the first statement here)   # print false (works only if this is the first statement here)
232   evaluate_retval   evaluate_retval
233    
234   #set ALX_STATE to error so everybody sees there was an error   # set ALX_STATE to error so everybody sees there was an error
235   ALX_STATE=error   ALX_STATE=error
236    
237   #show an error that no new serial was found   # show an error that no new serial was found
238   #nice serial output   # nice serial output
239   $CURS_UP   $CURS_UP
240   $SET_WCOL   $SET_WCOL
241   echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"   echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
242   fi   fi
243   fi   fi
244    
245   #write current state to temp file   # write current state to temp file
246   echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state   echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
247     echo "ALX_IFACE=${ALX_IFACE}" >> /etc/alxconfig-ng/state/state
248  }  }
249    
250    
251  check_is_configured() {  check_is_configured()
252    {
253   if [ -f /etc/alxconfig-ng/state/configured ]   if [ -f /etc/alxconfig-ng/state/configured ]
254   then   then
255   export ALX_CONFIGURED=true   export ALX_CONFIGURED=true
# Line 278  check_is_configured() { Line 260  check_is_configured() {
260    
261    
262  # imports current settings to the database resolved by the hardware detection  # imports current settings to the database resolved by the hardware detection
263  import_settings_to_db() {  import_settings_to_db()
264   #note: networking is always 'dhcp' if hw was autodetected  {
265   #note: default_domain/hostname is set in config.rc   # note: networking is always 'dhcp' if hw was autodetected
266     # note: default_domain/hostname is set in config.rc
267   #to be safe, we do some sanity checks  
268     # to be safe, we do some sanity checks
269   [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain   [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
270   [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx   [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
271    
272   #vars used by hwdetect   # vars used by hwdetect
273   local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME   local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
274   local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER   local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
275   local MOUSETYPE XMOUSETYPE FULLNAME DEVICE   local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
276    
277   #get setting from hwdetect   # get setting from hwdetect
278   source /etc/sysconfig/hwsetup/knoppix   source /etc/sysconfig/hwsetup/knoppix
279   source /etc/sysconfig/hwsetup/mouse   source /etc/sysconfig/hwsetup/mouse
280    
281   echo   echo
282   echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}   echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
283    
284   #network   # network
285   echo -e "      Network settings ..."   echo -e "      Network settings ..."
286   mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   if [[ ${ALX_CONFD_NETWORKING} = true ]]
287   "insert into cfg_network(   then
288   hostname,   # get settings
289   serial,   #source ${rc_base}/init.d/network &> /dev/null
290   module,   for iface in $(onboot_interface_list ${network_settings}/net.*)
291   domain,   do
292   networking   [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue
293   )   echo "WARNING: only importing settings for interface [ ${iface} ] !"
294   values(   source ${network_settings}/net.${iface} || exit 1
295   '${ALX_DEFAULT_HOSTNAME}',   NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)"
296   '${ALX_SERIAL}',  
297   '${NETCARD_DRIVER}',   mysqldo "insert into cfg_network(
298   '${ALX_DEFAULT_DOMAIN}',   hostname,
299   'dhcp'   serial,
300   );"   module,
301     domain,
302     networking,
303     netmask,
304     dns,
305     gateway,
306     broadcast,
307     ip,
308     forcemacto,
309     wireless_bitrate,
310     wireless_channel,
311     wireless_essid,
312     wireless_frequency,
313     wireless_mode,
314     wireless_nick,
315     wireless_auth_mode,
316     wireless_key_length,
317     wireless_key,
318     wireless_key_ascii
319     )
320     values(
321     '${ALX_DEFAULT_HOSTNAME}',
322     '${ALX_SERIAL}',
323     '${NETCARD_DRIVER}',
324     '${ALX_DEFAULT_DOMAIN}',
325     '${NETWORKING}',
326     '${NETMASK}',
327     '${NAMESERVER}',
328     '${GATEWAY}',
329     '${BROADCAST}',
330     '${IP}',
331     '${FORCE_MAC_TO}',
332     '${WIRELESS_BITRATE}',
333     '${WIRELESS_CHANNEL}',
334     '${WIRELESS_ESSID}',
335     '${WIRELESS_FREQUENCY}',
336     '${WIRELESS_MODE}',
337     '${WIRELESS_NICK}',
338     '${WIRELESS_AUTH_MODE}',
339     '${WIRELESS_KEY_LENGTH}',
340     '${WIRELESS_KEY}',
341     '${WIRELESS_KEY_ASCII}'
342     );"
343    
344     # only insert the *FIRST* iface
345     break
346     done
347     else
348     mysqldo "insert into cfg_network(
349     hostname,
350     serial,
351     module,
352     domain,
353     networking
354     )
355     values(
356     '${ALX_DEFAULT_HOSTNAME}',
357     '${ALX_SERIAL}',
358     '${NETCARD_DRIVER}',
359     '${ALX_DEFAULT_DOMAIN}',
360     'dhcp'
361     );"
362     fi
363   evaluate_retval   evaluate_retval
364    
365   #xserver   # xserver
366   echo -e "      Graphic settings ..."   echo -e "      Graphic settings ..."
367   #xserver general   # xserver general
368   ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   ( mysqldo "insert into cfg_graphic(
  "insert into cfg_graphic(  
369   serial,   serial,
370   module,   module,
371   resolution,   resolution,
372   depth   depth,
373     monitorid
374   )   )
375   values(   values(
376   '${ALX_SERIAL}',   '${ALX_SERIAL}',
377   '${XMODULE}',   '${XMODULE}',
378   '1024x768',   '1024x768',
379   '16'   '16',
380   );";   '0'
381   #xserver monitor   );"; )
382    mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   evaluate_retval
383   "insert into cfg_monitor(  
384     # input
385     echo -e "      Input settings ..."
386     mysqldo "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');"
387     evaluate_retval
388    
389     # auth
390     echo -e "      Authentification settings ..."
391     mysqldo "insert into client_auth(
392   serial,   serial,
393   vendor,   username,
394   model,   shell,
395   hsync,   vnc,
396   vrefresh   samba,
397     station
398   )   )
399   values(   values(
400   '${ALX_SERIAL}',   '${ALX_SERIAL}',
401   'Aamazing',   '${ALX_UNPRIV_USER}',
402   'CM-1528-FS',   '',
403   '28-64',   '',
404   '47-104'   '',
405   );";   ''
406     );"
407     evaluate_retval
408    
409     # exchange ssh rsa keys - the first boot needs this !
410     # or no reboot will work via the webadmin
411     echo -e "      SSH authentification settings ..."
412     HOME=/root config_ssh_auth
413     evaluate_retval
414    
415     # autostart
416     echo -e "      Autostart settings ..."
417     mysqldo "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');"
418    
419     # screensaver
420     echo -e "      Screensaver settings ..."
421     mysqldo "insert into cfg_screensaver(serial,screensaver) values('${ALX_SERIAL}','')"
422    
423     evaluate_retval
424    }
425    
426    # imports current settings to the database resolved by the hardware detection
427    update_settings_in_db()
428    {
429     # note: networking is always 'dhcp' if hw was autodetected
430     # note: default_domain/hostname is set in config.rc or exported
431     # note: we updating only hardware settings here !
432    
433     # to be safe, we do some sanity checks
434     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
435     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
436    
437     # vars used by hwdetect
438     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
439     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
440     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
441    
442     # get setting from hwdetect
443     source /etc/sysconfig/hwsetup/knoppix
444     source /etc/sysconfig/hwsetup/mouse
445    
446     echo
447     echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT}
448    
449     # network
450     echo -e "      Network settings ..."
451     if [[ ${ALX_CONFD_NETWORKING} = true ]]
452     then
453     # get settings
454     #source ${rc_base}/init.d/network &> /dev/null
455     for iface in $(onboot_interface_list ${network_settings}/net.*)
456     do
457     [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue
458     echo "WARNING: only importing settings for interface [ ${iface} ] !"
459     source ${network_settings}/net.${iface} || exit 1
460     NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)"
461    
462     mysqldo "update cfg_network set
463     hostname='${ALX_DEFAULT_HOSTNAME}',
464     module='${NETCARD_DRIVER}',
465     domain='${ALX_DEFAULT_DOMAIN}',
466     networking='${NETWORKING}',
467     netmask='${NETMASK}',
468     dns='${NAMESERVER}',
469     gateway='${GATEWAY}',
470     broadcast='${BROADCAST}',
471     ip='${IP}',
472     forcemacto='${FORCE_MAC_TO}',
473     wireless_bitrate='${WIRELESS_BITRATE}',
474     wireless_channel='${WIRELESS_CHANNEL}',
475     wireless_essid='${WIRELESS_ESSID}',
476     wireless_frequency='${WIRELESS_FREQUENCY}',
477     wireless_mode='${WIRELESS_MODE}',
478     wireless_nick='${WIRELESS_NICK}',
479     wireless_auth_mode='${WIRELESS_AUTH_MODE}',
480     wireless_key_length='${WIRELESS_KEY_LENGTH}',
481     wireless_key='${WIRELESS_KEY}',
482     wireless_key_ascii='${WIRELESS_KEY_ASCII}'
483     where serial=${ALX_SERIAL};"
484    
485     # only insert the *FIRST* iface
486     break
487     done
488     else
489     mysqldo "update cfg_network set
490     hostname='${ALX_DEFAULT_HOSTNAME}',
491     module='${NETCARD_DRIVER}',
492     domain='${ALX_DEFAULT_DOMAIN}',
493     networking='dhcp'
494     where serial=${ALX_SERIAL};"
495     fi
496     evaluate_retval
497    
498     # xserver
499     echo -e "      Graphic settings ..."
500     # xserver general
501     mysqldo "update cfg_graphic set
502     module='${XMODULE}',
503     resolution='1024x768',
504     depth='16',
505     monitorid='0'
506     where serial=${ALX_SERIAL};"
507     evaluate_retval
508    
509   # input   # input
510    mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \   echo -e "      Input settings ..."
511   "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');";)   mysqldo "update cfg_input set mouse='${XMOUSETYPE}' where serial=${ALX_SERIAL};"
512   evaluate_retval   evaluate_retval
513  }  }
514    
515  # imports current settings to the local system resolved by the hardware detection  # imports current settings to the local system resolved by the hardware detection
516  # we only need the network settings  # we only need the network settings
517  import_settings_local(){  import_settings_local()
518   #note: networking is always 'dhcp' if hw was autodetected  {
519   #note: default_domain/hostname is set in config.rc   # note: networking is always 'dhcp' if hw was autodetected
520     # note: default_domain/hostname is set in config.rc
521    
522   #to be safe, we do some sanity checks   # to be safe, we do some sanity checks
523   [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain   [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
524   [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx   [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
525    
526   #vars used by hwdetect   # vars used by hwdetect
527   local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME   local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
528   local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER   local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
529   local MOUSETYPE XMOUSETYPE FULLNAME DEVICE   local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
530    
531   #get setting from hwdetect   # get setting from hwdetect
532   source /etc/sysconfig/hwsetup/knoppix   source /etc/sysconfig/hwsetup/knoppix
533    
534   echo   echo
535   echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}   echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
536    
537   [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}   if [[ ${ALX_CONFD_NETWORKING} = false ]]
538   echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules   then
539   evaluate_retval   #[ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
540     #echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
541    
542     # set an device alias for modprobe.conf
543     [ ! -d /etc/modules.d ] && install -d /etc/modules.d
544     echo "alias eth0 ${NETCARD_DRIVER}" > /etc/modules.d/net.eth0
545    
546     # regenerate modprobe.conf
547     [ -x $(which modules-update) ] && modules-update || echo "cannot regen modprobe.conf"
548     evaluate_retval
549     fi
550    
551   #set system state to 'already configured'   # set system state to 'already configured'
552   touch /etc/alxconfig-ng/state/configured   touch /etc/alxconfig-ng/state/configured
553    
554     # if only an recheck was forced than abort now
555     [[ ${ALX_FORCED_RECHECK} = true ]] && return 0
556    
557     # create a fresh fluxbox directory
558     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
559     install -d ${ALX_UNPRIV_HOME}/.fluxbox
560    
561     # now generate fluxbox config files
562    
563     # fluxbox main config
564     cat ${ALX_SKELETONS}/fluxbox/init \
565     > ${ALX_UNPRIV_HOME}/.fluxbox/init
566    
567     # fluxbox autostart
568     cat ${ALX_SKELETONS}/fluxbox/apps \
569     > ${ALX_UNPRIV_HOME}/.fluxbox/apps
570    
571     # fluxbox menu header
572     cat ${ALX_SKELETONS}/fluxbox/menu.header \
573     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
574    
575     # now fix it with proper messages :P
576     local ver="$(< /etc/mageversion)"
577     sed -i "s:@CHANGEME@:alx-${ver}  #${ALX_SERIAL}:g" \
578     ${ALX_UNPRIV_HOME}/.fluxbox/menu
579    
580     # add a newline (maybe there is no crlf in the header)
581     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
582    
583     # fluxbox menu footer
584     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
585     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
586    
587     # add a newline (maybe there is no crlf in the footer)
588     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
589    
590    
591     # setup some standart icons (sysinfo.lnk)
592     # basic config
593     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc
594    
595     # clean desktop icon location
596     [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop
597     install -d ${ALX_UNPRIV_HOME}/.xtdesktop
598    
599     # last but not least gen a icon with some sys informations
600     local sysinfo
601     local osversion
602     local xres
603     local yres
604    
605     osversion="$(< /etc/mageversion)"
606     sysinfo="Hostname: ${ALX_DEFAULT_HOSTNAME} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
607    
608     # at first boot we got always a resolution of 1024x768-16@60
609     # middle of the screen
610     # (no txt - length required, xtdesk manage that itself)
611     xres="$((1024 / 2))"
612     # default y pos (full yres -22 !)
613     yres="$((768 - 22 ))"
614    
615     generate_icon \
616     --name "${sysinfo}" \
617     --command "exit 0" \
618     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
619     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \
620     --xres "${xres}" \
621     --yres "${yres}" \
622     --icon-width "1" \
623     --icon-height "1"
624    
625     # set correct permissions
626     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
627     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
628     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
629     chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
630     chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
631  }  }
632    
633  #start|stop  # start|stop
634  preliminary_network(){  preliminary_network()
635    {
636   local module   local module
637    
638   if [ -f /etc/alxconfig-ng/state/configured ]   if [ -f /etc/alxconfig-ng/state/configured ]
639   then   then
640   #get module name   # compat for old clients
641   module=$(cat ${SETTINGSPATH}/modules)   if [ -f ${SETTINGSPATH}/modules ]
642   modprobe ${module}   then
643     # get module name
644     module=$(cat ${SETTINGSPATH}/modules)
645     modprobe ${module}
646     fi
647   else   else
648   #vars used by hwdetect   # vars used by hwdetect
649   local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME   local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
650   local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER   local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
651    
652   #get setting from hwdetect   # get setting from hwdetect
653   source /etc/sysconfig/hwsetup/knoppix   source /etc/sysconfig/hwsetup/knoppix
654   modprobe ${NETCARD_DRIVER}   modprobe ${NETCARD_DRIVER}
655   fi   fi
# Line 417  preliminary_network(){ Line 667  preliminary_network(){
667   else   else
668   rm -f /var/run/dhcpcd-eth?.pid   rm -f /var/run/dhcpcd-eth?.pid
669   fi   fi
670     [[ ${ALX_CONFD_NETWORKING} = true ]] && [[ ${RUNLEVEL} != S ]] && \
671     ${rc_base}/init.d/network stop
672    
673   echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}   echo -e ${COLMAGENTA}"Starting preliminary networking ... "${COLDEFAULT}
  dhcpcd &> /dev/null  
674    
675   # aka_fix ########################################   # start network configured from /etc/conf.d
676   #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up   if [[ ${ALX_CONFD_NETWORKING} = true ]]
677   #route del default gw 128.20.50.13 &> /dev/null   then
678   #route add default gw 128.20.50.21 &> /dev/null   ${rc_base}/init.d/network start
679   #echo "nameserver 128.20.50.21" > /etc/resolv.conf   else
680   ##################################################   echo -e ${COLOREDSTAR}"Starting default dhcp based networking ... "${COLDEFAULT}
681     # -t 10 timeout of 10 secs
682   evaluate_retval   dhcpcd -t 10 &> /dev/null
683     evaluate_retval
684     fi
685   ;;   ;;
686    
687   stop)   stop)
688   echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}   echo -e ${COLMAGENTA}"Stopping preliminary networking ... "${COLDEFAULT}
689   ifconfig eth0 down   if [[ ${ALX_CONFD_NETWORKING} = true ]]
690     then
691     ${rc_base}/init.d/network stop
692     else
693     echo -e ${COLOREDSTAR}"Stopping default dhcp based networking ... "${COLDEFAULT}
694     ifconfig eth0 down
695     fi
696   if ps -A|grep dhcpcd > /dev/null   if ps -A|grep dhcpcd > /dev/null
697   then   then
698   dhcpcd -z  &> /dev/null   dhcpcd -z  &> /dev/null
# Line 447  preliminary_network(){ Line 706  preliminary_network(){
706   esac   esac
707  }  }
708    
709    reset_system_settings()
710    {
711     # force load of de kbdkeys
712     loadkeys -q de
713     echo
714     echo -en ${COLRED}
715     echo -n "*** Warning: you are about to reset *all* local settings on this system!"
716     echo -e ${COLDEFAULT}
717     echo "*** Do you really want to continue ?"
718     echo -n "*** Enter 'yes' to continue, anything else to abort: "
719     read kbinsert
720     if [[ ${kbinsert} = yes ]]
721     then
722     echo -en ${COLRED}
723     echo -n "*** OK, you really want it ... killing all settings: "
724     for i in 3 2 1 now
725     do
726     echo -n " ${i}"
727     sleep 1
728     done
729     echo -e ${COLDEFAULT}
730    
731     ## reset all settings:
732     rm -rf ${SETTINGSPATH}/*
733     rm -f /etc/alxconfig-ng/serial
734     rm -rf /etc/alxconfig-ng/state
735    
736     echo "I am done now, press [Enter] to reboot system ..."
737     else
738     echo "Aborted, press [Enter] to reboot system ..."
739     fi
740     read
741     reboot
742    }
743    
744    onboot_interface_list()
745    {
746     local file
747     local devices
748     local iface
749    
750     # get list of all devices
751     for file in $@
752     do
753     if [[ $(read_value ONBOOT ${file}) = yes ]]
754     then
755     iface="$(basename ${file} | sed s/net.//)"
756     # exclude backup files
757     case "${iface}" in
758     *~) ;;
759     *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;
760     esac
761     fi
762     done
763    
764     echo "${devices}"
765    }
766    
767    # read values from net.* files
768    read_value()
769    {
770     local var="$1"
771     local file="$2"
772     local value
773    
774     # local all possible vars
775     # global
776     local ONBOOT
777     local NETWORKING
778    
779     # static
780     local IP
781     local NETMASK
782     local BROADCAST
783     local NETWORKING
784     local FORCE_MAC_TO
785    
786     # dhcp
787     local DHCP_PROG
788     local DHCP_START
789     local DHCP_STOP
790    
791     # default gw
792     local GATEWAY
793     local GATEWAY_IF
794    
795     # wireless extensions
796     local WIRELESS_AP
797     local WIRELESS_AUTH_MODE
798     local WIRELESS_BITRATE
799     local WIRELESS_CHANNEL
800     local WIRELESS_DEFAULT_KEY
801     local WIRELESS_ESSID
802     local WIRELESS_FREQUENCY
803     local WIRELESS_KEY
804     local WIRELESS_KEY_ASCII
805     local WIRELESS_KEY_0
806     local WIRELESS_KEY_1
807     local WIRELESS_KEY_2
808     local WIRELESS_KEY_3
809     local WIRELESS_KEY_LENGTH
810     local WIRELESS_MODE
811     local WIRELESS_NICK
812     local WIRELESS_NWID
813     local WIRELESS_POWER
814    
815     source ${file}
816     eval value=\$$(echo ${var})
817     echo "${value}"
818    }
819    
820  case $1 in  case $1 in
821   start)   start)
822   #retrieve or validate current serial   # check for global overrides
823     [ -f ${SETTINGSPATH}/confd-networking ] && ALX_CONFD_NETWORKING=true
824     [ -f /hardware-auto-detection ] && ALX_FORCED_RECHECK=true
825     read_cmdline hardware-auto-detection && ALX_FORCED_RECHECK=true
826     read_cmdline alx-reset-settings && ALX_RESET_SETTINGS=true
827    
828     # kill all settings if requested
829     if [[ ${ALX_RESET_SETTINGS} = true ]]
830     then
831     reset_system_settings
832     fi
833    
834     # retrieve or validate current serial
835   get_system_serial   get_system_serial
836   if [ "${ALX_HW_DETECT}" == "true" ]   if [[ ${ALX_HW_DETECT} = true ]]
837   then   then
838   import_settings_to_db   if [[ ${ALX_FORCED_RECHECK} = true ]]
839     then
840     update_settings_in_db
841     else
842     import_settings_to_db
843     fi
844   import_settings_local   import_settings_local
845    
846     # here we should also exchange the ssh keys
847     # or the system cannot be rebooted after
848     # the first start via the alx-webadmin
849     config_ssh_auth
850   fi   fi
   
  #now setup system configuration  
  #alx_setup_or_whatever_it_will_be_called()  
  [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings  
851    
852   #stop at last the preliminary networking (dhcp)   # now setup system configuration
853     # alx_setup_or_whatever_it_will_be_called()
854     [[ ${ALX_HW_DETECT} = false ]] && update_system_settings
855    
856     # stop at last the preliminary networking (dhcp)
857   preliminary_network stop   preliminary_network stop
858   ;;   ;;
859    
860   stop)   stop)
861   #unset_alx_connected #--> now in alxsetstate-rc6   # unset_alx_connected #--> now in alxsetstate-rc6
862   # ! important !: del systemstate   # ! important !: del systemstate
863   [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state   [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
864   sleep 0.1   sleep 0.1
# Line 475  case $1 in Line 867  case $1 in
867   echo "Usage: $0 {start|stop} ..."   echo "Usage: $0 {start|stop} ..."
868   ;;   ;;
869  esac  esac
870    

Legend:
Removed from v.226  
changed lines
  Added in v.348