Magellan Linux

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

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

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

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