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