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

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