Magellan Linux

Contents of /alx-src/trunk/alxconfig-ng/init.d/alxsettings

Parent Directory Parent Directory | Revision Log Revision Log


Revision 227 - (show annotations) (download)
Wed Mar 9 00:04:23 2005 UTC (19 years, 1 month ago) by niro
File size: 11169 byte(s)
fixed

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.3 2005-03-09 00:04:23 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_x11
34
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 [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
47
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 update_system_settings(){
114 echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
115
116 # 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 }
130
131 get_system_serial(){
132
133 local CUR_IP CUR_MAC CUR_MTIME
134
135 #check if serial file exists
136 if [ -f /etc/alxconfig-ng/serial ]
137 then
138 source /etc/alxconfig-ng/serial
139
140 # if system is already configured, it *has* a hostname.
141 # so we take the hostname of this system here
142 source /etc/hostname
143
144 #start preliminary networking (dhcp)
145 preliminary_network start
146
147 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
151 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
152
153 #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
172 #set hostname to alx_default_hostname
173 [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
174 HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
175
176 #update the hostname on the system for sure
177 echo "HOSTNAME=${HOSTNAME}" > /etc/hostname
178
179 #start preliminary networking (dhcp)
180 preliminary_network start
181
182 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
186 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
187
188 #request new serial
189 #ALX_REG_DATE="$(date +%F)"
190
191 #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
202 #then validate and retrieve serial
203
204 ### 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 ### you have more than one serial number then ###
207
208 #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
219 #set ALX_STATE to ok so everybody that everything was ok
220 ALX_STATE=ok
221
222 echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
223 echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial
224
225 evaluate_retval
226 else
227 #print false (works only if this is the first statement here)
228 evaluate_retval
229
230 #set ALX_STATE to error so everybody sees there was an error
231 ALX_STATE=error
232
233 #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
241 #write current state to temp file
242 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
243 }
244
245
246 check_is_configured() {
247 if [ -f /etc/alxconfig-ng/state/configured ]
248 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
261 #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
265 #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
270 #get setting from hwdetect
271 source /etc/sysconfig/hwsetup/knoppix
272 source /etc/sysconfig/hwsetup/mouse
273
274 echo
275 echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
276
277 #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
296 #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 depth
305 )
306 values(
307 '${ALX_SERIAL}',
308 '${XMODULE}',
309 '1024x768',
310 '16'
311 );";
312 #xserver monitor
313 mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
314 "insert into cfg_monitor(
315 serial,
316 vendor,
317 model,
318 hsync,
319 vrefresh
320 )
321 values(
322 '${ALX_SERIAL}',
323 'Aamazing',
324 'CM-1528-FS',
325 '28-64',
326 '47-104'
327 );";
328
329 # input
330 mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
331 "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');";)
332 evaluate_retval
333 }
334
335 # imports current settings to the local system resolved by the hardware detection
336 # we only need the network settings
337 import_settings_local(){
338 #note: networking is always 'dhcp' if hw was autodetected
339 #note: default_domain/hostname is set in config.rc
340
341 #to be safe, we do some sanity checks
342 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
343 [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
344
345 #vars used by hwdetect
346 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
347 local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
348 local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
349
350 #get setting from hwdetect
351 source /etc/sysconfig/hwsetup/knoppix
352
353 echo
354 echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
355
356 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
357 echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
358 evaluate_retval
359
360 #set system state to 'already configured'
361 touch /etc/alxconfig-ng/state/configured
362 }
363
364 #start|stop
365 preliminary_network(){
366 local module
367
368 if [ -f /etc/alxconfig-ng/state/configured ]
369 then
370 #get module name
371 module=$(cat ${SETTINGSPATH}/modules)
372 modprobe ${module}
373 else
374 #vars used by hwdetect
375 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
376 local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
377
378 #get setting from hwdetect
379 source /etc/sysconfig/hwsetup/knoppix
380 modprobe ${NETCARD_DRIVER}
381 fi
382
383 case $1 in
384 start)
385 # keeping like always safe:
386 # no network should be startet here,
387 # so we can delete all pid files if one exists
388 if ps -A|grep dhcpcd > /dev/null
389 then
390 echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT}
391 dhcpcd -k
392 sleep 1
393 else
394 rm -f /var/run/dhcpcd-eth?.pid
395 fi
396
397 echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
398 dhcpcd &> /dev/null
399
400 # aka_fix ########################################
401 #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up
402 #route del default gw 128.20.50.13 &> /dev/null
403 #route add default gw 128.20.50.21 &> /dev/null
404 #echo "nameserver 128.20.50.21" > /etc/resolv.conf
405 ##################################################
406
407 evaluate_retval
408 ;;
409
410 stop)
411 echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}
412 ifconfig eth0 down
413 if ps -A|grep dhcpcd > /dev/null
414 then
415 dhcpcd -z &> /dev/null
416 fi
417 evaluate_retval
418 ;;
419
420 *)
421 echo "Usage: preliminary_network {start|stop}"
422 ;;
423 esac
424 }
425
426 case $1 in
427 start)
428 #retrieve or validate current serial
429 get_system_serial
430 if [ "${ALX_HW_DETECT}" == "true" ]
431 then
432 import_settings_to_db
433 import_settings_local
434 fi
435
436 #now setup system configuration
437 #alx_setup_or_whatever_it_will_be_called()
438 [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings
439
440 #stop at last the preliminary networking (dhcp)
441 preliminary_network stop
442 ;;
443
444 stop)
445 #unset_alx_connected #--> now in alxsetstate-rc6
446 # ! important !: del systemstate
447 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
448 sleep 0.1
449 ;;
450 *)
451 echo "Usage: $0 {start|stop} ..."
452 ;;
453 esac

Properties

Name Value
svn:executable *