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