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

Legend:
Removed from v.265  
changed lines
  Added in v.3467