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