Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 231 - (hide annotations) (download)
Wed Mar 9 00:25:57 2005 UTC (19 years, 2 months ago) by niro
File size: 10782 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 231 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.6 2005-03-09 00:25:57 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     #start preliminary networking (dhcp)
141 niro 221 preliminary_network start
142 niro 226
143 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
144     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
145     CUR_MTIME=$(date +%s)
146 niro 226
147 niro 221 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
148 niro 226
149 niro 221 #nice serial output
150     $CURS_UP
151     $SET_WCOL
152     echo "[ SN: ${ALX_SERIAL} ]"
153    
154     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
155     then
156     ALX_STATE="ok"
157     else
158     ALX_STATE="invalid serial"
159     fi
160    
161     else
162     #run hardware detection
163     echo
164     echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}
165     ALX_HW_DETECT=true
166     /etc/init.d/hwdetect start
167 niro 226
168 niro 221 #set hostname to alx_default_hostname
169     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
170     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
171 niro 226
172 niro 221 #update the hostname on the system for sure
173 niro 230 echo "${HOSTNAME}" > /etc/hostname
174 niro 226
175 niro 221 #start preliminary networking (dhcp)
176     preliminary_network start
177 niro 226
178 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
179     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
180     CUR_MTIME=$(date +%s)
181 niro 226
182 niro 221 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
183 niro 226
184 niro 221 #request new serial
185     #ALX_REG_DATE="$(date +%F)"
186 niro 226
187 niro 221 #we're using the mtime now (better for vaildating the serial)
188     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
189     "insert into client_serials(
190     mtime,
191     mac
192     )
193     values(
194     '${CUR_MTIME}',
195     '${CUR_MAC}'
196     );"
197 niro 226
198 niro 221 #then validate and retrieve serial
199 niro 226
200 niro 221 ### warning must be changed that only the LAST ID will be fetched, ###
201     ### or you get error if the computer name and date are the same ###
202 niro 226 ### you have more than one serial number then ###
203    
204 niro 221 #select highest id only (added max)
205     ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
206     "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'")
207    
208     if [ "${ALX_SERIAL}" != NULL ]
209     then
210     #nice serial output
211     $CURS_UP
212     $SET_WCOL
213     echo "[ SN: ${ALX_SERIAL} ]"
214 niro 226
215 niro 221 #set ALX_STATE to ok so everybody that everything was ok
216     ALX_STATE=ok
217 niro 226
218     echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
219     echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial
220    
221 niro 221 evaluate_retval
222     else
223     #print false (works only if this is the first statement here)
224     evaluate_retval
225 niro 226
226 niro 221 #set ALX_STATE to error so everybody sees there was an error
227     ALX_STATE=error
228 niro 226
229 niro 221 #show an error that no new serial was found
230     #nice serial output
231     $CURS_UP
232     $SET_WCOL
233     echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
234     fi
235     fi
236 niro 226
237 niro 221 #write current state to temp file
238 niro 226 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
239 niro 221 }
240    
241    
242     check_is_configured() {
243 niro 226 if [ -f /etc/alxconfig-ng/state/configured ]
244 niro 221 then
245     export ALX_CONFIGURED=true
246     else
247     export ALX_CONFIGURED=false
248     fi
249     }
250    
251    
252     # imports current settings to the database resolved by the hardware detection
253     import_settings_to_db() {
254     #note: networking is always 'dhcp' if hw was autodetected
255     #note: default_domain/hostname is set in config.rc
256 niro 229
257 niro 221 #to be safe, we do some sanity checks
258     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
259     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
260 niro 229
261 niro 221 #vars used by hwdetect
262     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
263     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
264     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
265 niro 229
266 niro 221 #get setting from hwdetect
267     source /etc/sysconfig/hwsetup/knoppix
268     source /etc/sysconfig/hwsetup/mouse
269 niro 229
270 niro 221 echo
271     echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
272 niro 229
273 niro 221 #network
274     echo -e " Network settings ..."
275     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
276     "insert into cfg_network(
277     hostname,
278     serial,
279     module,
280     domain,
281     networking
282     )
283     values(
284     '${ALX_DEFAULT_HOSTNAME}',
285     '${ALX_SERIAL}',
286     '${NETCARD_DRIVER}',
287     '${ALX_DEFAULT_DOMAIN}',
288     'dhcp'
289     );"
290     evaluate_retval
291 niro 229
292 niro 221 #xserver
293     echo -e " Graphic settings ..."
294     #xserver general
295     ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
296     "insert into cfg_graphic(
297     serial,
298     module,
299     resolution,
300 niro 229 depth,
301     monitorid
302 niro 221 )
303     values(
304     '${ALX_SERIAL}',
305     '${XMODULE}',
306     '1024x768',
307 niro 229 '16',
308     '0'
309 niro 221 );";
310 niro 229
311 niro 221 # input
312     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
313     "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');";)
314     evaluate_retval
315     }
316    
317     # imports current settings to the local system resolved by the hardware detection
318 niro 226 # we only need the network settings
319 niro 221 import_settings_local(){
320     #note: networking is always 'dhcp' if hw was autodetected
321     #note: default_domain/hostname is set in config.rc
322 niro 226
323 niro 221 #to be safe, we do some sanity checks
324     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
325     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
326 niro 226
327 niro 221 #vars used by hwdetect
328     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
329     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
330     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
331    
332     #get setting from hwdetect
333     source /etc/sysconfig/hwsetup/knoppix
334 niro 226
335 niro 221 echo
336     echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
337    
338 niro 226 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
339     echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
340     evaluate_retval
341 niro 221
342     #set system state to 'already configured'
343 niro 226 touch /etc/alxconfig-ng/state/configured
344 niro 221 }
345    
346     #start|stop
347     preliminary_network(){
348     local module
349 niro 226
350     if [ -f /etc/alxconfig-ng/state/configured ]
351 niro 221 then
352     #get module name
353 niro 226 module=$(cat ${SETTINGSPATH}/modules)
354 niro 221 modprobe ${module}
355     else
356     #vars used by hwdetect
357     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
358     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
359 niro 226
360 niro 221 #get setting from hwdetect
361     source /etc/sysconfig/hwsetup/knoppix
362     modprobe ${NETCARD_DRIVER}
363     fi
364 niro 226
365 niro 221 case $1 in
366     start)
367     # keeping like always safe:
368     # no network should be startet here,
369     # so we can delete all pid files if one exists
370     if ps -A|grep dhcpcd > /dev/null
371     then
372     echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT}
373     dhcpcd -k
374     sleep 1
375     else
376     rm -f /var/run/dhcpcd-eth?.pid
377     fi
378 niro 226
379 niro 221 echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
380 niro 226 dhcpcd &> /dev/null
381    
382 niro 221 # aka_fix ########################################
383 niro 226 #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up
384     #route del default gw 128.20.50.13 &> /dev/null
385     #route add default gw 128.20.50.21 &> /dev/null
386     #echo "nameserver 128.20.50.21" > /etc/resolv.conf
387 niro 221 ##################################################
388 niro 226
389 niro 221 evaluate_retval
390     ;;
391 niro 226
392 niro 221 stop)
393     echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}
394     ifconfig eth0 down
395     if ps -A|grep dhcpcd > /dev/null
396     then
397     dhcpcd -z &> /dev/null
398     fi
399     evaluate_retval
400     ;;
401 niro 226
402 niro 221 *)
403     echo "Usage: preliminary_network {start|stop}"
404     ;;
405     esac
406     }
407    
408     case $1 in
409     start)
410     #retrieve or validate current serial
411     get_system_serial
412     if [ "${ALX_HW_DETECT}" == "true" ]
413     then
414     import_settings_to_db
415     import_settings_local
416     fi
417    
418     #now setup system configuration
419     #alx_setup_or_whatever_it_will_be_called()
420     [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings
421    
422     #stop at last the preliminary networking (dhcp)
423     preliminary_network stop
424     ;;
425    
426     stop)
427     #unset_alx_connected #--> now in alxsetstate-rc6
428     # ! important !: del systemstate
429 niro 226 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
430 niro 221 sleep 0.1
431     ;;
432     *)
433     echo "Usage: $0 {start|stop} ..."
434     ;;
435     esac

Properties

Name Value
svn:executable *