Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (hide annotations) (download)
Wed Mar 9 00:04:18 2005 UTC (19 years, 2 months ago) by niro
File size: 11480 byte(s)
fixed

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

Properties

Name Value
svn:executable *