Contents of /alx-src/trunk/alxconfig-ng/init.d/alxsettings
Parent Directory | Revision Log
Revision 239 -
(show annotations)
(download)
Tue Apr 12 20:46:52 2005 UTC (19 years, 5 months ago) by niro
File size: 10854 byte(s)
Tue Apr 12 20:46:52 2005 UTC (19 years, 5 months ago) by niro
File size: 10854 byte(s)
import from aka-cvs
1 | #!/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 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.7 2005-04-12 20:45:55 niro Exp $ |
15 | |
16 | # checks first if the client was already configured and if it has an valid serial |
17 | # if not it runs the autoconfiguration script |
18 | # these settings will be used for client setup |
19 | # |
20 | # if client was valid it first will check if his settings against the server |
21 | # if no changes are at server side they will be kept, if yes the get updated. |
22 | # the server settings has higher priority. |
23 | |
24 | source /etc/sysconfig/rc |
25 | source $rc_functions |
26 | |
27 | #mysql settings |
28 | source /etc/alxconfig-ng/config.rc |
29 | source /usr/lib/alxconfig-ng/functions/mysqlfunctions |
30 | source /usr/lib/alxconfig-ng/functions/serial_functions |
31 | source /usr/lib/alxconfig-ng/functions/config_network |
32 | source /usr/lib/alxconfig-ng/functions/config_printers |
33 | source /usr/lib/alxconfig-ng/functions/config_sessions |
34 | source /usr/lib/alxconfig-ng/functions/config_x11 |
35 | |
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 | [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state |
48 | |
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 | update_system_settings(){ |
115 | echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} |
116 | |
117 | # 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 | config_sessions |
128 | |
129 | # imports printer settings from db |
130 | config_printing |
131 | } |
132 | |
133 | get_system_serial(){ |
134 | |
135 | local CUR_IP CUR_MAC CUR_MTIME |
136 | |
137 | #check if serial file exists |
138 | if [ -f /etc/alxconfig-ng/serial ] |
139 | then |
140 | source /etc/alxconfig-ng/serial |
141 | |
142 | #start preliminary networking (dhcp) |
143 | preliminary_network start |
144 | |
145 | 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 | |
149 | echo -e ${COLOREDSTAR} "Trying to validate my serial ..." |
150 | |
151 | #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 | |
170 | #set hostname to alx_default_hostname |
171 | [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx |
172 | HOSTNAME="${ALX_DEFAULT_HOSTNAME}" |
173 | |
174 | #update the hostname on the system for sure |
175 | echo "${HOSTNAME}" > /etc/hostname |
176 | |
177 | #start preliminary networking (dhcp) |
178 | preliminary_network start |
179 | |
180 | 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 | |
184 | echo -e ${COLOREDSTAR} "Trying to get new serial ..." |
185 | |
186 | #request new serial |
187 | #ALX_REG_DATE="$(date +%F)" |
188 | |
189 | #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 | |
200 | #then validate and retrieve serial |
201 | |
202 | ### 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 | ### you have more than one serial number then ### |
205 | |
206 | #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 | |
217 | #set ALX_STATE to ok so everybody that everything was ok |
218 | ALX_STATE=ok |
219 | |
220 | echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial |
221 | echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial |
222 | |
223 | evaluate_retval |
224 | else |
225 | #print false (works only if this is the first statement here) |
226 | evaluate_retval |
227 | |
228 | #set ALX_STATE to error so everybody sees there was an error |
229 | ALX_STATE=error |
230 | |
231 | #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 | |
239 | #write current state to temp file |
240 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
241 | } |
242 | |
243 | |
244 | check_is_configured() { |
245 | if [ -f /etc/alxconfig-ng/state/configured ] |
246 | 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 | |
259 | #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 | |
263 | #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 | |
268 | #get setting from hwdetect |
269 | source /etc/sysconfig/hwsetup/knoppix |
270 | source /etc/sysconfig/hwsetup/mouse |
271 | |
272 | echo |
273 | echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT} |
274 | |
275 | #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 | |
294 | #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 | depth, |
303 | monitorid |
304 | ) |
305 | values( |
306 | '${ALX_SERIAL}', |
307 | '${XMODULE}', |
308 | '1024x768', |
309 | '16', |
310 | '0' |
311 | );"; |
312 | |
313 | # 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 | # we only need the network settings |
321 | import_settings_local(){ |
322 | #note: networking is always 'dhcp' if hw was autodetected |
323 | #note: default_domain/hostname is set in config.rc |
324 | |
325 | #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 | |
329 | #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 | |
337 | echo |
338 | echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT} |
339 | |
340 | [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
341 | echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules |
342 | evaluate_retval |
343 | |
344 | #set system state to 'already configured' |
345 | touch /etc/alxconfig-ng/state/configured |
346 | } |
347 | |
348 | #start|stop |
349 | preliminary_network(){ |
350 | local module |
351 | |
352 | if [ -f /etc/alxconfig-ng/state/configured ] |
353 | then |
354 | #get module name |
355 | module=$(cat ${SETTINGSPATH}/modules) |
356 | 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 | |
362 | #get setting from hwdetect |
363 | source /etc/sysconfig/hwsetup/knoppix |
364 | modprobe ${NETCARD_DRIVER} |
365 | fi |
366 | |
367 | 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 | |
381 | echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} |
382 | dhcpcd &> /dev/null |
383 | |
384 | # aka_fix ######################################## |
385 | #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 | ################################################## |
390 | |
391 | evaluate_retval |
392 | ;; |
393 | |
394 | 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 | |
404 | *) |
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 | [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state |
432 | sleep 0.1 |
433 | ;; |
434 | *) |
435 | echo "Usage: $0 {start|stop} ..." |
436 | ;; |
437 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |