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

Legend:
Removed from v.230  
changed lines
  Added in v.1596