Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 221 - (hide annotations) (download)
Tue Mar 8 20:49:14 2005 UTC (19 years, 2 months ago) by niro
File size: 30392 byte(s)
new

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     # +-----+
23     # |start|
24     # +-----+
25     # |
26     # |
27     # start_preliminary_network
28     # |
29     # | n
30     # serial_check -------> get_new_serial
31     # | |
32     # y| |
33     # | n |
34     # check_is_configured ----> run_hw_detection
35     # | |
36     # y| |
37     # n | |
38     # +--------cfg_equal_to_db import_settings_to_db
39     # | | |
40     # update_from_db y| |
41     # | | |
42     # set_is_configured | set_is_configured
43     # +-----------------| |
44     # +----------------------+
45     # |
46     # |
47     # stop_preliminary_network
48     # |
49     # |
50     # +----+
51     # |done|
52     # +----+
53     # |
54     # |
55     # normal_system_bootup
56     # |
57     # .
58     # .
59     # .
60     #
61     #
62     #
63    
64     source /etc/sysconfig/rc
65     source $rc_functions
66    
67     #mysql settings
68     source /etc/alx-config/config.rc
69     source /opt/alx-config/functions/mysqlfunctions
70     source /opt/alx-config/functions/alx-mysql-functions
71    
72     #check if mysql is available
73     [ -x /usr/bin/mysql ] && MYSQL_ALX=true
74    
75     #other needed vars
76     ALX_HW_DETECT=false
77     ALX_NETWORK_SETUP=false
78     ALX_XSERVER_SETUP=false
79     ALX_SESSION_SETUP=false
80     ALX_PRINTER_SETUP=false
81    
82     #unset vars which may kill us
83     unset ALX_SERIAL ALX_STATE
84    
85    
86     #setup needed directories
87     [ ! -d /etc/alx-config/state ] && install -d /etc/alx-config/state
88    
89    
90     # still a need to implement this ?
91     # #needed to detect usb/livecd boot
92     # if [ -e /.bootdev ]
93     # then
94     # source /.bootdev
95     # else
96     # echo "Couldn't find /.bootdev. Aborting."
97     # exit 1
98     # fi
99    
100     # still a need to implement this ? --> media-check ?
101     settings_import() {
102     if [ "${FSTYPE}" == "vfat" ]
103     then
104     if [ -e /mnt/cdrom/settings/system ]
105     then
106     echo -e ${COLOREDSTAR}"Importing old alx-settings ..."
107     ( cp -R /mnt/cdrom/settings/system/* /etc/alx-config/settings/menu &&
108     source /etc/alx-config/config.rc &&
109     source /opt/alx-config/Configurator/config_functions.sh &&
110     setup_xfree > /dev/null 2>&1 &&
111     setup_modules > /dev/null 2>&1 &&
112     setup_network > /dev/null 2>&1 &&
113     #setup_printers > /dev/null 2>&1 &&
114     setup_sessions > /dev/null 2>&1 &&
115     touch /etc/alx-config/imported )
116     evaluate_retval
117     fi
118     fi
119     }
120    
121    
122     # this thingy needs an complete rewrite.
123     # first get all settings from db server,
124     # than check against local system settings,
125     # if there are any differences, update the local settings,
126     # as the server has a higher priority.
127     # Important: write local settings only if they make sense,
128     # to have a fallback in case the server is down!
129     #get_settings_from_server(){
130     # #some needed arrays
131     # #ARRAY_NETWORK #module domain networking netmask dns gateway
132     # #SESSION #
133     # #GRAFIK #
134     #
135     # echo "Importing now old Settings ..."
136     #
137     # local serial module domain networking netmask dns gateway i x all
138     #
139     # declare -i i=0
140     #
141     # #get hostname from database
142     # MY_HOSTNAME=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
143     # "select hostname from cfg_serial where id='${ALX_SERIAL}'")
144     #
145     # #get network settings from database
146     # all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
147     # "select module,
148     # domain,
149     # networking,
150     # netmask,
151     # dns,
152     # gateway,
153     # broadcast,
154     # ip
155     # from cfg_network where serial='${ALX_SERIAL}'")
156     # #split'em up and put in array
157     # for x in ${all}
158     # do
159     # ARRAY_NETWORK[${i}]=${x}
160     # ((i++))
161     # done
162     # echo " Network:"
163     # echo " MODULE: ${ARRAY_NETWORK[0]}"
164     # echo " IP: ${ARRAY_NETWORK[7]}"
165     # echo " HOSTNAME: ${MY_HOSTNAME}"
166     # echo " DOMAIN: ${ARRAY_NETWORK[1]}"
167     # echo " NETWORKING: ${ARRAY_NETWORK[2]}"
168     # echo " NETMASK: ${ARRAY_NETWORK[3]}"
169     # echo " DNS: ${ARRAY_NETWORK[4]}"
170     # echo " GATEWAY: ${ARRAY_NETWORK[5]}"
171     # echo " BROADCAST: ${ARRAY_NETWORK[6]}"
172     # echo
173     #
174     # #get x settings from database
175     # local module resolution
176     #
177     # #reset i
178     # declare -i i=0
179     # all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
180     # "select module,
181     # resolution
182     # from cfg_grafik where serial='${ALX_SERIAL}'")
183     # #split'em up and put in array
184     # for x in ${all}
185     # do
186     # ARRAY_GRAFIK[${i}]=${x}
187     # ((i++))
188     # done
189     #
190     # echo " VGA:"
191     # echo " MODULE: ${ARRAY_GRAFIK[0]}"
192     # echo " RESOLUTION: ${ARRAY_GRAFIK[1]}"
193     # echo
194     #
195     # #get ica-sessions from database
196     # ARRAY_SESSIONS=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
197     # "select session from cfg_session where serial='${ALX_SERIAL}'")
198     #
199     # echo " SESSIONS:"
200     # declare -i i=0
201     # for x in ${ARRAY_SESSIONS}
202     # do
203     # ((i++))
204     # echo " SESSION${i}: ${x}"
205     # done
206     # echo
207     #
208     # #now write these settings
209     # local SETTINGSPATH
210     #
211     # #network
212     #
213     # #settings must be also set on system, so we put this to menu
214     # SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
215     #
216     # [ ! -d ${SETTINGSPATH}/modules ] && install -d ${SETTINGSPATH}/modules
217     # echo "${ARRAY_NETWORK[0]}" > ${SETTINGSPATH}/modules/modules
218     #
219     # [ ! -d ${SETTINGSPATH}/network ] && install -d ${SETTINGSPATH}/network
220     # echo "${MY_HOSTNAME}" > ${SETTINGSPATH}/network/hostname
221     # echo "${ARRAY_NETWORK[1]}" > ${SETTINGSPATH}/network/domain
222     # echo "${ARRAY_NETWORK[2]}" > ${SETTINGSPATH}/network/networking
223     # [ -n "${ARRAY_NETWORK[3]}" ] && echo "${ARRAY_NETWORK[3]}" > ${SETTINGSPATH}/network/netmask
224     # [ -n "${ARRAY_NETWORK[4]}" ] && echo "${ARRAY_NETWORK[4]}" > ${SETTINGSPATH}/network/dns
225     # [ -n "${ARRAY_NETWORK[5]}" ] && echo "${ARRAY_NETWORK[5]}" > ${SETTINGSPATH}/network/gateway
226     # [ -n "${ARRAY_NETWORK[6]}" ] && echo "${ARRAY_NETWORK[6]}" > ${SETTINGSPATH}/network/broadcast
227     # [ -n "${ARRAY_NETWORK[7]}" ] && echo "${ARRAY_NETWORK[7]}" > ${SETTINGSPATH}/network/ip
228    
229    
230     validate_networking(){
231     #source /opt/alx-config/Configurator/config_functions.sh
232    
233     local x i all LOCAL_NETWORK DB_NETWORK SETTINGSPATH
234    
235     #all arrays:
236     # -> hostname modules domain networking ip netmask dns gateway broadcast
237    
238     #networking
239     #get settings from local system
240     SETTINGSPATH=${SETTINGS_TEMPLATE}/system
241     declare -i i=0
242     for x in network/hostname \
243     modules/modules \
244     network/domain \
245     network/networking \
246     network/ip \
247     network/netmask \
248     network/dns \
249     network/gateway \
250     network/broadcast
251     do
252     if [ -f ${SETTINGSPATH}/${x} ]
253     then
254     #file exist, then use content
255     LOCAL_NETWORK[${i}]="$(< ${SETTINGSPATH}/${x})"
256     else
257     LOCAL_NETWORK[${i}]=""
258     fi
259     ((i++))
260     done
261    
262     #get settings from database
263     # DB_NETWORK[0]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
264     # "select hostname from cfg_network where serial='${ALX_SERIAL}'")
265    
266     all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
267     "select hostname,
268     module,
269     domain,
270     networking,
271     ip,
272     netmask,
273     dns,
274     gateway,
275     broadcast
276     from cfg_network where serial='${ALX_SERIAL}'")
277    
278     #split'em up and put in an array
279     declare -i i=0
280     for x in ${all}
281     do
282     DB_NETWORK[${i}]=${x}
283     ((i++))
284     done
285    
286     #needed by the small hotfix
287     local FIX_ME
288     FIX_ME="${DB_NETWORK[2]}"
289    
290    
291     #now compare this stuff if they are equal
292     for ((i=0; i < 9; i++))
293     do
294     if [ "${DB_NETWORK[${i}]}" = "${LOCAL_NETWORK[${i}]}" ]
295     then
296     echo "${i}: ${DB_NETWORK[${i}]} == ${LOCAL_NETWORK[${i}]}"
297    
298     #delete equal stuff from DB_NETWORK
299     DB_NETWORK[${i}]="*NULL*"
300    
301     else
302     echo "${i}: ${DB_NETWORK[${i}]} != ${LOCAL_NETWORK[${i}]}"
303     fi
304     done
305    
306    
307     #update configs
308     SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
309     declare -i i=0
310     for x in network/hostname \
311     modules/modules \
312     network/domain \
313     network/networking \
314     network/ip \
315     network/netmask \
316     network/dns \
317     network/gateway \
318     network/broadcast
319     do
320     #update only staff wich wasn't overwritten
321     if [ "${DB_NETWORK[${i}]}" != "*NULL*" ]
322     then
323     #create directory if not exist
324     if [ ! -d $(dirname ${SETTINGSPATH}/${x}) ]
325     then
326     install -d $(dirname ${SETTINGSPATH}/${x})
327     fi
328     echo "${DB_NETWORK[${i}]}" > ${SETTINGSPATH}/${x}
329    
330     # theses fucking config functions:
331     # network gets only updated,
332     # if ${SETTINGS_TEMPLATE}/menu/network/networking exist
333     # so we force an update here
334     if [ ! -f ${SETTINGSPATH}/network/networking ]
335     then
336     [ ! -d ${SETTINGSPATH}/network ] && install -d ${SETTINGSPATH}/network
337     echo "${FIX_ME}" > ${SETTINGSPATH}/network/networking
338     fi
339    
340     #set update flag
341     ALX_NETWORK_SETUP=true
342     fi
343     ((i++))
344     done
345     }
346    
347    
348    
349     validate_xserver(){
350     #source /opt/alx-config/Configurator/config_functions.sh
351    
352     local x i all LOCAL_XSERVER DB_XSERVER SETTINGSPATH
353    
354     #all arrays:
355     # -> xmodule resolution depth mouse monvendor monmodel hsync vref
356    
357     #xserver
358     #get settings from local system
359     #vga
360     SETTINGSPATH=${SETTINGS_TEMPLATE}/system
361     declare -i i=0
362     for x in vga/vga \
363     vga/vgares \
364     vga/vgadepth
365     do
366     if [ -f ${SETTINGSPATH}/${x} ]
367     then
368     #file exist, then use content
369     LOCAL_XSERVER[${i}]="$(< ${SETTINGSPATH}/${x})"
370     else
371     LOCAL_XSERVER[${i}]=""
372     fi
373     ((i++))
374     done
375    
376     #mouse
377     if [ -f ${SETTINGSPATH}/mouse/mouse ]
378     then
379     #file exist, then use content
380     LOCAL_XSERVER[3]="$(< ${SETTINGSPATH}/mouse/mouse)"
381     else
382     LOCAL_XSERVER[3]=""
383     fi
384    
385     #monitor
386     local myvendor mymodel hsync vref
387     if [ -f ${SETTINGSPATH}/monitor/monitor ]
388     then
389     source ${SETTINGSPATH}/monitor/monitor
390    
391     declare -i i=4
392     for x in "${myvendor}" \
393     "${mymodel}" \
394     "${hsync}" \
395     "${vref}"
396     do
397     LOCAL_XSERVER[${i}]="${x}"
398     ((i++))
399     done
400     else
401     LOCAL_XSERVER[4]=""
402     LOCAL_XSERVER[5]=""
403     LOCAL_XSERVER[6]=""
404     LOCAL_XSERVER[7]=""
405     fi
406    
407    
408     #get settings from database
409     all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
410     "select module,
411     resolution,
412     depth
413     from cfg_graphic where serial='${ALX_SERIAL}'")
414    
415     #split'em up and put in an array
416     declare -i i=0
417     for x in ${all}
418     do
419     DB_XSERVER[${i}]=${x}
420     ((i++))
421     done
422    
423     # read mouse
424     DB_XSERVER[3]=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
425     "select mouse from cfg_input where serial='${ALX_SERIAL}'")
426    
427     #monitors
428     # all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
429     # "select vendor,
430     # model,
431     # hsync,
432     # vrefresh
433     # from cfg_monitor where serial='${ALX_SERIAL}'")
434    
435     all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
436     "select vendor,
437     model,
438     hsync,
439     vrefresh
440     from list_monitors
441     inner join cfg_graphic
442     on cfg_graphic.monitorid=list_monitors.id;")
443    
444     #split'em up and put in an array
445     declare -i i=4
446     for x in ${all}
447     do
448     DB_XSERVER[${i}]=${x}
449     ((i++))
450     done
451    
452     # #now compare this stuff if they are equal
453     # for ((i=0; i < 8; i++))
454     # do
455     # if [ "${DB_XSERVER[${i}]}" = "${LOCAL_XSERVER[${i}]}" ]
456     # then
457     # echo "${i}: ${DB_XSERVER[${i}]} == ${LOCAL_XSERVER[${i}]}"
458     #
459     # #delete equal stuff from DB_NETWORK
460     # DB_XSERVER[${i}]="*NULL*"
461     #
462     # else
463     # echo "${i}: ${DB_XSERVER[${i}]} != ${LOCAL_XSERVER[${i}]}"
464     # fi
465     # done
466     #
467     #
468     # #update configs
469     # SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
470     # #xserver general
471     # declare -i i=0
472     # for x in vga/vga \
473     # vga/vgares \
474     # vga/vgadepth \
475     # mouse/mouse
476     # do
477     # #update only staff wich wasn't overwritten
478     # if [ "${DB_XSERVER[${i}]}" != "*NULL*" ]
479     # then
480     # #create directory if not exist
481     # if [ ! -d $(dirname ${SETTINGSPATH}/${x}) ]
482     # then
483     # install -d $(dirname ${SETTINGSPATH}/${x})
484     # fi
485     # echo "${DB_XSERVER[${i}]}" > ${SETTINGSPATH}/${x}
486     # #set update flag
487     # ALX_XSERVER_SETUP=true
488     # fi
489     # ((i++))
490     # done
491     #
492     # #xserver monitors
493     # if [ "${DB_XSERVER[4]}" != "*NULL*" \
494     # -o "${DB_XSERVER[5]}" != "*NULL*" \
495     # -o "${DB_XSERVER[6]}" != "*NULL*" \
496     # -o "${DB_XSERVER[7]}" != "*NULL*" ]
497     # then
498     # if [ ! -d ${SETTINGSPATH}/monitor ]
499     # then
500     # install -d ${SETTINGSPATH}/monitor
501     # fi
502     # echo "myvendor=\"${DB_XSERVER[4]}\"" > ${SETTINGSPATH}/monitor/monitor
503     # echo "mymodel=\"${DB_XSERVER[5]}\"" >> ${SETTINGSPATH}/monitor/monitor
504     # echo "hsync=\"${DB_XSERVER[6]}\"" >> ${SETTINGSPATH}/monitor/monitor
505     # echo "vref=\"${DB_XSERVER[7]}\"" >> ${SETTINGSPATH}/monitor/monitor
506     #
507     # #set update flag
508     # ALX_XSERVER_SETUP=true
509     # fi
510    
511     # - damn fucking setup_xfree routine need to rewrite this fucking stuff -
512     # setup_xfree will only run
513     # if ${SETTINGS_TEMPLATE}/menu/vga/vga exist
514     # so we must *always* update *all* settings if something has changed
515    
516     #now compare this stuff if they are equal
517     for ((i=0; i < 8; i++))
518     do
519     if [ "${DB_XSERVER[${i}]}" = "${LOCAL_XSERVER[${i}]}" ]
520     then
521     echo "${i}: ${DB_XSERVER[${i}]} == ${LOCAL_XSERVER[${i}]}"
522    
523     #delete equal stuff from DB_NETWORK
524     #DB_XSERVER[${i}]="*NULL*"
525    
526     else
527     echo "${i}: ${DB_XSERVER[${i}]} != ${LOCAL_XSERVER[${i}]}"
528     fi
529     done
530    
531     SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
532     if [ "${DB_XSERVER[0]}" != "*NULL*" \
533     -o "${DB_XSERVER[1]}" != "*NULL*" \
534     -o "${DB_XSERVER[2]}" != "*NULL*" \
535     -o "${DB_XSERVER[3]}" != "*NULL*" \
536     -o "${DB_XSERVER[4]}" != "*NULL*" \
537     -o "${DB_XSERVER[5]}" != "*NULL*" \
538     -o "${DB_XSERVER[6]}" != "*NULL*" \
539     -o "${DB_XSERVER[7]}" != "*NULL*" ]
540     then
541     [ ! -d ${SETTINGSPATH}/vga ] && install -d ${SETTINGSPATH}/vga
542     [ ! -d ${SETTINGSPATH}/mouse ] && install -d ${SETTINGSPATH}/mouse
543     [ ! -d ${SETTINGSPATH}/monitor ] && install -d ${SETTINGSPATH}/monitor
544    
545     echo "${DB_XSERVER[0]}" > ${SETTINGSPATH}/vga/vga
546     echo "${DB_XSERVER[1]}" > ${SETTINGSPATH}/vga/vgares
547     echo "${DB_XSERVER[2]}" > ${SETTINGSPATH}/vga/vgadepth
548     echo "${DB_XSERVER[3]}" > ${SETTINGSPATH}/mouse/mouse
549    
550     echo "myvendor=\"${DB_XSERVER[4]}\"" > ${SETTINGSPATH}/monitor/monitor
551     echo "mymodel=\"${DB_XSERVER[5]}\"" >> ${SETTINGSPATH}/monitor/monitor
552     echo "hsync=\"${DB_XSERVER[6]}\"" >> ${SETTINGSPATH}/monitor/monitor
553     echo "vref=\"${DB_XSERVER[7]}\"" >> ${SETTINGSPATH}/monitor/monitor
554    
555     #set update flag
556     ALX_XSERVER_SETUP=true
557     fi
558     }
559    
560    
561     validate_sessions(){
562     #source /opt/alx-config/Configurator/config_functions.sh
563    
564     local x i all LOCAL_SESSIONS DB_SESSIONS SETTINGSPATH count
565    
566     #all arrays:
567     # -> session1 session2 ... sessionN
568    
569    
570     #no LOCAL_SESSIONS here, needs bubblesort
571    
572     #get settings from database
573     all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
574     "select session from cfg_sessions where serial='${ALX_SERIAL}'")
575    
576     #split'em up and put in an array (only if $all not zero)
577     declare -i i=0
578     if [ -n "${all}" ]
579     then
580     for x in ${all}
581     do
582     DB_SESSIONS[${i}]=${x}
583     ((i++))
584     done
585     count=${i}
586     else
587     count=0
588     fi
589    
590     ## no compare here, can only done with bubblesort or s.th like that
591     # shows only the new sessions
592     declare -i i=0
593     #count=${#DB_SESSIONS[*]} #---> not working gets always 1, why ?
594    
595     echo "Number of new sessions: ${count}"
596     for ((i=0; i < count; i++))
597     do
598     echo "${i} - ${DB_SESSIONS[${i}]}"
599     done
600    
601     #update local configs
602     SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
603     declare -i i=0
604    
605     #count=${#DB_SESSIONS[*]}
606    
607     if [ ${count} -gt 0 ]
608     then
609     #create directory if not exist
610     [ ! -d ${SETTINGSPATH}/sessions ] && install -d ${SETTINGSPATH}/sessions
611    
612     #delete old sessions
613     echo -n > ${SETTINGSPATH}/sessions/sessions
614    
615     for ((i=0; i < count; i++))
616     do
617     echo "${DB_SESSIONS[${i}]}" >> ${SETTINGSPATH}/sessions/sessions
618     done
619    
620     #set update flag
621     ALX_SESSION_SETUP=true
622     fi
623     }
624    
625    
626     validate_printing(){
627     #source /opt/alx-config/Configurator/config_functions.sh
628    
629     local x i k all LOCAL_PRINTER DB_PRINTER SETTINGSPATH count
630    
631     #all arrays: [2 dimensions !]
632     # -> name1 name2 ... nameN
633     # -> name1 printingport ip share
634    
635     #later on, for now -> name1 port1 ip1 share1 name2 ....
636     # seperator is 4
637    
638     #local PRINTERNAME PRINTING IP SHARE
639    
640     # update *always* printers from database;
641     # compare with local settings cannot be done yet
642    
643     #get settings from database
644     all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
645     "select printer_name,
646     port,
647     ip,
648     share
649     from cfg_printers where serial='${ALX_SERIAL}'")
650    
651     #split'em up and put in an array
652     declare -i i=0
653     declare -i k=0
654    
655     if [ -n "${all}" ]
656     then
657     for x in ${all}
658     do
659     ((k++))
660     DB_PRINTER[${i}]="${DB_PRINTER[${i}]} ${x}"
661     if [ ${k} -eq 4 ]
662     then
663     ((i++))
664     #reset $k
665     declare -i k=0
666     fi
667     done
668     count=${i}
669     else
670     count=0
671     fi
672    
673     #echo settings
674     echo "Number of new printers: ${count}"
675     for ((i=0; i < count; i++))
676     do
677     echo "${i} printer:"
678     for x in ${DB_PRINTER[${i}]}
679     do
680     echo " ${x}"
681     done
682     done
683    
684     #import settings (only if counter > 0)
685     local prnset
686    
687     #delete all printers (*always*)
688     if [ -d ${SETTINGS_TEMPLATE}/system/printing ]
689     then
690     SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
691     [ -d ${SETTINGSPATH}/delete ] && rm -rf ${SETTINGSPATH}/delete
692     install -d ${SETTINGSPATH}/delete
693     mv -f ${SETTINGS_TEMPLATE}/system/printing/* ${SETTINGSPATH}/delete
694     rm -rf ${SETTINGS_TEMPLATE}/system/printing
695    
696     #set update flag (*always*)
697     ALX_PRINTER_SETUP=true
698     fi
699    
700     if [ ${count} -gt 0 ]
701     then
702     SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
703    
704     [ ! -d ${SETTINGSPATH}/printing ] && install -d ${SETTINGSPATH}/printing
705     for ((i=0; i < count; i++))
706     do
707     declare -i k=0
708     for x in ${DB_PRINTER[${i}]}
709     do
710     prnset[${k}]=${x}
711     ((k++))
712     done
713    
714     echo "PRINTERNAME=${prnset[0]}" > ${SETTINGSPATH}/printing/${prnset[0]}
715     echo "PRINTING=${prnset[1]}" >> ${SETTINGSPATH}/printing/${prnset[0]}
716     echo "IP=${prnset[2]}" >> ${SETTINGSPATH}/printing/${prnset[0]}
717     echo "SHARE=${prnset[3]}" >> ${SETTINGSPATH}/printing/${prnset[0]}
718     done
719    
720     #set update flag (*always*)
721     ALX_PRINTER_SETUP=true
722     fi
723    
724     }
725    
726     update_system_settings(){
727     source /opt/alx-config/Configurator/config_functions.sh
728    
729     echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
730    
731     echo
732     echo "network"
733     validate_networking
734     echo
735     echo "xserver"
736     validate_xserver
737     echo
738     echo "sessions"
739     validate_sessions
740     echo
741     #echo "printers"
742     #validate_printing
743     #echo
744    
745     if [ "${ALX_NETWORK_SETUP}" == "true" ]
746     then
747     echo -e ${COLMAGENTA}"Updating network settings"${COLDEFAULT}
748     setup_modules
749     setup_network
750     fi
751    
752     if [ "${ALX_XSERVER_SETUP}" == "true" ]
753     then
754     echo -e ${COLMAGENTA}"Updating xserver settings"${COLDEFAULT}
755     setup_xfree
756     fi
757    
758     if [ "${ALX_SESSION_SETUP}" == "true" ]
759     then
760     echo -e ${COLMAGENTA}"Updating session settings"${COLDEFAULT}
761     setup_sessions
762     fi
763    
764     #if [ "${ALX_PRINTER_SETUP}" == "true" ]
765     #then
766     # echo -e ${COLMAGENTA}"Updating printer settings"${COLDEFAULT}
767     # setup_printers
768     #fi
769    
770     #clean up temp files
771     local SETTINGSPATH
772     SETTINGSPATH=${SETTINGS_TEMPLATE}/menu
773     #[ -d ${SETTINGSPATH} ] && rm -rf ${SETTINGSPATH}
774     }
775    
776     get_system_serial(){
777    
778     local CUR_IP CUR_MAC CUR_MTIME
779    
780     #check if serial file exists
781     if [ -f /etc/alx-config/serial ]
782     then
783     source /etc/alx-config/serial
784    
785     # if system is already configured, it *has* a hostname.
786     # so we take the hostname of this system here
787     source /etc/hostname
788    
789     #start preliminary networking (dhcp)
790     preliminary_network start
791    
792     CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
793     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
794     CUR_MTIME=$(date +%s)
795    
796     echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
797    
798     #nice serial output
799     $CURS_UP
800     $SET_WCOL
801     echo "[ SN: ${ALX_SERIAL} ]"
802    
803     # #is this system outdated ?
804     # #MY_HOSTNAME=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
805     # # "select hostname from cfg_serial where id='${ALX_SERIAL}'")
806     #
807     # #we do this now with the date instead of the hostname
808     # local MY_ALX_REG_DATE
809     # MY_ALX_REG_DATE=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
810     # "select mtime from client_serial where serial='${ALX_SERIAL}'")
811     #
812     # #if [ "${MY_HOSTNAME}" == "${HOSTNAME}" ]
813     # if [ "${MY_ALX_REG_DATE}" == "${ALX_REG_DATE}" ]
814     # then
815     # #set ALX_STATE to ok so everybody that everything was ok
816     # ALX_STATE=ok
817     #
818     # evaluate_retval
819     # else
820     # #print false (works only if this is the first statement here)
821     # evaluate_retval
822     #
823     # #set ALX_STATE to error so everybody sees there was an error
824     # ALX_STATE=error
825     # fi
826    
827     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
828     then
829     ALX_STATE="ok"
830     else
831     ALX_STATE="invalid serial"
832     fi
833    
834     else
835     #run hardware detection
836     echo
837     echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}
838     ALX_HW_DETECT=true
839     /etc/init.d/hwdetect start
840    
841     #set hostname to alx_default_hostname
842     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
843     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
844    
845     #update the hostname on the system for sure
846     echo "HOSTNAME=${HOSTNAME}" > /etc/hostname
847    
848     #start preliminary networking (dhcp)
849     preliminary_network start
850    
851     CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
852     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
853     CUR_MTIME=$(date +%s)
854    
855     echo -e ${COLOREDSTAR} "Trying to get new serial ..."
856    
857     #request new serial
858     #ALX_REG_DATE="$(date +%F)"
859    
860     #we're using the mtime now (better for vaildating the serial)
861     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
862     "insert into client_serials(
863     mtime,
864     mac
865     )
866     values(
867     '${CUR_MTIME}',
868     '${CUR_MAC}'
869     );"
870    
871     #then validate and retrieve serial
872    
873     ### warning must be changed that only the LAST ID will be fetched, ###
874     ### or you get error if the computer name and date are the same ###
875     ### you have more then one serial number than ###
876    
877     #not 100% working may get more than *one* id
878     #ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
879     # "select id from cfg_serial where datum='${ALX_REG_DATE}' and hostname='${HOSTNAME}'")
880    
881     #select highest id only (added max)
882     ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
883     "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'")
884    
885     if [ "${ALX_SERIAL}" != NULL ]
886     then
887     #nice serial output
888     $CURS_UP
889     $SET_WCOL
890     echo "[ SN: ${ALX_SERIAL} ]"
891    
892     #set ALX_STATE to ok so everybody that everything was ok
893     ALX_STATE=ok
894    
895     echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alx-config/serial
896     echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alx-config/serial
897    
898     evaluate_retval
899     else
900     #print false (works only if this is the first statement here)
901     evaluate_retval
902    
903     #set ALX_STATE to error so everybody sees there was an error
904     ALX_STATE=error
905    
906     #show an error that no new serial was found
907     #nice serial output
908     $CURS_UP
909     $SET_WCOL
910     echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
911     fi
912     fi
913    
914     #write current state to temp file
915     echo "ALX_STATE=${ALX_STATE}" > /etc/alx-config/state/state
916     }
917    
918    
919     check_is_configured() {
920     if [ -f /etc/alx-config/state/configured ]
921     then
922     export ALX_CONFIGURED=true
923     else
924     export ALX_CONFIGURED=false
925     fi
926     }
927    
928    
929     # imports current settings to the database resolved by the hardware detection
930     import_settings_to_db() {
931     #note: networking is always 'dhcp' if hw was autodetected
932     #note: default_domain/hostname is set in config.rc
933    
934     #to be safe, we do some sanity checks
935     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
936     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
937    
938     #vars used by hwdetect
939     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
940     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
941     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
942    
943     #get setting from hwdetect
944     source /etc/sysconfig/hwsetup/knoppix
945     source /etc/sysconfig/hwsetup/mouse
946    
947     echo
948     echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
949    
950     #network
951     echo -e " Network settings ..."
952     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
953     "insert into cfg_network(
954     hostname,
955     serial,
956     module,
957     domain,
958     networking
959     )
960     values(
961     '${ALX_DEFAULT_HOSTNAME}',
962     '${ALX_SERIAL}',
963     '${NETCARD_DRIVER}',
964     '${ALX_DEFAULT_DOMAIN}',
965     'dhcp'
966     );"
967     evaluate_retval
968    
969     #xserver
970     echo -e " Graphic settings ..."
971     #xserver general
972     ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
973     "insert into cfg_graphic(
974     serial,
975     module,
976     resolution,
977     depth
978     )
979     values(
980     '${ALX_SERIAL}',
981     '${XMODULE}',
982     '1024x768',
983     '16'
984     );";
985     #xserver monitor
986     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
987     "insert into cfg_monitor(
988     serial,
989     vendor,
990     model,
991     hsync,
992     vrefresh
993     )
994     values(
995     '${ALX_SERIAL}',
996     'Aamazing',
997     'CM-1528-FS',
998     '28-64',
999     '47-104'
1000     );";
1001    
1002     # input
1003     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
1004     "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');";)
1005     evaluate_retval
1006     }
1007    
1008     # imports current settings to the local system resolved by the hardware detection
1009     import_settings_local(){
1010     #note: networking is always 'dhcp' if hw was autodetected
1011     #note: default_domain/hostname is set in config.rc
1012    
1013     #to be safe, we do some sanity checks
1014     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
1015     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
1016    
1017     #vars used by hwdetect
1018     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
1019     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
1020     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
1021    
1022    
1023     #get setting from hwdetect
1024     source /etc/sysconfig/hwsetup/knoppix
1025     source /etc/sysconfig/hwsetup/mouse
1026    
1027     echo
1028     echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
1029    
1030    
1031     #allready configured, no update needed so we put it to system
1032     SETTINGSPATH=${SETTINGS_TEMPLATE}/system
1033    
1034    
1035     #network
1036     echo -e " Network settings ..."
1037    
1038     [ ! -d ${SETTINGSPATH}/modules ] && install -d ${SETTINGSPATH}/modules
1039     echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules/modules
1040    
1041     [ ! -d ${SETTINGSPATH}/network ] && install -d ${SETTINGSPATH}/network
1042     ( echo "${ALX_DEFAULT_HOSTNAME}" > ${SETTINGSPATH}/network/hostname;
1043     echo "${ALX_DEFAULT_DOMAIN}" > ${SETTINGSPATH}/network/domain;
1044     echo "dhcp" > ${SETTINGSPATH}/network/networking )
1045     evaluate_retval
1046    
1047    
1048     #xserver
1049     echo -e " Graphic settings ..."
1050    
1051     [ ! -d ${SETTINGSPATH}/vga ] && install -d ${SETTINGSPATH}/vga
1052     [ ! -d ${SETTINGSPATH}/mouse ] && install -d ${SETTINGSPATH}/mouse
1053     [ ! -d ${SETTINGSPATH}/monitor ] && install -d ${SETTINGSPATH}/monitor
1054     ( echo "${XMODULE}" > ${SETTINGSPATH}/vga/vga;
1055     echo "16" > ${SETTINGSPATH}/vga/vgadepth;
1056     echo "1024x768" > ${SETTINGSPATH}/vga/vgares;
1057     echo "${XMOUSETYPE}" > ${SETTINGSPATH}/mouse/mouse;
1058     echo "myvendor=\"Aamazing\"" > ${SETTINGSPATH}/monitor/monitor;
1059     echo "mymodel=\"CM-1528-FS\"" >> ${SETTINGSPATH}/monitor/monitor;
1060     echo "hsync=\"28-64\"" >> ${SETTINGSPATH}/monitor/monitor;
1061     echo "vref=\"47-104\"" >> ${SETTINGSPATH}/monitor/monitor;)
1062     evaluate_retval
1063    
1064     #set system state to 'already configured'
1065     touch /etc/alx-config/state/configured
1066     }
1067    
1068     #start|stop
1069     preliminary_network(){
1070     local module
1071    
1072     if [ -f /etc/alx-config/state/configured ]
1073     then
1074     #get module name
1075     module=$(cat ${SETTINGS_TEMPLATE}/system/modules/modules)
1076     modprobe ${module}
1077     else
1078     #vars used by hwdetect
1079     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
1080     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
1081    
1082     #get setting from hwdetect
1083     source /etc/sysconfig/hwsetup/knoppix
1084     modprobe ${NETCARD_DRIVER}
1085     fi
1086    
1087     case $1 in
1088     start)
1089     # keeping like always safe:
1090     # no network should be startet here,
1091     # so we can delete all pid files if one exists
1092     if ps -A|grep dhcpcd > /dev/null
1093     then
1094     echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT}
1095     dhcpcd -k
1096     sleep 1
1097     else
1098     rm -f /var/run/dhcpcd-eth?.pid
1099     fi
1100    
1101     echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
1102     #dhcpcd &> /dev/null #&& echo "ok" || echo "false"
1103    
1104     # aka_fix ########################################
1105     ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up
1106     route del default gw 128.20.50.13 &> /dev/null
1107     route add default gw 128.20.50.21 &> /dev/null
1108     echo "nameserver 128.20.50.21" > /etc/resolv.conf
1109     ##################################################
1110     evaluate_retval
1111     ;;
1112     stop)
1113     echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}
1114     ifconfig eth0 down
1115     if ps -A|grep dhcpcd > /dev/null
1116     then
1117     #echo -en ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}
1118     dhcpcd -z &> /dev/null
1119     fi
1120     evaluate_retval
1121     ;;
1122     *)
1123     echo "Usage: preliminary_network {start|stop}"
1124     ;;
1125     esac
1126     }
1127    
1128     case $1 in
1129     start)
1130     #retrieve or validate current serial
1131     get_system_serial
1132     if [ "${ALX_HW_DETECT}" == "true" ]
1133     then
1134     import_settings_to_db
1135     import_settings_local
1136     fi
1137    
1138     #now setup system configuration
1139     #alx_setup_or_whatever_it_will_be_called()
1140     [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings
1141    
1142     #stop at last the preliminary networking (dhcp)
1143     preliminary_network stop
1144     ;;
1145    
1146     stop)
1147     #unset_alx_connected #--> now in alxsetstate-rc6
1148     # ! important !: del systemstate
1149     [ -f /etc/alx-config/state/state ] && rm /etc/alx-config/state/state
1150     sleep 0.1
1151     ;;
1152     *)
1153     echo "Usage: $0 {start|stop} ..."
1154     ;;
1155     esac

Properties

Name Value
svn:executable *