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