Annotation of /alx-src/tags/alxconf-0_6_4_1/init.d/alxsettings
Parent Directory | Revision Log
Revision 275 -
(hide annotations)
(download)
Sun Jul 10 17:55:03 2005 UTC (19 years, 2 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 11656 byte(s)
Sun Jul 10 17:55:03 2005 UTC (19 years, 2 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 11656 byte(s)
create fluxbox config at first boot
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 | 275 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.14 2005-07-10 17:55:03 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 | #mysql settings | ||
28 | niro | 226 | source /etc/alxconfig-ng/config.rc |
29 | 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 | 221 | |
39 | #check if mysql is available | ||
40 | [ -x /usr/bin/mysql ] && MYSQL_ALX=true | ||
41 | |||
42 | #other needed vars | ||
43 | ALX_HW_DETECT=false | ||
44 | |||
45 | #unset vars which may kill us | ||
46 | unset ALX_SERIAL ALX_STATE | ||
47 | |||
48 | |||
49 | #setup needed directories | ||
50 | niro | 226 | [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state |
51 | niro | 221 | |
52 | |||
53 | niro | 226 | update_system_settings(){ |
54 | echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} | ||
55 | niro | 221 | |
56 | niro | 257 | # get the modules settings |
57 | # ! is the first thing that must be configured ! | ||
58 | config_modules | ||
59 | |||
60 | niro | 226 | # imports network settings from db |
61 | config_networking | ||
62 | |||
63 | # imports x11 settings from db | ||
64 | config_x11 | ||
65 | |||
66 | niro | 248 | # imports session settings from db |
67 | niro | 239 | config_sessions |
68 | niro | 226 | |
69 | # imports printer settings from db | ||
70 | config_printing | ||
71 | niro | 248 | |
72 | # imports auth settings from db | ||
73 | config_auth | ||
74 | niro | 252 | |
75 | # exchange ssh rsa keys | ||
76 | niro | 265 | HOME=/root config_ssh_auth |
77 | niro | 221 | } |
78 | |||
79 | get_system_serial(){ | ||
80 | |||
81 | local CUR_IP CUR_MAC CUR_MTIME | ||
82 | |||
83 | #check if serial file exists | ||
84 | niro | 226 | if [ -f /etc/alxconfig-ng/serial ] |
85 | niro | 221 | then |
86 | niro | 226 | source /etc/alxconfig-ng/serial |
87 | |||
88 | #start preliminary networking (dhcp) | ||
89 | niro | 221 | preliminary_network start |
90 | niro | 226 | |
91 | niro | 221 | CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') |
92 | CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) | ||
93 | CUR_MTIME=$(date +%s) | ||
94 | niro | 226 | |
95 | niro | 221 | echo -e ${COLOREDSTAR} "Trying to validate my serial ..." |
96 | niro | 226 | |
97 | niro | 221 | #nice serial output |
98 | $CURS_UP | ||
99 | $SET_WCOL | ||
100 | echo "[ SN: ${ALX_SERIAL} ]" | ||
101 | |||
102 | if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}" | ||
103 | then | ||
104 | ALX_STATE="ok" | ||
105 | else | ||
106 | ALX_STATE="invalid serial" | ||
107 | fi | ||
108 | |||
109 | else | ||
110 | #run hardware detection | ||
111 | echo | ||
112 | echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT} | ||
113 | ALX_HW_DETECT=true | ||
114 | /etc/init.d/hwdetect start | ||
115 | niro | 226 | |
116 | niro | 221 | #set hostname to alx_default_hostname |
117 | [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx | ||
118 | HOSTNAME="${ALX_DEFAULT_HOSTNAME}" | ||
119 | niro | 226 | |
120 | niro | 221 | #update the hostname on the system for sure |
121 | niro | 230 | echo "${HOSTNAME}" > /etc/hostname |
122 | niro | 226 | |
123 | niro | 221 | #start preliminary networking (dhcp) |
124 | preliminary_network start | ||
125 | niro | 226 | |
126 | niro | 221 | CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp') |
127 | CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11) | ||
128 | CUR_MTIME=$(date +%s) | ||
129 | niro | 226 | |
130 | niro | 221 | echo -e ${COLOREDSTAR} "Trying to get new serial ..." |
131 | niro | 226 | |
132 | niro | 221 | #request new serial |
133 | #ALX_REG_DATE="$(date +%F)" | ||
134 | niro | 226 | |
135 | niro | 221 | #we're using the mtime now (better for vaildating the serial) |
136 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
137 | "insert into client_serials( | ||
138 | mtime, | ||
139 | mac | ||
140 | ) | ||
141 | values( | ||
142 | '${CUR_MTIME}', | ||
143 | '${CUR_MAC}' | ||
144 | );" | ||
145 | niro | 226 | |
146 | niro | 221 | #then validate and retrieve serial |
147 | niro | 226 | |
148 | niro | 221 | ### warning must be changed that only the LAST ID will be fetched, ### |
149 | ### or you get error if the computer name and date are the same ### | ||
150 | niro | 226 | ### you have more than one serial number then ### |
151 | |||
152 | niro | 221 | #select highest id only (added max) |
153 | ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
154 | "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'") | ||
155 | |||
156 | if [ "${ALX_SERIAL}" != NULL ] | ||
157 | then | ||
158 | #nice serial output | ||
159 | $CURS_UP | ||
160 | $SET_WCOL | ||
161 | echo "[ SN: ${ALX_SERIAL} ]" | ||
162 | niro | 226 | |
163 | niro | 221 | #set ALX_STATE to ok so everybody that everything was ok |
164 | ALX_STATE=ok | ||
165 | niro | 226 | |
166 | echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial | ||
167 | echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial | ||
168 | |||
169 | niro | 221 | evaluate_retval |
170 | else | ||
171 | #print false (works only if this is the first statement here) | ||
172 | evaluate_retval | ||
173 | niro | 226 | |
174 | niro | 221 | #set ALX_STATE to error so everybody sees there was an error |
175 | ALX_STATE=error | ||
176 | niro | 226 | |
177 | niro | 221 | #show an error that no new serial was found |
178 | #nice serial output | ||
179 | $CURS_UP | ||
180 | $SET_WCOL | ||
181 | echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]" | ||
182 | fi | ||
183 | fi | ||
184 | niro | 226 | |
185 | niro | 221 | #write current state to temp file |
186 | niro | 226 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
187 | niro | 221 | } |
188 | |||
189 | |||
190 | check_is_configured() { | ||
191 | niro | 226 | if [ -f /etc/alxconfig-ng/state/configured ] |
192 | niro | 221 | then |
193 | export ALX_CONFIGURED=true | ||
194 | else | ||
195 | export ALX_CONFIGURED=false | ||
196 | fi | ||
197 | } | ||
198 | |||
199 | |||
200 | # imports current settings to the database resolved by the hardware detection | ||
201 | import_settings_to_db() { | ||
202 | #note: networking is always 'dhcp' if hw was autodetected | ||
203 | #note: default_domain/hostname is set in config.rc | ||
204 | niro | 229 | |
205 | niro | 221 | #to be safe, we do some sanity checks |
206 | [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain | ||
207 | [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx | ||
208 | niro | 229 | |
209 | niro | 221 | #vars used by hwdetect |
210 | local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME | ||
211 | local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER | ||
212 | local MOUSETYPE XMOUSETYPE FULLNAME DEVICE | ||
213 | niro | 229 | |
214 | niro | 221 | #get setting from hwdetect |
215 | source /etc/sysconfig/hwsetup/knoppix | ||
216 | source /etc/sysconfig/hwsetup/mouse | ||
217 | niro | 229 | |
218 | niro | 221 | echo |
219 | echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT} | ||
220 | niro | 229 | |
221 | niro | 221 | #network |
222 | echo -e " Network settings ..." | ||
223 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
224 | "insert into cfg_network( | ||
225 | hostname, | ||
226 | serial, | ||
227 | module, | ||
228 | domain, | ||
229 | networking | ||
230 | ) | ||
231 | values( | ||
232 | '${ALX_DEFAULT_HOSTNAME}', | ||
233 | '${ALX_SERIAL}', | ||
234 | '${NETCARD_DRIVER}', | ||
235 | '${ALX_DEFAULT_DOMAIN}', | ||
236 | 'dhcp' | ||
237 | );" | ||
238 | evaluate_retval | ||
239 | niro | 229 | |
240 | niro | 221 | #xserver |
241 | echo -e " Graphic settings ..." | ||
242 | #xserver general | ||
243 | ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
244 | "insert into cfg_graphic( | ||
245 | serial, | ||
246 | module, | ||
247 | resolution, | ||
248 | niro | 229 | depth, |
249 | monitorid | ||
250 | niro | 221 | ) |
251 | values( | ||
252 | '${ALX_SERIAL}', | ||
253 | '${XMODULE}', | ||
254 | '1024x768', | ||
255 | niro | 229 | '16', |
256 | '0' | ||
257 | niro | 252 | );"; ) |
258 | evaluate_retval | ||
259 | niro | 229 | |
260 | niro | 221 | # input |
261 | niro | 252 | echo -e " Input settings ..." |
262 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
263 | "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');" | ||
264 | niro | 221 | evaluate_retval |
265 | niro | 252 | |
266 | # auth | ||
267 | echo -e " Authentifcation settings ..." | ||
268 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
269 | "insert into client_auth( | ||
270 | serial, | ||
271 | username, | ||
272 | shell, | ||
273 | vnc, | ||
274 | samba, | ||
275 | station | ||
276 | ) | ||
277 | values( | ||
278 | '${ALX_SERIAL}', | ||
279 | '${ALX_UNPRIV_USER}', | ||
280 | '', | ||
281 | '', | ||
282 | '', | ||
283 | '' | ||
284 | );" | ||
285 | evaluate_retval | ||
286 | |||
287 | niro | 263 | # exchange ssh rsa keys - the first boot needs this ! |
288 | # or no reboot will work via the webadmin | ||
289 | echo -e " SSH authentifcation settings ..." | ||
290 | niro | 264 | HOME=/root config_ssh_auth |
291 | niro | 263 | evaluate_retval |
292 | |||
293 | niro | 252 | # input |
294 | echo -e " Autostart settings ..." | ||
295 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
296 | "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');" | ||
297 | evaluate_retval | ||
298 | niro | 221 | } |
299 | |||
300 | # imports current settings to the local system resolved by the hardware detection | ||
301 | niro | 226 | # we only need the network settings |
302 | niro | 221 | import_settings_local(){ |
303 | #note: networking is always 'dhcp' if hw was autodetected | ||
304 | #note: default_domain/hostname is set in config.rc | ||
305 | niro | 226 | |
306 | niro | 221 | #to be safe, we do some sanity checks |
307 | [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain | ||
308 | [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx | ||
309 | niro | 226 | |
310 | niro | 221 | #vars used by hwdetect |
311 | local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME | ||
312 | local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER | ||
313 | local MOUSETYPE XMOUSETYPE FULLNAME DEVICE | ||
314 | |||
315 | #get setting from hwdetect | ||
316 | source /etc/sysconfig/hwsetup/knoppix | ||
317 | niro | 226 | |
318 | niro | 221 | echo |
319 | echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT} | ||
320 | |||
321 | niro | 226 | [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
322 | echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules | ||
323 | evaluate_retval | ||
324 | niro | 221 | |
325 | #set system state to 'already configured' | ||
326 | niro | 226 | touch /etc/alxconfig-ng/state/configured |
327 | niro | 252 | |
328 | niro | 275 | # create a fresh fluxbox directory |
329 | [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox | ||
330 | install -d ${ALX_UNPRIV_HOME}/.fluxbox | ||
331 | |||
332 | # now generate fluxbox config files | ||
333 | |||
334 | # fluxbox main config | ||
335 | cat ${ALX_SKELETONS}/fluxbox/init \ | ||
336 | > ${ALX_UNPRIV_HOME}/.fluxbox/init | ||
337 | |||
338 | # fluxbox menu header | ||
339 | cat ${ALX_SKELETONS}/fluxbox/menu.header \ | ||
340 | > ${ALX_UNPRIV_HOME}/.fluxbox/menu | ||
341 | |||
342 | # add a newline (maybe there is no crlf in the header) | ||
343 | echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu | ||
344 | |||
345 | # fluxbox menu footer | ||
346 | cat ${ALX_SKELETONS}/fluxbox/menu.footer \ | ||
347 | >> ${ALX_UNPRIV_HOME}/.fluxbox/menu | ||
348 | |||
349 | # add a newline (maybe there is no crlf in the footer) | ||
350 | echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu | ||
351 | |||
352 | niro | 252 | # default passwords are bad |
353 | #usermod -p $(perl -e "printf(crypt('foobar','AD'))") root | ||
354 | #usermod -p $(perl -e "printf(crypt('foobar','AD'))") ${ALX_UNPRIV_USER} | ||
355 | #smbpasswd -a root foobar | ||
356 | niro | 221 | } |
357 | |||
358 | #start|stop | ||
359 | preliminary_network(){ | ||
360 | local module | ||
361 | niro | 226 | |
362 | if [ -f /etc/alxconfig-ng/state/configured ] | ||
363 | niro | 221 | then |
364 | #get module name | ||
365 | niro | 226 | module=$(cat ${SETTINGSPATH}/modules) |
366 | niro | 221 | modprobe ${module} |
367 | else | ||
368 | #vars used by hwdetect | ||
369 | local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME | ||
370 | local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER | ||
371 | niro | 226 | |
372 | niro | 221 | #get setting from hwdetect |
373 | source /etc/sysconfig/hwsetup/knoppix | ||
374 | modprobe ${NETCARD_DRIVER} | ||
375 | fi | ||
376 | niro | 226 | |
377 | niro | 221 | case $1 in |
378 | start) | ||
379 | # keeping like always safe: | ||
380 | # no network should be startet here, | ||
381 | # so we can delete all pid files if one exists | ||
382 | if ps -A|grep dhcpcd > /dev/null | ||
383 | then | ||
384 | echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT} | ||
385 | dhcpcd -k | ||
386 | sleep 1 | ||
387 | else | ||
388 | rm -f /var/run/dhcpcd-eth?.pid | ||
389 | fi | ||
390 | niro | 226 | |
391 | niro | 221 | echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} |
392 | niro | 226 | dhcpcd &> /dev/null |
393 | |||
394 | niro | 221 | # aka_fix ######################################## |
395 | niro | 226 | #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up |
396 | #route del default gw 128.20.50.13 &> /dev/null | ||
397 | #route add default gw 128.20.50.21 &> /dev/null | ||
398 | #echo "nameserver 128.20.50.21" > /etc/resolv.conf | ||
399 | niro | 221 | ################################################## |
400 | niro | 226 | |
401 | niro | 221 | evaluate_retval |
402 | ;; | ||
403 | niro | 226 | |
404 | niro | 221 | stop) |
405 | echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT} | ||
406 | ifconfig eth0 down | ||
407 | if ps -A|grep dhcpcd > /dev/null | ||
408 | then | ||
409 | dhcpcd -z &> /dev/null | ||
410 | fi | ||
411 | evaluate_retval | ||
412 | ;; | ||
413 | niro | 226 | |
414 | niro | 221 | *) |
415 | echo "Usage: preliminary_network {start|stop}" | ||
416 | ;; | ||
417 | esac | ||
418 | } | ||
419 | |||
420 | case $1 in | ||
421 | start) | ||
422 | #retrieve or validate current serial | ||
423 | get_system_serial | ||
424 | if [ "${ALX_HW_DETECT}" == "true" ] | ||
425 | then | ||
426 | import_settings_to_db | ||
427 | import_settings_local | ||
428 | niro | 252 | |
429 | # here we should also exchange the ssh keys | ||
430 | # or the system cannot be rebooted after | ||
431 | # the first start via the alx-webadmin | ||
432 | config_ssh_auth | ||
433 | niro | 221 | fi |
434 | niro | 252 | |
435 | niro | 221 | #now setup system configuration |
436 | #alx_setup_or_whatever_it_will_be_called() | ||
437 | [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings | ||
438 | |||
439 | #stop at last the preliminary networking (dhcp) | ||
440 | preliminary_network stop | ||
441 | ;; | ||
442 | |||
443 | stop) | ||
444 | #unset_alx_connected #--> now in alxsetstate-rc6 | ||
445 | # ! important !: del systemstate | ||
446 | niro | 226 | [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state |
447 | niro | 221 | sleep 0.1 |
448 | ;; | ||
449 | *) | ||
450 | echo "Usage: $0 {start|stop} ..." | ||
451 | ;; | ||
452 | esac | ||
453 | niro | 252 |
Properties
Name | Value |
---|---|
svn:executable | * |