Magellan Linux

Annotation of /alx-src/tags/alxconf-0_6_8/init.d/alxsettings

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5588 - (hide annotations) (download)
Wed Apr 23 13:20:54 2014 UTC (10 years, 1 month ago) by niro
File size: 25396 byte(s)
tagged 'alxconf-0_6_8'
1 niro 221 #!/bin/bash
2 niro 1976 # $Id$
3 niro 221 # <niro@magellan-linux.de>
4    
5 niro 2007 #%rlevels: 7:s 0:k
6 niro 221 #%start: 41
7     #%stop: 01
8    
9     #deps
10     #%needs:
11     #%before:
12     #%after:
13    
14     # checks first if the client was already configured and if it has an valid serial
15     # if not it runs the autoconfiguration script
16     # these settings will be used for client setup
17     #
18     # if client was valid it first will check if his settings against the server
19     # if no changes are at server side they will be kept, if yes the get updated.
20     # the server settings has higher priority.
21    
22 niro 1976 source /etc/conf.d/rc
23 niro 221 source $rc_functions
24    
25 niro 282 # mysql settings
26 niro 226 source /etc/alxconfig-ng/config.rc
27 niro 282
28     # helper functions
29 niro 2778 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 niro 2786 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 niro 221
42 niro 282 # other needed vars
43 niro 221 ALX_HW_DETECT=false
44 niro 282 ALX_FORCED_RECHECK=false
45 niro 337 ALX_RESET_SETTINGS=false
46     ALX_CONFD_NETWORKING=false
47 niro 221
48 niro 282 # unset vars which may kill us
49 niro 221 unset ALX_SERIAL ALX_STATE
50    
51    
52 niro 282 # setup needed directories
53 niro 226 [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
54 niro 221
55 niro 337 update_system_settings()
56     {
57 niro 2153 rc_mecho Checking system setup ...
58 niro 221
59 niro 257 # get the modules settings
60     # ! is the first thing that must be configured !
61     config_modules
62    
63 niro 2748 # install or uninstall plugins
64     config_plugins
65    
66 niro 226 # imports network settings from db
67     config_networking
68    
69     # imports x11 settings from db
70     config_x11
71    
72 niro 248 # imports session settings from db
73 niro 239 config_sessions
74 niro 226
75     # imports printer settings from db
76     config_printing
77 niro 248
78     # imports auth settings from db
79     config_auth
80 niro 252
81     # exchange ssh rsa keys
82 niro 265 HOME=/root config_ssh_auth
83 niro 1582
84     # import version info
85     config_version
86 niro 221 }
87    
88 niro 337 get_system_serial()
89     {
90 niro 3467 # never declare ALX_IFACE as a local variable! ->fixme!
91     local CUR_IP CUR_MAC CUR_MTIME CONFIG
92 niro 221
93 niro 350 if [[ ${ALX_CONFD_NETWORKING} = true ]]
94     then
95     ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)"
96     else
97     ALX_IFACE="eth0"
98     fi
99    
100 niro 282 # check if serial file exists
101 niro 337 if [ -f /etc/alxconfig-ng/serial ] && [[ ${ALX_FORCED_RECHECK} = false ]]
102 niro 221 then
103 niro 226 source /etc/alxconfig-ng/serial
104    
105 niro 282 # start preliminary networking (dhcp)
106 niro 295 preliminary_network start
107 niro 226
108 niro 295 # check if mysql server is reachable
109     # if not abort this script
110     if ! reach_mysql_server
111     then
112     preliminary_network stop
113     exit 1
114     fi
115    
116 niro 1976 CUR_IP=$(ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
117     CUR_MAC=$(ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
118 niro 221 CUR_MTIME=$(date +%s)
119 niro 226
120 niro 2141 rc_print "Trying to validate my serial ..."
121 niro 226
122 niro 282 # nice serial output
123 niro 221 $CURS_UP
124     $SET_WCOL
125 niro 3476 rc_echo "[ SN: ${ALX_SERIAL} ]"
126 niro 221
127     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
128     then
129     ALX_STATE="ok"
130     else
131 niro 307 # abort on non valid serial
132 niro 221 ALX_STATE="invalid serial"
133 niro 3466 CONFIG="/etc/alxconfig-ng/state/state"
134     clearconfig
135     addconfig "ALX_STATE=\"${ALX_STATE}\""
136 niro 307 show_invalid_serial_msg
137     exit 1
138 niro 221 fi
139    
140     else
141 niro 282 # run hardware detection
142 niro 3476 rc_echo
143 niro 337 if [[ ${ALX_FORCED_RECHECK} = true ]]
144 niro 282 then
145 niro 2141 rc_mecho "Hardware autodetection forced by system-administrator"
146 niro 1622 # always disable CONFD_NETWORKING here
147     export ALX_CONFD_NETWORKING="false"
148 niro 282 else
149 niro 2141 rc_mecho "Preparing system for first boot"
150 niro 282 fi
151 niro 221 ALX_HW_DETECT=true
152 niro 2009 hwsetup
153 niro 226
154 niro 282 # set hostname to alx_default_hostname
155     # use old hostname if this is a forced re-check
156 niro 337 [[ ${ALX_FORCED_RECHECK} = true ]] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)"
157 niro 221 [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
158     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
159 niro 226
160 niro 282 # update the hostname on the system for sure
161 niro 3466 CONFIG="/etc/hostname"
162     clearconfig
163     addconfig "${HOSTNAME}"
164 niro 226
165 niro 282 # start preliminary networking (dhcp)
166 niro 221 preliminary_network start
167 niro 226
168 niro 295 # check if mysql server is reachable
169     # if not abort this script
170     if ! reach_mysql_server
171     then
172     preliminary_network stop
173     exit 1
174     fi
175    
176 niro 2509 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 niro 221 CUR_MTIME=$(date +%s)
179 niro 226
180 niro 282 # abort now if this is a forced re-check
181 niro 337 if [[ ${ALX_FORCED_RECHECK} = true ]]
182 niro 282 then
183     # but first check the serial
184     source /etc/alxconfig-ng/serial
185    
186 niro 2141 rc_print "Trying to validate my serial ..."
187 niro 282
188     # nice serial output
189     $CURS_UP
190     $SET_WCOL
191 niro 3476 rc_echo "[ SN: ${ALX_SERIAL} ]"
192 niro 282
193     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
194     then
195     ALX_STATE="ok"
196     else
197 niro 307 # abort on non valid serial
198 niro 282 ALX_STATE="invalid serial"
199 niro 3466 CONFIG="/etc/alxconfig-ng/state/state"
200     clearconfig
201     addconfig "ALX_STATE=\"${ALX_STATE}\""
202 niro 307 show_invalid_serial_msg
203     exit 1
204 niro 282 fi
205    
206     # write current state to temp file
207 niro 3466 CONFIG="/etc/alxconfig-ng/state/state"
208     clearconfig
209     addconfig "ALX_STATE=\"${ALX_STATE}\""
210 niro 337 [ -f /hardware-auto-detection ] && rm /hardware-auto-detection
211 niro 282
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 niro 2141 rc_print "Trying to get new serial ..."
219 niro 226
220 niro 313 # request a new serial; one command now (cause must be done in the same session)
221 niro 348 ALX_SERIAL=$(mysqldo "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}');
222 niro 314 select last_insert_id();")
223 niro 221
224 niro 337 if [[ ${ALX_SERIAL} != NULL ]]
225 niro 221 then
226 niro 282 # nice serial output
227 niro 221 $CURS_UP
228     $SET_WCOL
229 niro 3476 rc_echo "[ SN: ${ALX_SERIAL} ]"
230 niro 226
231 niro 348 # set ALX_STATE to ok so everybody knows that everything was ok
232 niro 221 ALX_STATE=ok
233 niro 226
234 niro 3466 CONFIG="/etc/alxconfig-ng/serial"
235     clearconfig
236     addconfig "ALX_SERIAL=\"${ALX_SERIAL}\""
237     addconfig "ALX_REG_DATE=\"${CUR_MTIME}\""
238 niro 226
239 niro 221 evaluate_retval
240     else
241 niro 282 # print false (works only if this is the first statement here)
242 niro 221 evaluate_retval
243 niro 226
244 niro 282 # set ALX_STATE to error so everybody sees there was an error
245 niro 221 ALX_STATE=error
246 niro 226
247 niro 282 # show an error that no new serial was found
248     # nice serial output
249 niro 221 $CURS_UP
250     $SET_WCOL
251 niro 3476 rc_echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
252 niro 221 fi
253     fi
254 niro 226
255 niro 282 # write current state to temp file
256 niro 3466 CONFIG="/etc/alxconfig-ng/state/state"
257     clearconfig
258     addconfig "ALX_STATE=\"${ALX_STATE}\""
259     addconfig "ALX_IFACE=\"${ALX_IFACE}\""
260 niro 221 }
261    
262    
263 niro 337 check_is_configured()
264     {
265 niro 226 if [ -f /etc/alxconfig-ng/state/configured ]
266 niro 221 then
267     export ALX_CONFIGURED=true
268     else
269     export ALX_CONFIGURED=false
270     fi
271     }
272    
273    
274     # imports current settings to the database resolved by the hardware detection
275 niro 337 import_settings_to_db()
276     {
277 niro 282 # note: networking is always 'dhcp' if hw was autodetected
278     # note: default_domain/hostname is set in config.rc
279 niro 229
280 niro 282 # to be safe, we do some sanity checks
281 niro 221 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
282     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
283 niro 229
284 niro 2009 # vars used by hwsetup
285 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
286     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
287     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
288 niro 229
289 niro 2009 # get setting from hwsetup
290 niro 2008 source /etc/conf.d/hwsetup/knoppix
291     source /etc/conf.d/hwsetup/mouse
292 niro 229
293 niro 3476 rc_echo
294 niro 2141 rc_mecho "Importing detected settings to database"
295 niro 229
296 niro 282 # network
297 niro 2141 rc_mecho " Network settings ..."
298 niro 337 if [[ ${ALX_CONFD_NETWORKING} = true ]]
299     then
300     # get settings
301     for iface in $(onboot_interface_list ${network_settings}/net.*)
302     do
303     [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue
304 niro 2141 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 niro 2122 NETCARD_DRIVER="$(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f3)"
307 niro 337
308 niro 348 mysqldo "insert into cfg_network(
309 niro 337 hostname,
310     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 niro 348 mysqldo "insert into cfg_network(
360 niro 337 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 niro 221 evaluate_retval
375 niro 229
376 niro 282 # xserver
377 niro 2141 rc_mecho " Graphic settings ..."
378 niro 282 # xserver general
379 niro 348 ( mysqldo "insert into cfg_graphic(
380 niro 221 serial,
381     module,
382     resolution,
383 niro 229 depth,
384 niro 1582 refresh_rate
385 niro 221 )
386     values(
387     '${ALX_SERIAL}',
388     '${XMODULE}',
389     '1024x768',
390 niro 229 '16',
391 niro 1582 '60'
392 niro 252 );"; )
393     evaluate_retval
394 niro 229
395 niro 221 # input
396 niro 2141 rc_mecho " Input settings ..."
397 niro 348 mysqldo "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');"
398 niro 221 evaluate_retval
399 niro 252
400     # auth
401 niro 2141 rc_mecho " Authentification settings ..."
402 niro 348 mysqldo "insert into client_auth(
403 niro 252 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 niro 263 # exchange ssh rsa keys - the first boot needs this !
421     # or no reboot will work via the webadmin
422 niro 2141 rc_mecho " SSH authentification settings ..."
423 niro 264 HOME=/root config_ssh_auth
424 niro 263 evaluate_retval
425    
426 niro 348 # autostart
427 niro 2141 rc_mecho " Autostart settings ..."
428 niro 348 mysqldo "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');"
429    
430     # screensaver
431 niro 2141 rc_mecho " Screensaver settings ..."
432 niro 348 mysqldo "insert into cfg_screensaver(serial,screensaver) values('${ALX_SERIAL}','')"
433    
434 niro 1582 # version info
435 niro 2141 rc_mecho " OS version info ..."
436 niro 1582 local alx_os
437     local alx_utils
438     alx_os="$(< /etc/mageversion)"
439 niro 2568 alx_utils="$(magequery -n alxconfig-ng | sed 's:.*\[\ \(.*\)\ \].*:\1:')"
440     alx_utils="${alx_utils/alxconfig-ng-}"
441 niro 1582 mysqldo "insert into client_version(serial,os,utils) values('${ALX_SERIAL}','${alx_os}','${alx_utils}')"
442    
443 niro 252 evaluate_retval
444 niro 221 }
445    
446 niro 282 # imports current settings to the database resolved by the hardware detection
447 niro 337 update_settings_in_db()
448     {
449 niro 282 # 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 niro 2009 # vars used by hwsetup
458 niro 282 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 niro 2009 # get setting from hwsetup
463 niro 2008 source /etc/conf.d/hwsetup/knoppix
464     source /etc/conf.d/hwsetup/mouse
465 niro 282
466 niro 3476 rc_echo
467 niro 2141 rc_mecho "Updating detected settings in database"
468 niro 282
469     # network
470 niro 2141 rc_mecho " Network settings ..."
471 niro 337 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 niro 2141 rc_echo "WARNING: only importing settings for interface [ ${iface} ] !"
479 niro 337 source ${network_settings}/net.${iface} || exit 1
480 niro 2122 NETCARD_DRIVER="$(cat /etc/modprobe.d/net.${iface}.conf | cut -d' ' -f3)"
481 niro 282
482 niro 348 mysqldo "update cfg_network set
483 niro 337 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 niro 348 mysqldo "update cfg_network set
510 niro 337 hostname='${ALX_DEFAULT_HOSTNAME}',
511     module='${NETCARD_DRIVER}',
512     domain='${ALX_DEFAULT_DOMAIN}',
513     networking='dhcp'
514     where serial=${ALX_SERIAL};"
515     fi
516 niro 282 evaluate_retval
517    
518     # xserver
519 niro 2141 rc_mecho " Graphic settings ..."
520 niro 282 # xserver general
521 niro 348 mysqldo "update cfg_graphic set
522 niro 282 module='${XMODULE}',
523     resolution='1024x768',
524     depth='16',
525 niro 1582 refresh_rate='60'
526 niro 282 where serial=${ALX_SERIAL};"
527     evaluate_retval
528    
529     # input
530 niro 2141 rc_mecho " Input settings ..."
531 niro 348 mysqldo "update cfg_input set mouse='${XMOUSETYPE}' where serial=${ALX_SERIAL};"
532 niro 282 evaluate_retval
533 niro 1582
534     # version info
535 niro 2141 rc_mecho " OS version info ..."
536 niro 1582 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 niro 282 }
543    
544 niro 221 # imports current settings to the local system resolved by the hardware detection
545 niro 337 # we only need the network settings
546     import_settings_local()
547     {
548 niro 282 # note: networking is always 'dhcp' if hw was autodetected
549     # note: default_domain/hostname is set in config.rc
550 niro 226
551 niro 282 # to be safe, we do some sanity checks
552 niro 221 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
553     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
554 niro 226
555 niro 2009 # vars used by hwsetup
556 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
557     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
558     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
559    
560 niro 2009 # get setting from hwsetup
561 niro 2008 source /etc/conf.d/hwsetup/knoppix
562 niro 226
563 niro 3476 rc_echo
564 niro 2141 rc_mecho "Importing detected settings to local system"
565 niro 221
566 niro 337 if [[ ${ALX_CONFD_NETWORKING} = false ]]
567     then
568 niro 2039 # set an device alias for modprobe.conf
569 niro 1622 [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d
570 niro 2509 # 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 niro 337
575 niro 2509 # update confd-networking default iface
576     [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
577     CONFIG="${SETTINGSPATH}/confd-networking"
578     clearconfig
579     addconfig "${ALX_IFACE}"
580    
581 niro 337 # regenerate modprobe.conf
582 niro 2141 [ -x $(which modules-update) ] && modules-update || rc_echo "modules-update not found!"
583 niro 337 evaluate_retval
584 niro 4834
585     # restore default networking if hardware-detection was called by administrator and iface config is empty
586     if [[ ${ALX_FORCED_RECHECK} = true ]] && [ ! -s /etc/conf.d/net.${ALX_IFACE} ] && [ -f ${SETTINGSPATH}/confd-networking ]
587     then
588     rc_echo " Network config is empty, using default skeleton"
589     cat ${ALX_SKELETONS}/net/net.eth0 > /etc/conf.d/net.${ALX_IFACE}
590     fi
591 niro 337 fi
592    
593 niro 282 # set system state to 'already configured'
594 niro 226 touch /etc/alxconfig-ng/state/configured
595 niro 252
596 niro 1715 # install slim desktopmanager configuration
597 niro 1718 config_display_manager
598 niro 1715
599 niro 313 # if only an recheck was forced than abort now
600     [[ ${ALX_FORCED_RECHECK} = true ]] && return 0
601    
602 niro 275 # create a fresh fluxbox directory
603     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
604     install -d ${ALX_UNPRIV_HOME}/.fluxbox
605    
606     # now generate fluxbox config files
607    
608     # fluxbox main config
609 niro 2470 local fbinit
610     if [ -f ${ALX_SKELETONS}/fluxbox/init ]
611     then
612     fbinit="${ALX_SKELETONS}/fluxbox/init"
613     else
614     fbinit="/usr/share/fluxbox/init"
615     fi
616     cat ${fbinit} > ${ALX_UNPRIV_HOME}/.fluxbox/init
617 niro 275
618 niro 319 # fluxbox autostart
619 niro 2470 CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps"
620     # do not show decorations on messages generated with xmessage
621     if [ -x /usr/bin/xmessage ]
622     then
623     addconfig '[app] (xmessage)'
624     addconfig ' [Deco] {NONE}'
625     addconfig '[end]'
626     fi
627     # add icon utility
628     [ -x /usr/bin/idesk ] && addconfig '[startup] {nohup idesk > /dev/null &}'
629     # add numlock utility
630     [ -x /usr/bin/numlockx ] && addconfig '[startup] {nohup numlockx on &}'
631 niro 319
632 niro 2470 # fluxbox hotkeys
633     local fbkeys
634     if [ -f ${ALX_SKELETONS}/fluxbox/keys ]
635     then
636     fbkeys="${ALX_SKELETONS}/fluxbox/keys"
637     else
638     fbkeys="/usr/share/fluxbox/keys"
639     fi
640     cat ${fbkeys} > ${ALX_UNPRIV_HOME}/.fluxbox/keys
641    
642 niro 275 # fluxbox menu header
643 niro 2039 cat ${ALX_SKELETONS}/fluxbox/menu.header > ${ALX_UNPRIV_HOME}/.fluxbox/menu
644 niro 275
645 niro 297 # now fix it with proper messages :P
646     local ver="$(< /etc/mageversion)"
647 niro 2039 sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu
648 niro 297
649 niro 275 # add a newline (maybe there is no crlf in the header)
650     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
651    
652     # fluxbox menu footer
653 niro 2039 cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
654 niro 275
655     # add a newline (maybe there is no crlf in the footer)
656     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
657    
658 niro 313 # setup some standart icons (sysinfo.lnk)
659     # clean desktop icon location
660 niro 2455 [ -d ${ALX_UNPRIV_HOME}/.idesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.idesktop
661     install -d ${ALX_UNPRIV_HOME}/.idesktop
662 niro 313
663 niro 2471 # add shutdown, reboot icons
664     local name
665     # default settings
666     declare -i x=30
667     declare -i y=30
668     for i in shutdown reboot
669     do
670     case ${i} in
671 niro 2479 shutdown) name="Herunterfahren" ;;
672     reboot) name="Neustarten" ;;
673 niro 2471 esac
674    
675     generate_icon \
676     --name "${name}" \
677     --command "/usr/lib/alxconfig-ng/bin/user_${i}.sh" \
678     --icon "${ALX_SESSIONS_ICONS}/${i}.png" \
679     --dest "${dest}/${i}.lnk" \
680     --xres "${x}" \
681     --yres "${y}"
682    
683     y=$((${y} + 80))
684     done
685    
686 niro 313 # last but not least gen a icon with some sys informations
687     local sysinfo
688     local osversion
689     local xres
690     local yres
691    
692     osversion="$(< /etc/mageversion)"
693     sysinfo="Hostname: ${ALX_DEFAULT_HOSTNAME} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
694    
695     # at first boot we got always a resolution of 1024x768-16@60
696     # middle of the screen
697     # (no txt - length required, xtdesk manage that itself)
698     xres="$((1024 / 2))"
699     # default y pos (full yres -22 !)
700     yres="$((768 - 22 ))"
701    
702     generate_icon \
703     --name "${sysinfo}" \
704     --command "exit 0" \
705     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
706 niro 2455 --dest "${ALX_UNPRIV_HOME}/.idesktop/sysinfo.lnk" \
707 niro 313 --xres "${xres}" \
708     --yres "${yres}" \
709     --icon-width "1" \
710     --icon-height "1"
711    
712 niro 282 # set correct permissions
713     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
714     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
715     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
716 niro 2455 chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop
717 niro 2470 if [ -f ${ALX_UNPRIV_HOME}/.ideskrc ]
718     then
719     chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc
720     fi
721 niro 221 }
722    
723 niro 282 # start|stop
724 niro 337 preliminary_network()
725     {
726 niro 221 local module
727 niro 226
728     if [ -f /etc/alxconfig-ng/state/configured ]
729 niro 221 then
730 niro 337 # compat for old clients
731     if [ -f ${SETTINGSPATH}/modules ]
732     then
733     # get module name
734     module=$(cat ${SETTINGSPATH}/modules)
735     modprobe ${module}
736     fi
737 niro 1976
738 niro 221 else
739 niro 2009 # vars used by hwsetup
740 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
741     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
742 niro 226
743 niro 2009 # get setting from hwsetup
744 niro 2008 source /etc/conf.d/hwsetup/knoppix
745 niro 221 modprobe ${NETCARD_DRIVER}
746     fi
747 niro 226
748 niro 221 case $1 in
749     start)
750     # keeping like always safe:
751     # no network should be startet here,
752     # so we can delete all pid files if one exists
753 niro 2156 if [[ ! -z $(pidof $(basename ${ALX_DHCP_PROG})) ]]
754 niro 221 then
755 niro 2141 rc_mecho "Forcing network down"
756 niro 2156 killall $(basename ${ALX_DHCP_PROG}) &> /dev/null
757 niro 221 sleep 1
758     fi
759 niro 2039 [[ ${ALX_CONFD_NETWORKING} = true ]] && ${rc_base}/init.d/network stop
760 niro 226
761 niro 2141 rc_mecho "Starting preliminary networking ... "
762 niro 226
763 niro 337 # start network configured from /etc/conf.d
764     if [[ ${ALX_CONFD_NETWORKING} = true ]]
765     then
766     ${rc_base}/init.d/network start
767     else
768 niro 2141 rc_print "Starting default dhcp based networking ... "
769 niro 2509 ${ALX_DHCP_PROG} ${ALX_DHCP_START} ${ALX_IFACE} &> /dev/null
770 niro 337 evaluate_retval
771     fi
772 niro 221 ;;
773 niro 226
774 niro 221 stop)
775 niro 2141 rc_mecho "Stopping preliminary networking ... "
776 niro 337 if [[ ${ALX_CONFD_NETWORKING} = true ]]
777     then
778     ${rc_base}/init.d/network stop
779     else
780 niro 2141 rc_print "Stopping default dhcp based networking ... "
781 niro 2156 ifconfig ${ALX_IFACE} down
782 niro 337 fi
783 niro 2156 if [[ ! -z $(pidof $(basename ${ALX_DHCP_PROG})) ]]
784 niro 221 then
785 niro 2156 killall $(basename ${ALX_DHCP_PROG}) &> /dev/null
786 niro 1596 sleep 1
787 niro 221 fi
788     evaluate_retval
789     ;;
790 niro 226
791 niro 221 *)
792 niro 3476 rc_echo "Usage: preliminary_network {start|stop}"
793 niro 221 ;;
794     esac
795     }
796    
797 niro 337 reset_system_settings()
798     {
799     # force load of de kbdkeys
800 niro 3457 [ -x /usr/bin/loadkeys ] && loadkeys -q de
801     [ -x /sbin/loadkmap ] && loadkmap < /usr/share/busybox/keymaps/de.kmap
802 niro 2141 rc_echo
803 niro 3458 rc_echo -en "${COLRED}"
804     rc_echo -n '--- Warning: you are about to reset *all* local settings on this system!'
805     rc_echo -e "${COLDEFAULT}"
806     rc_echo '--- Do you really want to continue ?'
807     rc_echo -n '--- Enter 'yes' to continue, anything else to abort: '
808 niro 337 read kbinsert
809     if [[ ${kbinsert} = yes ]]
810     then
811 niro 3458 rc_echo -en "${COLRED}"
812     rc_echo -n '--- OK, you really want it ... killing all settings: '
813 niro 337 for i in 3 2 1 now
814     do
815 niro 2141 rc_echo -n " ${i}"
816 niro 337 sleep 1
817     done
818 niro 3458 rc_echo -e "${COLDEFAULT}"
819 niro 337
820     ## reset all settings:
821 niro 3459 rm -rf ${SETTINGSPATH}
822 niro 337 rm -f /etc/alxconfig-ng/serial
823     rm -rf /etc/alxconfig-ng/state
824 niro 3464 local i
825     for i in xserver netcard knoppix mouse
826     do
827     [[ -f /etc/conf.d/hwsetup/${i} ]] && rm /etc/conf.d/hwsetup/${i}
828     done
829 niro 337
830 niro 357 # clear all printers & net-shares
831 niro 2122 :> /etc/printcap
832 niro 357
833 niro 2122 # remove lprng
834     rc-config del lprng &> /dev/null
835 niro 3460 rc-config del nmbd &> /dev/null
836 niro 357
837     # remove all user settings
838     [ -d ${ALX_UNPRIV_HOME} ] && rm -rf ${ALX_UNPRIV_HOME}
839 niro 3461 install -o ${ALX_UNPRIV_USER} -g ${ALX_UNPRIV_GROUP} -d ${ALX_UNPRIV_HOME}
840 niro 357
841     # remove all ica-sessions
842 niro 3456 find ${ALX_ICA_SESSIONS} -type f -name '*.ica' | xargs --no-run-if-empty rm
843 niro 357
844     # remove all old nics and modules configs
845 niro 3456 find /etc/conf.d -type f -name 'net.*' | xargs --no-run-if-empty rm
846     find /etc/modprobe.d -type f -name 'net.*' | xargs --no-run-if-empty rm
847 niro 357
848     # restore default networking
849     cat ${ALX_SKELETONS}/net/net.eth0 > /etc/conf.d/net.eth0
850 niro 3466 local CONFIG="/etc/hostname"
851     clearconfig
852     addconfig "${ALX_DEFAULT_HOSTNAME}"
853 niro 357
854 niro 3463 rc_echo -n "I am done now, press [Enter] to reboot system ..."
855 niro 348 else
856 niro 3463 rc_echo -n "Aborted, press [Enter] to reboot system ..."
857 niro 337 fi
858 niro 348 read
859 niro 3465 sync
860     mount -oremount,ro /
861     reboot -f
862 niro 337 }
863    
864     onboot_interface_list()
865     {
866     local file
867     local devices
868     local iface
869    
870     # get list of all devices
871     for file in $@
872     do
873     if [[ $(read_value ONBOOT ${file}) = yes ]]
874     then
875     iface="$(basename ${file} | sed s/net.//)"
876     # exclude backup files
877     case "${iface}" in
878     *~) ;;
879     *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;
880     esac
881     fi
882     done
883    
884     echo "${devices}"
885     }
886    
887 niro 348 # read values from net.* files
888 niro 337 read_value()
889     {
890     local var="$1"
891     local file="$2"
892     local value
893    
894     # local all possible vars
895     # global
896     local ONBOOT
897     local NETWORKING
898    
899     # static
900     local IP
901     local NETMASK
902     local BROADCAST
903     local NETWORKING
904     local FORCE_MAC_TO
905    
906     # dhcp
907     local DHCP_PROG
908     local DHCP_START
909     local DHCP_STOP
910    
911     # default gw
912     local GATEWAY
913     local GATEWAY_IF
914    
915     # wireless extensions
916     local WIRELESS_AP
917     local WIRELESS_AUTH_MODE
918     local WIRELESS_BITRATE
919     local WIRELESS_CHANNEL
920     local WIRELESS_DEFAULT_KEY
921     local WIRELESS_ESSID
922     local WIRELESS_FREQUENCY
923     local WIRELESS_KEY
924     local WIRELESS_KEY_ASCII
925     local WIRELESS_KEY_0
926     local WIRELESS_KEY_1
927     local WIRELESS_KEY_2
928     local WIRELESS_KEY_3
929     local WIRELESS_KEY_LENGTH
930     local WIRELESS_MODE
931     local WIRELESS_NICK
932     local WIRELESS_NWID
933     local WIRELESS_POWER
934    
935     source ${file}
936     eval value=\$$(echo ${var})
937     echo "${value}"
938     }
939    
940 niro 221 case $1 in
941     start)
942 niro 337 # check for global overrides
943     [ -f ${SETTINGSPATH}/confd-networking ] && ALX_CONFD_NETWORKING=true
944     [ -f /hardware-auto-detection ] && ALX_FORCED_RECHECK=true
945     read_cmdline hardware-auto-detection && ALX_FORCED_RECHECK=true
946     read_cmdline alx-reset-settings && ALX_RESET_SETTINGS=true
947    
948     # kill all settings if requested
949     if [[ ${ALX_RESET_SETTINGS} = true ]]
950     then
951     reset_system_settings
952     fi
953    
954 niro 282 # retrieve or validate current serial
955 niro 221 get_system_serial
956 niro 282 if [[ ${ALX_HW_DETECT} = true ]]
957 niro 221 then
958 niro 282 if [[ ${ALX_FORCED_RECHECK} = true ]]
959     then
960     update_settings_in_db
961     else
962     import_settings_to_db
963     fi
964 niro 221 import_settings_local
965 niro 252
966     # here we should also exchange the ssh keys
967     # or the system cannot be rebooted after
968     # the first start via the alx-webadmin
969     config_ssh_auth
970 niro 221 fi
971 niro 252
972 niro 282 # now setup system configuration
973     # alx_setup_or_whatever_it_will_be_called()
974 niro 348 [[ ${ALX_HW_DETECT} = false ]] && update_system_settings
975 niro 221
976 niro 282 # stop at last the preliminary networking (dhcp)
977 niro 221 preliminary_network stop
978     ;;
979 niro 282
980 niro 221 stop)
981 niro 282 # unset_alx_connected #--> now in alxsetstate-rc6
982 niro 221 # ! important !: del systemstate
983 niro 226 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
984 niro 221 sleep 0.1
985     ;;
986 niro 2039
987 niro 221 *)
988 niro 3476 rc_echo "Usage: $0 {start|stop} ..."
989 niro 221 ;;
990     esac

Properties

Name Value
svn:executable *