Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 231 - (show annotations) (download)
Wed Mar 9 00:25:57 2005 UTC (19 years, 1 month ago) by niro
File size: 10782 byte(s)
fixed hostname

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.6 2005-03-09 00:25:57 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 #start preliminary networking (dhcp)
141 preliminary_network start
142
143 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
147 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
148
149 #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
168 #set hostname to alx_default_hostname
169 [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
170 HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
171
172 #update the hostname on the system for sure
173 echo "${HOSTNAME}" > /etc/hostname
174
175 #start preliminary networking (dhcp)
176 preliminary_network start
177
178 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
182 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
183
184 #request new serial
185 #ALX_REG_DATE="$(date +%F)"
186
187 #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
198 #then validate and retrieve serial
199
200 ### 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 ### you have more than one serial number then ###
203
204 #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
215 #set ALX_STATE to ok so everybody that everything was ok
216 ALX_STATE=ok
217
218 echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
219 echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial
220
221 evaluate_retval
222 else
223 #print false (works only if this is the first statement here)
224 evaluate_retval
225
226 #set ALX_STATE to error so everybody sees there was an error
227 ALX_STATE=error
228
229 #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
237 #write current state to temp file
238 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
239 }
240
241
242 check_is_configured() {
243 if [ -f /etc/alxconfig-ng/state/configured ]
244 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
257 #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
261 #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
266 #get setting from hwdetect
267 source /etc/sysconfig/hwsetup/knoppix
268 source /etc/sysconfig/hwsetup/mouse
269
270 echo
271 echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
272
273 #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
292 #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 depth,
301 monitorid
302 )
303 values(
304 '${ALX_SERIAL}',
305 '${XMODULE}',
306 '1024x768',
307 '16',
308 '0'
309 );";
310
311 # 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 # we only need the network settings
319 import_settings_local(){
320 #note: networking is always 'dhcp' if hw was autodetected
321 #note: default_domain/hostname is set in config.rc
322
323 #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
327 #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
335 echo
336 echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
337
338 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
339 echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
340 evaluate_retval
341
342 #set system state to 'already configured'
343 touch /etc/alxconfig-ng/state/configured
344 }
345
346 #start|stop
347 preliminary_network(){
348 local module
349
350 if [ -f /etc/alxconfig-ng/state/configured ]
351 then
352 #get module name
353 module=$(cat ${SETTINGSPATH}/modules)
354 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
360 #get setting from hwdetect
361 source /etc/sysconfig/hwsetup/knoppix
362 modprobe ${NETCARD_DRIVER}
363 fi
364
365 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
379 echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
380 dhcpcd &> /dev/null
381
382 # aka_fix ########################################
383 #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 ##################################################
388
389 evaluate_retval
390 ;;
391
392 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
402 *)
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 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
430 sleep 0.1
431 ;;
432 *)
433 echo "Usage: $0 {start|stop} ..."
434 ;;
435 esac

Properties

Name Value
svn:executable *