Magellan Linux

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

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

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

Legend:
Removed from v.275  
changed lines
  Added in v.2156