Contents of /alx-src/trunk/tinyalxconfig-ng/init.d/alxsettings
Parent Directory | Revision Log
Revision 537 -
(show annotations)
(download)
Mon Jan 26 17:16:32 2009 UTC (15 years, 8 months ago) by niro
File size: 14064 byte(s)
Mon Jan 26 17:16:32 2009 UTC (15 years, 8 months ago) by niro
File size: 14064 byte(s)
-fixed header
1 | #!/bin/bash |
2 | |
3 | # <niro@magellan-linux.de> |
4 | |
5 | #%rlevels: 7:s 0:k |
6 | #%start: 41 |
7 | #%stop: 01 |
8 | |
9 | #deps |
10 | #%needs: |
11 | #%before: |
12 | #%after: |
13 | |
14 | # $Id$ |
15 | |
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/conf.d/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_driverkits |
34 | source /usr/lib/alxconfig-ng/functions/config_modules |
35 | source /usr/lib/alxconfig-ng/functions/config_network |
36 | source /usr/lib/alxconfig-ng/functions/config_printers |
37 | source /usr/lib/alxconfig-ng/functions/config_sessions |
38 | source /usr/lib/alxconfig-ng/functions/config_x11 |
39 | source /usr/lib/alxconfig-ng/functions/config_auth |
40 | source /usr/lib/alxconfig-ng/functions/config_ssh_auth |
41 | |
42 | # other needed vars |
43 | ALX_HW_DETECT=false |
44 | ALX_FORCED_RECHECK=false |
45 | ALX_RESET_SETTINGS=false |
46 | |
47 | # unset vars which may kill us |
48 | unset ALX_SERIAL ALX_STATE |
49 | |
50 | |
51 | # setup needed directories |
52 | [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state |
53 | |
54 | |
55 | # read_cmdline ${item} |
56 | read_cmdline() |
57 | { |
58 | local i |
59 | |
60 | for i in $(< /proc/cmdline) |
61 | do |
62 | [[ ${i} = $1 ]] && return 0 |
63 | done |
64 | |
65 | return 1 |
66 | } |
67 | |
68 | update_system_settings() |
69 | { |
70 | echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} |
71 | |
72 | # install neccessary driverkits |
73 | config_driverkits |
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 | # check if serial file exists |
103 | if [ -f /etc/alxconfig-ng/serial ] && [[ ${ALX_FORCED_RECHECK} = false ]] |
104 | then |
105 | source /etc/alxconfig-ng/serial |
106 | |
107 | # start preliminary networking (dhcp) |
108 | preliminary_network start |
109 | |
110 | # check if mysql server is reachable |
111 | # if not abort this script |
112 | if ! reach_mysql_server |
113 | then |
114 | preliminary_network stop |
115 | exit 1 |
116 | fi |
117 | |
118 | CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp') |
119 | CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11) |
120 | CUR_MTIME=$(date +%s) |
121 | |
122 | echo -e ${COLOREDSTAR} "Trying to validate my serial ..." |
123 | |
124 | # nice serial output |
125 | $CURS_UP |
126 | $SET_WCOL |
127 | echo "[ SN: ${ALX_SERIAL} ]" |
128 | |
129 | if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" |
130 | then |
131 | ALX_STATE="ok" |
132 | else |
133 | # abort on non valid serial |
134 | ALX_STATE="invalid serial" |
135 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
136 | show_invalid_serial_msg |
137 | exit 1 |
138 | fi |
139 | |
140 | else |
141 | # run hardware detection |
142 | echo |
143 | if [[ ${ALX_FORCED_RECHECK} = true ]] |
144 | then |
145 | echo -e ${COLMAGENTA}"Hardware autodetection forced by system-administrator"${COLDEFAULT} |
146 | else |
147 | echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT} |
148 | fi |
149 | # cleaning up old data-crap |
150 | if [ -d /etc/sysconfig/hwsetup ] |
151 | then |
152 | echo -e ${COLOREDSTAR}"Cleaning up old data ..." |
153 | rm -f /etc/sysconfig/hwsetup/* |
154 | fi |
155 | ALX_HW_DETECT=true |
156 | echo -en "${COLOREDSTAR}";hwsetup -p > /dev/null |
157 | |
158 | # set hostname to alx_default_hostname |
159 | # use old hostname if this is a forced re-check |
160 | [[ ${ALX_FORCED_RECHECK} = true ]] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)" |
161 | [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx |
162 | HOSTNAME="${ALX_DEFAULT_HOSTNAME}" |
163 | |
164 | # update the hostname on the system for sure |
165 | echo "${HOSTNAME}" > /etc/hostname |
166 | |
167 | # start preliminary networking (dhcp) |
168 | preliminary_network start |
169 | |
170 | # check if mysql server is reachable |
171 | # if not abort this script |
172 | if ! reach_mysql_server |
173 | then |
174 | preliminary_network stop |
175 | exit 1 |
176 | fi |
177 | |
178 | CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') |
179 | CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) |
180 | CUR_MTIME=$(date +%s) |
181 | |
182 | # abort now if this is a forced re-check |
183 | if [[ ${ALX_FORCED_RECHECK} = true ]] |
184 | then |
185 | # but first check the serial |
186 | source /etc/alxconfig-ng/serial |
187 | |
188 | echo -e ${COLOREDSTAR} "Trying to validate my serial ..." |
189 | |
190 | # nice serial output |
191 | $CURS_UP |
192 | $SET_WCOL |
193 | echo "[ SN: ${ALX_SERIAL} ]" |
194 | |
195 | if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" |
196 | then |
197 | ALX_STATE="ok" |
198 | else |
199 | # abort on non valid serial |
200 | ALX_STATE="invalid serial" |
201 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
202 | show_invalid_serial_msg |
203 | exit 1 |
204 | fi |
205 | |
206 | # write current state to temp file |
207 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
208 | [ -f /hardware-auto-detection ] && rm /hardware-auto-detection |
209 | |
210 | # now export ALX_FORCED_RECHECK=true |
211 | # that the setting will be updated not inserted ! |
212 | export ALX_FORCED_RECHECK=true |
213 | return 0 |
214 | fi |
215 | |
216 | echo -e ${COLOREDSTAR} "Trying to get new serial ..." |
217 | |
218 | # request a new serial; one command now (cause must be done in the same session) |
219 | ALX_SERIAL=$(mysqldo "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}'); |
220 | select last_insert_id();") |
221 | |
222 | if [[ ${ALX_SERIAL} != NULL ]] |
223 | then |
224 | # nice serial output |
225 | $CURS_UP |
226 | $SET_WCOL |
227 | echo "[ SN: ${ALX_SERIAL} ]" |
228 | |
229 | # set ALX_STATE to ok so everybody knows that everything was ok |
230 | ALX_STATE=ok |
231 | |
232 | echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial |
233 | echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial |
234 | |
235 | evaluate_retval |
236 | else |
237 | # print false (works only if this is the first statement here) |
238 | evaluate_retval |
239 | |
240 | # set ALX_STATE to error so everybody sees there was an error |
241 | ALX_STATE=error |
242 | |
243 | # show an error that no new serial was found |
244 | # nice serial output |
245 | $CURS_UP |
246 | $SET_WCOL |
247 | echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]" |
248 | fi |
249 | fi |
250 | |
251 | # write current state to temp file |
252 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
253 | echo "ALX_IFACE=${ALX_IFACE}" >> /etc/alxconfig-ng/state/state |
254 | } |
255 | |
256 | # imports current settings to the database resolved by the hardware detection |
257 | import_settings_to_db() |
258 | { |
259 | # note: networking is always 'dhcp' if hw was autodetected |
260 | # note: default_domain/hostname is set in config.rc |
261 | |
262 | # to be safe, we do some sanity checks |
263 | [[ -z ${ALX_DEFAULT_DOMAIN} ]] && ALX_DEFAULT_DOMAIN=localdomain |
264 | [[ -z ${ALX_DEFAULT_HOSTNAME} ]] && ALX_DEFAULT_HOSTNAME=magellan-alx |
265 | |
266 | # vars used by hwdetect |
267 | local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME |
268 | local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER |
269 | local MOUSETYPE XMOUSETYPE FULLNAME DEVICE |
270 | |
271 | # get setting from hwdetect |
272 | source /etc/sysconfig/hwsetup/knoppix |
273 | source /etc/sysconfig/hwsetup/mouse |
274 | |
275 | echo |
276 | echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT} |
277 | |
278 | # network |
279 | echo " Network settings ..." |
280 | # global settings |
281 | mysqldo "insert into cfg_network(serial, hostname, domain ) |
282 | values('${ALX_SERIAL}', '${ALX_DEFAULT_HOSTNAME}','${ALX_DEFAULT_DOMAIN}');" |
283 | |
284 | # let udev decide which module should be loaded |
285 | # get all devices from sysfs |
286 | local i |
287 | local iface |
288 | for i in /sys/class/net/eth? |
289 | do |
290 | iface=$(basename ${i}) |
291 | NETCARD_DRIVER=$(source /sys/class/net/${iface}/uevent; echo ${PHYSDEVDRIVER}) |
292 | mysqldo "insert into cfg_interfaces( |
293 | serial, |
294 | iface, |
295 | module, |
296 | networking |
297 | ) |
298 | values( |
299 | '${ALX_SERIAL}', |
300 | '${iface}', |
301 | '${NETCARD_DRIVER}', |
302 | 'dhcp' |
303 | );" |
304 | done |
305 | evaluate_retval |
306 | |
307 | # xserver |
308 | echo " Graphic settings ..." |
309 | # xserver general |
310 | ( mysqldo "insert into cfg_graphic( |
311 | serial, |
312 | module, |
313 | resolution, |
314 | depth, |
315 | monitorid |
316 | ) |
317 | values( |
318 | '${ALX_SERIAL}', |
319 | '${XMODULE}', |
320 | '1024x768', |
321 | '16', |
322 | '0' |
323 | );"; ) |
324 | evaluate_retval |
325 | |
326 | # input |
327 | echo " Input settings ..." |
328 | mysqldo "insert into cfg_input(serial,mouse,keyboard) values('${ALX_SERIAL}','${XMOUSETYPE}','kbd');" |
329 | evaluate_retval |
330 | |
331 | # auth |
332 | echo " Authentification settings ..." |
333 | mysqldo "insert into client_auth( |
334 | serial, |
335 | username, |
336 | shell, |
337 | vnc, |
338 | samba, |
339 | station |
340 | ) |
341 | values( |
342 | '${ALX_SERIAL}', |
343 | '${ALX_UNPRIV_USER}', |
344 | '', |
345 | '', |
346 | '', |
347 | '' |
348 | );" |
349 | evaluate_retval |
350 | |
351 | # exchange ssh rsa keys - the first boot needs this ! |
352 | # or no reboot will work via the webadmin |
353 | echo " SSH authentification settings ..." |
354 | HOME=/root config_ssh_auth |
355 | evaluate_retval |
356 | |
357 | # autostart |
358 | echo " Autostart settings ..." |
359 | mysqldo "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');" |
360 | |
361 | # screensaver |
362 | echo " Screensaver settings ..." |
363 | mysqldo "insert into cfg_screensaver(serial,screensaver) values('${ALX_SERIAL}','')" |
364 | |
365 | # theme |
366 | echo " Theme settings ..." |
367 | mysqldo "insert into cfg_theme(serial,theme) values('${ALX_SERIAL}','${ALX_DEFAULT_THEME}')" |
368 | |
369 | evaluate_retval |
370 | } |
371 | |
372 | # imports current settings to the database resolved by the hardware detection |
373 | update_settings_in_db() |
374 | { |
375 | # note: networking is always 'dhcp' if hw was autodetected |
376 | # note: default_domain/hostname is set in config.rc or exported |
377 | # note: we updating only hardware settings here ! |
378 | |
379 | # to be safe, we do some sanity checks |
380 | [[ -z ${ALX_DEFAULT_DOMAIN} ]] && ALX_DEFAULT_DOMAIN=localdomain |
381 | [[ -z ${ALX_DEFAULT_HOSTNAME} ]] && ALX_DEFAULT_HOSTNAME=magellan-alx |
382 | |
383 | # vars used by hwdetect |
384 | local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME |
385 | local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER |
386 | local MOUSETYPE XMOUSETYPE FULLNAME DEVICE |
387 | |
388 | # get setting from hwdetect |
389 | source /etc/sysconfig/hwsetup/knoppix |
390 | source /etc/sysconfig/hwsetup/mouse |
391 | |
392 | echo |
393 | echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT} |
394 | |
395 | # network |
396 | echo " Network settings ..." |
397 | mysqldo "update cfg_network set |
398 | hostname='${ALX_DEFAULT_HOSTNAME}', |
399 | domain='${ALX_DEFAULT_DOMAIN}'; |
400 | where serial=${ALX_SERIAL};" |
401 | |
402 | # let udev decide which module should be loaded |
403 | # get all devices from sysfs |
404 | local i |
405 | local iface |
406 | for i in /sys/class/net/eth? |
407 | do |
408 | iface=$(basename ${i}) |
409 | NETCARD_DRIVER=$(source /sys/class/net/${iface}/uevent; echo ${PHYSDEVDRIVER}) |
410 | mysqldo "update cfg_interfaces set |
411 | iface='${iface}', |
412 | module='${NETCARD_DRIVER}', |
413 | networking='${NETWORKING}', |
414 | where serial=${ALX_SERIAL};" |
415 | |
416 | # only insert the *FIRST* iface |
417 | break |
418 | done |
419 | evaluate_retval |
420 | |
421 | # xserver |
422 | echo " Graphic settings ..." |
423 | # xserver general |
424 | mysqldo "update cfg_graphic set |
425 | module='${XMODULE}', |
426 | resolution='1024x768', |
427 | depth='16', |
428 | monitorid='0' |
429 | where serial=${ALX_SERIAL};" |
430 | evaluate_retval |
431 | |
432 | # input |
433 | echo " Input settings ..." |
434 | mysqldo "update cfg_input set mouse='${XMOUSETYPE}', keyboard='kbd' where serial=${ALX_SERIAL};" |
435 | evaluate_retval |
436 | } |
437 | |
438 | # start|stop |
439 | preliminary_network() |
440 | { |
441 | case $1 in |
442 | start) |
443 | # keeping like always safe: |
444 | # no network should be started here |
445 | ${rc_base}/init.d/network stop |
446 | |
447 | echo -e ${COLMAGENTA}"Starting preliminary networking ... "${COLDEFAULT} |
448 | # start network configured from /etc/conf.d |
449 | ${rc_base}/init.d/network start |
450 | ;; |
451 | |
452 | stop) |
453 | echo -e ${COLMAGENTA}"Stopping preliminary networking ... "${COLDEFAULT} |
454 | ${rc_base}/init.d/network stop |
455 | ;; |
456 | |
457 | *) |
458 | echo "Usage: preliminary_network {start|stop}" |
459 | ;; |
460 | esac |
461 | } |
462 | |
463 | reset_system_settings() |
464 | { |
465 | # force load of de kbdkeys |
466 | loadkeys -q de |
467 | echo |
468 | echo -en ${COLRED} |
469 | echo -n "*** Warning: you are about to reset *all* local settings on this system!" |
470 | echo -e ${COLDEFAULT} |
471 | echo "*** Do you really want to continue ?" |
472 | echo -n "*** Enter 'yes' to continue, anything else to abort: " |
473 | read kbinsert |
474 | if [[ ${kbinsert} = yes ]] |
475 | then |
476 | echo -en ${COLRED} |
477 | echo -n "*** OK, you really want it ... killing all settings: " |
478 | for i in 3 2 1 now |
479 | do |
480 | echo -n " ${i}" |
481 | sleep 1 |
482 | done |
483 | echo -e ${COLDEFAULT} |
484 | |
485 | ## reset all settings: |
486 | rm -rf ${SETTINGSPATH}/* |
487 | rm -f /etc/alxconfig-ng/serial |
488 | rm -rf /etc/alxconfig-ng/state |
489 | |
490 | # clear all printers |
491 | :> /etc/printcap |
492 | find /var/spool/lpd/* -type d | xargs rm -rf &> /dev/null |
493 | |
494 | # remove all user settings |
495 | [ -d ${ALX_UNPRIV_HOME} ] && rm -rf ${ALX_UNPRIV_HOME} |
496 | |
497 | # remove all ica-sessions |
498 | find ${ALX_ICA_SESSIONS} -type f -name '*.ica' | xargs rm |
499 | |
500 | # remove all old nics and modules configs |
501 | find /etc/conf.d -type f -name 'net.*' | xargs rm |
502 | find /etc/modules.d -type f -name 'net.*' | xargs rm |
503 | |
504 | # restore default networking |
505 | cat ${ALX_SKELETONS}/net/net.eth0 > /etc/conf.d/net.eth0 |
506 | |
507 | echo "I am done now, press [Enter] to reboot system ..." |
508 | else |
509 | echo "Aborted, press [Enter] to reboot system ..." |
510 | fi |
511 | read |
512 | reboot |
513 | } |
514 | |
515 | case $1 in |
516 | start) |
517 | # check for global overrides |
518 | [ -f /hardware-auto-detection ] && ALX_FORCED_RECHECK=true |
519 | read_cmdline hardware-auto-detection && ALX_FORCED_RECHECK=true |
520 | read_cmdline alx-reset-settings && ALX_RESET_SETTINGS=true |
521 | |
522 | # kill all settings if requested |
523 | if [[ ${ALX_RESET_SETTINGS} = true ]] |
524 | then |
525 | reset_system_settings |
526 | fi |
527 | |
528 | # retrieve or validate current serial |
529 | get_system_serial |
530 | if [[ ${ALX_HW_DETECT} = true ]] |
531 | then |
532 | if [[ ${ALX_FORCED_RECHECK} = true ]] |
533 | then |
534 | update_settings_in_db |
535 | else |
536 | import_settings_to_db |
537 | fi |
538 | |
539 | # here we should also exchange the ssh keys |
540 | # or the system cannot be rebooted after |
541 | # the first start via the alx-webadmin |
542 | config_ssh_auth |
543 | fi |
544 | |
545 | # now setup system configuration |
546 | # alx_setup_or_whatever_it_will_be_called() |
547 | update_system_settings |
548 | |
549 | # stop at last the preliminary networking (dhcp) |
550 | preliminary_network stop |
551 | ;; |
552 | |
553 | stop) |
554 | # unset_alx_connected #--> now in alxsetstate-rc6 |
555 | # ! important !: del systemstate |
556 | [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state |
557 | ;; |
558 | *) |
559 | echo "Usage: $0 {start|stop} ..." |
560 | ;; |
561 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |