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