Magellan Linux

Annotation of /alx-src/branches/alxconf-060/init.d/alxsettings

Parent Directory Parent Directory | Revision Log Revision Log


Revision 282 - (hide annotations) (download)
Wed Aug 17 21:19:52 2005 UTC (18 years, 8 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 15163 byte(s)
added to major functions: do not change any settings if mysql server is not reachable and support re-check of the client hardware.
also set dhcp timeout of the preliminary network to 10 seconds

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 282 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.15 2005-08-17 21:19:52 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 niro 282 # mysql settings
28 niro 226 source /etc/alxconfig-ng/config.rc
29 niro 282
30     # helper functions
31 niro 226 source /usr/lib/alxconfig-ng/functions/mysqlfunctions
32 niro 227 source /usr/lib/alxconfig-ng/functions/serial_functions
33 niro 257 source /usr/lib/alxconfig-ng/functions/config_modules
34 niro 226 source /usr/lib/alxconfig-ng/functions/config_network
35     source /usr/lib/alxconfig-ng/functions/config_printers
36 niro 239 source /usr/lib/alxconfig-ng/functions/config_sessions
37 niro 226 source /usr/lib/alxconfig-ng/functions/config_x11
38 niro 248 source /usr/lib/alxconfig-ng/functions/config_auth
39 niro 252 source /usr/lib/alxconfig-ng/functions/config_ssh_auth
40 niro 221
41 niro 282 # check if mysql is available
42 niro 221 [ -x /usr/bin/mysql ] && MYSQL_ALX=true
43    
44 niro 282 # other needed vars
45 niro 221 ALX_HW_DETECT=false
46 niro 282 ALX_FORCED_RECHECK=false
47 niro 221
48 niro 282 # unset vars which may kill us
49 niro 221 unset ALX_SERIAL ALX_STATE
50    
51    
52 niro 282 # setup needed directories
53 niro 226 [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
54 niro 221
55    
56 niro 226 update_system_settings(){
57     echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
58 niro 221
59 niro 257 # get the modules settings
60     # ! is the first thing that must be configured !
61     config_modules
62    
63 niro 226 # imports network settings from db
64     config_networking
65    
66     # imports x11 settings from db
67     config_x11
68    
69 niro 248 # imports session settings from db
70 niro 239 config_sessions
71 niro 226
72     # imports printer settings from db
73     config_printing
74 niro 248
75     # imports auth settings from db
76     config_auth
77 niro 252
78     # exchange ssh rsa keys
79 niro 265 HOME=/root config_ssh_auth
80 niro 221 }
81    
82     get_system_serial(){
83    
84     local CUR_IP CUR_MAC CUR_MTIME
85    
86 niro 282 # check if serial file exists
87     if [ -f /etc/alxconfig-ng/serial ] && [ ! -f /hardware-auto-detection ]
88 niro 221 then
89 niro 226 source /etc/alxconfig-ng/serial
90    
91 niro 282 # doing this now before this function gets called
92     # start preliminary networking (dhcp)
93     # preliminary_network start
94 niro 226
95 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
96     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
97     CUR_MTIME=$(date +%s)
98 niro 226
99 niro 221 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
100 niro 226
101 niro 282 # nice serial output
102 niro 221 $CURS_UP
103     $SET_WCOL
104     echo "[ SN: ${ALX_SERIAL} ]"
105    
106     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
107     then
108     ALX_STATE="ok"
109     else
110     ALX_STATE="invalid serial"
111     fi
112    
113     else
114 niro 282 # run hardware detection
115 niro 221 echo
116 niro 282 if [ -f /hardware-auto-detection ]
117     then
118     echo -e ${COLMAGENTA}"Hardware-Auto-Detection forced by system-administrator"${COLDEFAULT}
119     else
120     echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}
121     fi
122 niro 221 ALX_HW_DETECT=true
123     /etc/init.d/hwdetect start
124 niro 226
125 niro 282 # set hostname to alx_default_hostname
126     # use old hostname if this is a forced re-check
127     [ -f /hardware-auto-detection ] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)"
128 niro 221 [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
129     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
130 niro 226
131 niro 282 # update the hostname on the system for sure
132 niro 230 echo "${HOSTNAME}" > /etc/hostname
133 niro 226
134 niro 282 # start preliminary networking (dhcp)
135 niro 221 preliminary_network start
136 niro 226
137 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
138     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
139     CUR_MTIME=$(date +%s)
140 niro 226
141 niro 282 # abort now if this is a forced re-check
142     if [ -f /hardware-auto-detection ]
143     then
144     # but first check the serial
145     source /etc/alxconfig-ng/serial
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     # write current state to temp file
162     echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
163     rm /hardware-auto-detection
164    
165     # now export ALX_FORCED_RECHECK=true
166     # that the setting will be updated not inserted !
167     export ALX_FORCED_RECHECK=true
168     return 0
169     fi
170    
171 niro 221 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
172 niro 226
173 niro 282 # request new serial
174     # ALX_REG_DATE="$(date +%F)"
175 niro 226
176 niro 282 # we're using the mtime now (better for vaildating the serial)
177 niro 221 mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
178     "insert into client_serials(
179     mtime,
180     mac
181     )
182     values(
183     '${CUR_MTIME}',
184     '${CUR_MAC}'
185     );"
186 niro 226
187 niro 282 # then validate and retrieve serial
188 niro 226
189 niro 221 ### warning must be changed that only the LAST ID will be fetched, ###
190     ### or you get error if the computer name and date are the same ###
191 niro 226 ### you have more than one serial number then ###
192    
193 niro 282 # select highest id only (added max)
194 niro 221 ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
195     "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'")
196    
197     if [ "${ALX_SERIAL}" != NULL ]
198     then
199 niro 282 # nice serial output
200 niro 221 $CURS_UP
201     $SET_WCOL
202     echo "[ SN: ${ALX_SERIAL} ]"
203 niro 226
204 niro 282 # set ALX_STATE to ok so everybody that everything was ok
205 niro 221 ALX_STATE=ok
206 niro 226
207     echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
208     echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial
209    
210 niro 221 evaluate_retval
211     else
212 niro 282 # print false (works only if this is the first statement here)
213 niro 221 evaluate_retval
214 niro 226
215 niro 282 # set ALX_STATE to error so everybody sees there was an error
216 niro 221 ALX_STATE=error
217 niro 226
218 niro 282 # show an error that no new serial was found
219     # nice serial output
220 niro 221 $CURS_UP
221     $SET_WCOL
222     echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
223     fi
224     fi
225 niro 226
226 niro 282 # write current state to temp file
227 niro 226 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
228 niro 221 }
229    
230    
231     check_is_configured() {
232 niro 226 if [ -f /etc/alxconfig-ng/state/configured ]
233 niro 221 then
234     export ALX_CONFIGURED=true
235     else
236     export ALX_CONFIGURED=false
237     fi
238     }
239    
240    
241     # imports current settings to the database resolved by the hardware detection
242     import_settings_to_db() {
243 niro 282 # note: networking is always 'dhcp' if hw was autodetected
244     # note: default_domain/hostname is set in config.rc
245 niro 229
246 niro 282 # to be safe, we do some sanity checks
247 niro 221 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
248     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
249 niro 229
250 niro 282 # vars used by hwdetect
251 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
252     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
253     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
254 niro 229
255 niro 282 # get setting from hwdetect
256 niro 221 source /etc/sysconfig/hwsetup/knoppix
257     source /etc/sysconfig/hwsetup/mouse
258 niro 229
259 niro 221 echo
260     echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
261 niro 229
262 niro 282 # network
263 niro 221 echo -e " Network settings ..."
264     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
265     "insert into cfg_network(
266     hostname,
267     serial,
268     module,
269     domain,
270     networking
271     )
272     values(
273     '${ALX_DEFAULT_HOSTNAME}',
274     '${ALX_SERIAL}',
275     '${NETCARD_DRIVER}',
276     '${ALX_DEFAULT_DOMAIN}',
277     'dhcp'
278     );"
279     evaluate_retval
280 niro 229
281 niro 282 # xserver
282 niro 221 echo -e " Graphic settings ..."
283 niro 282 # xserver general
284 niro 221 ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
285     "insert into cfg_graphic(
286     serial,
287     module,
288     resolution,
289 niro 229 depth,
290     monitorid
291 niro 221 )
292     values(
293     '${ALX_SERIAL}',
294     '${XMODULE}',
295     '1024x768',
296 niro 229 '16',
297     '0'
298 niro 252 );"; )
299     evaluate_retval
300 niro 229
301 niro 221 # input
302 niro 252 echo -e " Input settings ..."
303     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
304     "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');"
305 niro 221 evaluate_retval
306 niro 252
307     # auth
308     echo -e " Authentifcation settings ..."
309     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
310     "insert into client_auth(
311     serial,
312     username,
313     shell,
314     vnc,
315     samba,
316     station
317     )
318     values(
319     '${ALX_SERIAL}',
320     '${ALX_UNPRIV_USER}',
321     '',
322     '',
323     '',
324     ''
325     );"
326     evaluate_retval
327    
328 niro 263 # exchange ssh rsa keys - the first boot needs this !
329     # or no reboot will work via the webadmin
330     echo -e " SSH authentifcation settings ..."
331 niro 264 HOME=/root config_ssh_auth
332 niro 263 evaluate_retval
333    
334 niro 252 # input
335     echo -e " Autostart settings ..."
336     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
337     "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');"
338     evaluate_retval
339 niro 221 }
340    
341 niro 282 # imports current settings to the database resolved by the hardware detection
342     update_settings_in_db() {
343     # note: networking is always 'dhcp' if hw was autodetected
344     # note: default_domain/hostname is set in config.rc or exported
345     # note: we updating only hardware settings here !
346    
347     # to be safe, we do some sanity checks
348     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
349     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
350    
351     # vars used by hwdetect
352     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
353     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
354     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
355    
356     # get setting from hwdetect
357     source /etc/sysconfig/hwsetup/knoppix
358     source /etc/sysconfig/hwsetup/mouse
359    
360     echo
361     echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT}
362    
363     # network
364     echo -e " Network settings ..."
365    
366     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
367     "update cfg_network set
368     hostname='${ALX_DEFAULT_HOSTNAME}',
369     module='${NETCARD_DRIVER}',
370     domain='${ALX_DEFAULT_DOMAIN}',
371     networking='dhcp'
372     where serial=${ALX_SERIAL};"
373     evaluate_retval
374    
375     # xserver
376     echo -e " Graphic settings ..."
377     # xserver general
378     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
379     "update cfg_graphic set
380     module='${XMODULE}',
381     resolution='1024x768',
382     depth='16',
383     monitorid='0'
384     where serial=${ALX_SERIAL};"
385     evaluate_retval
386    
387     # input
388     echo -e " Input settings ..."
389     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
390     "update cfg_input set
391     mouse='${XMOUSETYPE}'
392     where serial=${ALX_SERIAL};"
393     evaluate_retval
394     }
395    
396 niro 221 # imports current settings to the local system resolved by the hardware detection
397 niro 226 # we only need the network settings
398 niro 221 import_settings_local(){
399 niro 282 # note: networking is always 'dhcp' if hw was autodetected
400     # note: default_domain/hostname is set in config.rc
401 niro 226
402 niro 282 # to be safe, we do some sanity checks
403 niro 221 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
404     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
405 niro 226
406 niro 282 # vars used by hwdetect
407 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
408     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
409     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
410    
411 niro 282 # get setting from hwdetect
412 niro 221 source /etc/sysconfig/hwsetup/knoppix
413 niro 226
414 niro 221 echo
415     echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
416    
417 niro 226 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
418     echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
419     evaluate_retval
420 niro 221
421 niro 282 # set system state to 'already configured'
422 niro 226 touch /etc/alxconfig-ng/state/configured
423 niro 252
424 niro 275 # create a fresh fluxbox directory
425     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
426     install -d ${ALX_UNPRIV_HOME}/.fluxbox
427    
428     # now generate fluxbox config files
429    
430     # fluxbox main config
431     cat ${ALX_SKELETONS}/fluxbox/init \
432     > ${ALX_UNPRIV_HOME}/.fluxbox/init
433    
434     # fluxbox menu header
435     cat ${ALX_SKELETONS}/fluxbox/menu.header \
436     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
437    
438     # add a newline (maybe there is no crlf in the header)
439     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
440    
441     # fluxbox menu footer
442     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
443     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
444    
445     # add a newline (maybe there is no crlf in the footer)
446     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
447    
448 niro 282 # set correct permissions
449     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
450     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
451     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
452     chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop
453     chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc
454    
455 niro 252 # default passwords are bad
456     #usermod -p $(perl -e "printf(crypt('foobar','AD'))") root
457     #usermod -p $(perl -e "printf(crypt('foobar','AD'))") ${ALX_UNPRIV_USER}
458     #smbpasswd -a root foobar
459 niro 221 }
460    
461 niro 282 # start|stop
462 niro 221 preliminary_network(){
463     local module
464 niro 226
465     if [ -f /etc/alxconfig-ng/state/configured ]
466 niro 221 then
467 niro 282 # get module name
468 niro 226 module=$(cat ${SETTINGSPATH}/modules)
469 niro 221 modprobe ${module}
470     else
471 niro 282 # vars used by hwdetect
472 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
473     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
474 niro 226
475 niro 282 # get setting from hwdetect
476 niro 221 source /etc/sysconfig/hwsetup/knoppix
477     modprobe ${NETCARD_DRIVER}
478     fi
479 niro 226
480 niro 221 case $1 in
481     start)
482     # keeping like always safe:
483     # no network should be startet here,
484     # so we can delete all pid files if one exists
485     if ps -A|grep dhcpcd > /dev/null
486     then
487     echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT}
488     dhcpcd -k
489     sleep 1
490     else
491     rm -f /var/run/dhcpcd-eth?.pid
492     fi
493 niro 226
494 niro 221 echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
495 niro 282 # -t 10 timeout of 10 secs
496     dhcpcd -t 10 &> /dev/null
497 niro 226
498 niro 221 # aka_fix ########################################
499 niro 226 #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up
500     #route del default gw 128.20.50.13 &> /dev/null
501     #route add default gw 128.20.50.21 &> /dev/null
502     #echo "nameserver 128.20.50.21" > /etc/resolv.conf
503 niro 221 ##################################################
504 niro 226
505 niro 221 evaluate_retval
506     ;;
507 niro 226
508 niro 221 stop)
509     echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}
510     ifconfig eth0 down
511     if ps -A|grep dhcpcd > /dev/null
512     then
513     dhcpcd -z &> /dev/null
514     fi
515     evaluate_retval
516     ;;
517 niro 226
518 niro 221 *)
519     echo "Usage: preliminary_network {start|stop}"
520     ;;
521     esac
522     }
523    
524     case $1 in
525     start)
526 niro 282 # start preliminary networking (dhcp)
527     preliminary_network start
528    
529     # check if mysql server is reachable
530     # if not abort this script
531     if ! reach_mysql_server
532     then
533     preliminary_network stop
534     exit 1
535     fi
536    
537     # retrieve or validate current serial
538 niro 221 get_system_serial
539 niro 282 if [[ ${ALX_HW_DETECT} = true ]]
540 niro 221 then
541 niro 282 if [[ ${ALX_FORCED_RECHECK} = true ]]
542     then
543     update_settings_in_db
544     else
545     import_settings_to_db
546     fi
547 niro 221 import_settings_local
548 niro 252
549     # here we should also exchange the ssh keys
550     # or the system cannot be rebooted after
551     # the first start via the alx-webadmin
552     config_ssh_auth
553 niro 221 fi
554 niro 252
555 niro 282 # now setup system configuration
556     # alx_setup_or_whatever_it_will_be_called()
557 niro 221 [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings
558    
559 niro 282 # stop at last the preliminary networking (dhcp)
560 niro 221 preliminary_network stop
561     ;;
562 niro 282
563 niro 221 stop)
564 niro 282 # unset_alx_connected #--> now in alxsetstate-rc6
565 niro 221 # ! important !: del systemstate
566 niro 226 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
567 niro 221 sleep 0.1
568     ;;
569     *)
570     echo "Usage: $0 {start|stop} ..."
571     ;;
572     esac
573 niro 252

Properties

Name Value
svn:executable *