Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 295 - (hide annotations) (download)
Thu Aug 18 07:39:00 2005 UTC (18 years, 8 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 15103 byte(s)
fixed some logic errors

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

Properties

Name Value
svn:executable *