Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1800 - (hide annotations) (download)
Thu Apr 14 19:29:35 2011 UTC (13 years, 1 month ago) by niro
File size: 24173 byte(s)
created 0.6.x branch
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 368 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.27 2005-10-11 12:10:15 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 1582 source /usr/lib/alxconfig-ng/functions/config_versions
41 niro 221
42 niro 282 # check if mysql is available
43 niro 221 [ -x /usr/bin/mysql ] && MYSQL_ALX=true
44    
45 niro 282 # other needed vars
46 niro 221 ALX_HW_DETECT=false
47 niro 282 ALX_FORCED_RECHECK=false
48 niro 337 ALX_RESET_SETTINGS=false
49     ALX_CONFD_NETWORKING=false
50 niro 221
51 niro 282 # unset vars which may kill us
52 niro 221 unset ALX_SERIAL ALX_STATE
53    
54    
55 niro 282 # setup needed directories
56 niro 226 [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
57 niro 221
58    
59 niro 337 # read_cmdline ${item}
60     read_cmdline()
61     {
62     local i
63    
64     for i in $(< /proc/cmdline)
65     do
66     [[ ${i} = $1 ]] && return 0
67     done
68    
69     return 1
70     }
71    
72     update_system_settings()
73     {
74 niro 226 echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
75 niro 221
76 niro 257 # get the modules settings
77     # ! is the first thing that must be configured !
78     config_modules
79    
80 niro 226 # imports network settings from db
81     config_networking
82    
83     # imports x11 settings from db
84     config_x11
85    
86 niro 248 # imports session settings from db
87 niro 239 config_sessions
88 niro 226
89     # imports printer settings from db
90     config_printing
91 niro 248
92     # imports auth settings from db
93     config_auth
94 niro 252
95     # exchange ssh rsa keys
96 niro 265 HOME=/root config_ssh_auth
97 niro 1582
98     # import version info
99     config_version
100 niro 221 }
101    
102 niro 337 get_system_serial()
103     {
104 niro 350 local CUR_IP CUR_MAC CUR_MTIME ALX_IFACE
105 niro 221
106 niro 350 if [[ ${ALX_CONFD_NETWORKING} = true ]]
107     then
108     ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)"
109     else
110     ALX_IFACE="eth0"
111     fi
112    
113 niro 282 # check if serial file exists
114 niro 337 if [ -f /etc/alxconfig-ng/serial ] && [[ ${ALX_FORCED_RECHECK} = false ]]
115 niro 221 then
116 niro 226 source /etc/alxconfig-ng/serial
117    
118 niro 282 # start preliminary networking (dhcp)
119 niro 295 preliminary_network start
120 niro 226
121 niro 295 # check if mysql server is reachable
122     # if not abort this script
123     if ! reach_mysql_server
124     then
125     preliminary_network stop
126     exit 1
127     fi
128    
129 niro 348 CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
130     CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
131 niro 221 CUR_MTIME=$(date +%s)
132 niro 226
133 niro 221 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
134 niro 226
135 niro 282 # nice serial output
136 niro 221 $CURS_UP
137     $SET_WCOL
138     echo "[ SN: ${ALX_SERIAL} ]"
139    
140     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
141     then
142     ALX_STATE="ok"
143     else
144 niro 307 # abort on non valid serial
145 niro 221 ALX_STATE="invalid serial"
146 niro 1616 echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state
147 niro 307 show_invalid_serial_msg
148     exit 1
149 niro 221 fi
150    
151     else
152 niro 282 # run hardware detection
153 niro 221 echo
154 niro 337 if [[ ${ALX_FORCED_RECHECK} = true ]]
155 niro 282 then
156 niro 295 echo -e ${COLMAGENTA}"Hardware autodetection forced by system-administrator"${COLDEFAULT}
157 niro 1622 # always disable CONFD_NETWORKING here
158     export ALX_CONFD_NETWORKING="false"
159 niro 282 else
160     echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}
161     fi
162 niro 221 ALX_HW_DETECT=true
163     /etc/init.d/hwdetect start
164 niro 226
165 niro 282 # set hostname to alx_default_hostname
166     # use old hostname if this is a forced re-check
167 niro 337 [[ ${ALX_FORCED_RECHECK} = true ]] && ALX_DEFAULT_HOSTNAME="$(< /etc/hostname)"
168 niro 221 [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
169     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
170 niro 226
171 niro 282 # update the hostname on the system for sure
172 niro 230 echo "${HOSTNAME}" > /etc/hostname
173 niro 226
174 niro 282 # start preliminary networking (dhcp)
175 niro 221 preliminary_network start
176 niro 226
177 niro 295 # check if mysql server is reachable
178     # if not abort this script
179     if ! reach_mysql_server
180     then
181     preliminary_network stop
182     exit 1
183     fi
184    
185 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
186     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
187     CUR_MTIME=$(date +%s)
188 niro 226
189 niro 282 # abort now if this is a forced re-check
190 niro 337 if [[ ${ALX_FORCED_RECHECK} = true ]]
191 niro 282 then
192     # but first check the serial
193     source /etc/alxconfig-ng/serial
194    
195     echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
196    
197     # nice serial output
198     $CURS_UP
199     $SET_WCOL
200     echo "[ SN: ${ALX_SERIAL} ]"
201    
202     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
203     then
204     ALX_STATE="ok"
205     else
206 niro 307 # abort on non valid serial
207 niro 282 ALX_STATE="invalid serial"
208 niro 307 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
209     show_invalid_serial_msg
210     exit 1
211 niro 282 fi
212    
213     # write current state to temp file
214 niro 1616 echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state
215 niro 337 [ -f /hardware-auto-detection ] && rm /hardware-auto-detection
216 niro 282
217     # now export ALX_FORCED_RECHECK=true
218     # that the setting will be updated not inserted !
219     export ALX_FORCED_RECHECK=true
220     return 0
221     fi
222    
223 niro 221 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
224 niro 226
225 niro 313 # request a new serial; one command now (cause must be done in the same session)
226 niro 348 ALX_SERIAL=$(mysqldo "insert into client_serials (mtime, mac) values('${CUR_MTIME}','${CUR_MAC}');
227 niro 314 select last_insert_id();")
228 niro 221
229 niro 337 if [[ ${ALX_SERIAL} != NULL ]]
230 niro 221 then
231 niro 282 # nice serial output
232 niro 221 $CURS_UP
233     $SET_WCOL
234     echo "[ SN: ${ALX_SERIAL} ]"
235 niro 226
236 niro 348 # set ALX_STATE to ok so everybody knows that everything was ok
237 niro 221 ALX_STATE=ok
238 niro 226
239 niro 1616 echo "ALX_SERIAL=\"${ALX_SERIAL}\"" > /etc/alxconfig-ng/serial
240     echo "ALX_REG_DATE=\"${CUR_MTIME}\"" >> /etc/alxconfig-ng/serial
241 niro 226
242 niro 221 evaluate_retval
243     else
244 niro 282 # print false (works only if this is the first statement here)
245 niro 221 evaluate_retval
246 niro 226
247 niro 282 # set ALX_STATE to error so everybody sees there was an error
248 niro 221 ALX_STATE=error
249 niro 226
250 niro 282 # show an error that no new serial was found
251     # nice serial output
252 niro 221 $CURS_UP
253     $SET_WCOL
254     echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
255     fi
256     fi
257 niro 226
258 niro 282 # write current state to temp file
259 niro 1616 echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state
260     echo "ALX_IFACE=\"${ALX_IFACE}\"" >> /etc/alxconfig-ng/state/state
261 niro 221 }
262    
263    
264 niro 337 check_is_configured()
265     {
266 niro 226 if [ -f /etc/alxconfig-ng/state/configured ]
267 niro 221 then
268     export ALX_CONFIGURED=true
269     else
270     export ALX_CONFIGURED=false
271     fi
272     }
273    
274    
275     # imports current settings to the database resolved by the hardware detection
276 niro 337 import_settings_to_db()
277     {
278 niro 282 # note: networking is always 'dhcp' if hw was autodetected
279     # note: default_domain/hostname is set in config.rc
280 niro 229
281 niro 282 # to be safe, we do some sanity checks
282 niro 221 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
283     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
284 niro 229
285 niro 282 # vars used by hwdetect
286 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
287     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
288     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
289 niro 229
290 niro 282 # get setting from hwdetect
291 niro 221 source /etc/sysconfig/hwsetup/knoppix
292     source /etc/sysconfig/hwsetup/mouse
293 niro 229
294 niro 221 echo
295     echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
296 niro 229
297 niro 282 # network
298 niro 221 echo -e " Network settings ..."
299 niro 337 if [[ ${ALX_CONFD_NETWORKING} = true ]]
300     then
301     # get settings
302     #source ${rc_base}/init.d/network &> /dev/null
303     for iface in $(onboot_interface_list ${network_settings}/net.*)
304     do
305     [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue
306     echo "WARNING: only importing settings for interface [ ${iface} ] !"
307     source ${network_settings}/net.${iface} || exit 1
308     NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)"
309    
310 niro 348 mysqldo "insert into cfg_network(
311 niro 337 hostname,
312     serial,
313     module,
314     domain,
315     networking,
316     netmask,
317     dns,
318     gateway,
319     broadcast,
320     ip,
321     forcemacto,
322     wireless_bitrate,
323     wireless_channel,
324     wireless_essid,
325     wireless_frequency,
326     wireless_mode,
327     wireless_nick,
328     wireless_auth_mode,
329     wireless_key_length,
330     wireless_key,
331     wireless_key_ascii
332     )
333     values(
334     '${ALX_DEFAULT_HOSTNAME}',
335     '${ALX_SERIAL}',
336     '${NETCARD_DRIVER}',
337     '${ALX_DEFAULT_DOMAIN}',
338     '${NETWORKING}',
339     '${NETMASK}',
340     '${NAMESERVER}',
341     '${GATEWAY}',
342     '${BROADCAST}',
343     '${IP}',
344     '${FORCE_MAC_TO}',
345     '${WIRELESS_BITRATE}',
346     '${WIRELESS_CHANNEL}',
347     '${WIRELESS_ESSID}',
348     '${WIRELESS_FREQUENCY}',
349     '${WIRELESS_MODE}',
350     '${WIRELESS_NICK}',
351     '${WIRELESS_AUTH_MODE}',
352     '${WIRELESS_KEY_LENGTH}',
353     '${WIRELESS_KEY}',
354     '${WIRELESS_KEY_ASCII}'
355     );"
356    
357     # only insert the *FIRST* iface
358     break
359     done
360     else
361 niro 348 mysqldo "insert into cfg_network(
362 niro 337 hostname,
363     serial,
364     module,
365     domain,
366     networking
367     )
368     values(
369     '${ALX_DEFAULT_HOSTNAME}',
370     '${ALX_SERIAL}',
371     '${NETCARD_DRIVER}',
372     '${ALX_DEFAULT_DOMAIN}',
373     'dhcp'
374     );"
375     fi
376 niro 221 evaluate_retval
377 niro 229
378 niro 282 # xserver
379 niro 221 echo -e " Graphic settings ..."
380 niro 282 # xserver general
381 niro 348 ( mysqldo "insert into cfg_graphic(
382 niro 221 serial,
383     module,
384     resolution,
385 niro 229 depth,
386 niro 1582 refresh_rate
387 niro 221 )
388     values(
389     '${ALX_SERIAL}',
390     '${XMODULE}',
391     '1024x768',
392 niro 229 '16',
393 niro 1582 '60'
394 niro 252 );"; )
395     evaluate_retval
396 niro 229
397 niro 221 # input
398 niro 252 echo -e " Input settings ..."
399 niro 348 mysqldo "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');"
400 niro 221 evaluate_retval
401 niro 252
402     # auth
403 niro 348 echo -e " Authentification settings ..."
404     mysqldo "insert into client_auth(
405 niro 252 serial,
406     username,
407     shell,
408     vnc,
409     samba,
410     station
411     )
412     values(
413     '${ALX_SERIAL}',
414     '${ALX_UNPRIV_USER}',
415     '',
416     '',
417     '',
418     ''
419     );"
420     evaluate_retval
421    
422 niro 263 # exchange ssh rsa keys - the first boot needs this !
423     # or no reboot will work via the webadmin
424 niro 348 echo -e " SSH authentification settings ..."
425 niro 264 HOME=/root config_ssh_auth
426 niro 263 evaluate_retval
427    
428 niro 348 # autostart
429 niro 252 echo -e " Autostart settings ..."
430 niro 348 mysqldo "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');"
431    
432     # screensaver
433     echo -e " Screensaver settings ..."
434     mysqldo "insert into cfg_screensaver(serial,screensaver) values('${ALX_SERIAL}','')"
435    
436 niro 1582 # version info
437     local alx_os
438     local alx_utils
439     alx_os="$(< /etc/mageversion)"
440     alx_utils="$(magequery -n alxconfig-ng-alx | sed 's:.*\[\ \(.*\)\ \].*:\1:')"
441     alx_utils="${alx_utils/alxconfig-ng-alx-}"
442     mysqldo "insert into client_version(serial,os,utils) values('${ALX_SERIAL}','${alx_os}','${alx_utils}')"
443    
444 niro 252 evaluate_retval
445 niro 221 }
446    
447 niro 282 # imports current settings to the database resolved by the hardware detection
448 niro 337 update_settings_in_db()
449     {
450 niro 282 # note: networking is always 'dhcp' if hw was autodetected
451     # note: default_domain/hostname is set in config.rc or exported
452     # note: we updating only hardware settings here !
453    
454     # to be safe, we do some sanity checks
455     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
456     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
457    
458     # vars used by hwdetect
459     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
460     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
461     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
462    
463     # get setting from hwdetect
464     source /etc/sysconfig/hwsetup/knoppix
465     source /etc/sysconfig/hwsetup/mouse
466    
467     echo
468     echo -e ${COLMAGENTA}"Updating detected settings in database"${COLDEFAULT}
469    
470     # network
471     echo -e " Network settings ..."
472 niro 337 if [[ ${ALX_CONFD_NETWORKING} = true ]]
473     then
474     # get settings
475     #source ${rc_base}/init.d/network &> /dev/null
476     for iface in $(onboot_interface_list ${network_settings}/net.*)
477     do
478     [[ $(< ${SETTINGSPATH}/confd-networking) != ${iface} ]] && continue
479     echo "WARNING: only importing settings for interface [ ${iface} ] !"
480     source ${network_settings}/net.${iface} || exit 1
481     NETCARD_DRIVER="$(cat /etc/modules.d/net.${iface} | cut -d' ' -f3)"
482 niro 282
483 niro 348 mysqldo "update cfg_network set
484 niro 337 hostname='${ALX_DEFAULT_HOSTNAME}',
485     module='${NETCARD_DRIVER}',
486     domain='${ALX_DEFAULT_DOMAIN}',
487     networking='${NETWORKING}',
488     netmask='${NETMASK}',
489     dns='${NAMESERVER}',
490     gateway='${GATEWAY}',
491     broadcast='${BROADCAST}',
492     ip='${IP}',
493     forcemacto='${FORCE_MAC_TO}',
494     wireless_bitrate='${WIRELESS_BITRATE}',
495     wireless_channel='${WIRELESS_CHANNEL}',
496     wireless_essid='${WIRELESS_ESSID}',
497     wireless_frequency='${WIRELESS_FREQUENCY}',
498     wireless_mode='${WIRELESS_MODE}',
499     wireless_nick='${WIRELESS_NICK}',
500     wireless_auth_mode='${WIRELESS_AUTH_MODE}',
501     wireless_key_length='${WIRELESS_KEY_LENGTH}',
502     wireless_key='${WIRELESS_KEY}',
503     wireless_key_ascii='${WIRELESS_KEY_ASCII}'
504     where serial=${ALX_SERIAL};"
505    
506     # only insert the *FIRST* iface
507     break
508     done
509     else
510 niro 348 mysqldo "update cfg_network set
511 niro 337 hostname='${ALX_DEFAULT_HOSTNAME}',
512     module='${NETCARD_DRIVER}',
513     domain='${ALX_DEFAULT_DOMAIN}',
514     networking='dhcp'
515     where serial=${ALX_SERIAL};"
516     fi
517 niro 282 evaluate_retval
518    
519     # xserver
520     echo -e " Graphic settings ..."
521     # xserver general
522 niro 348 mysqldo "update cfg_graphic set
523 niro 282 module='${XMODULE}',
524     resolution='1024x768',
525     depth='16',
526 niro 1582 refresh_rate='60'
527 niro 282 where serial=${ALX_SERIAL};"
528     evaluate_retval
529    
530     # input
531     echo -e " Input settings ..."
532 niro 348 mysqldo "update cfg_input set mouse='${XMOUSETYPE}' where serial=${ALX_SERIAL};"
533 niro 282 evaluate_retval
534 niro 1582
535     # version info
536     local alx_os
537     local alx_utils
538     alx_os="$(< /etc/mageversion)"
539     alx_utils="$(magequery -n alxconfig-ng-alx | sed 's:.*\[\ \(.*\)\ \].*:\1:')"
540     alx_utils="${alx_utils/alxconfig-ng-alx-}"
541     mysqldo "update client_version set os='${alx_os}', utils='${alx_utils}' where serial=${ALX_SERIAL};"
542 niro 282 }
543    
544 niro 221 # imports current settings to the local system resolved by the hardware detection
545 niro 337 # we only need the network settings
546     import_settings_local()
547     {
548 niro 282 # note: networking is always 'dhcp' if hw was autodetected
549     # note: default_domain/hostname is set in config.rc
550 niro 226
551 niro 282 # to be safe, we do some sanity checks
552 niro 221 [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
553     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
554 niro 226
555 niro 282 # vars used by hwdetect
556 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
557     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
558     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
559    
560 niro 282 # get setting from hwdetect
561 niro 221 source /etc/sysconfig/hwsetup/knoppix
562 niro 226
563 niro 221 echo
564     echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
565    
566 niro 337 if [[ ${ALX_CONFD_NETWORKING} = false ]]
567     then
568     #[ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
569     #echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
570 niro 221
571 niro 1622 # set an device alias for modprobe.conf and modules.conf
572 niro 337 [ ! -d /etc/modules.d ] && install -d /etc/modules.d
573 niro 1622 [ ! -d /etc/modprobe.d ] && install -d /etc/modprobe.d
574 niro 337 echo "alias eth0 ${NETCARD_DRIVER}" > /etc/modules.d/net.eth0
575 niro 1622 echo "alias eth0 ${NETCARD_DRIVER}" > /etc/modprobe.d/net.eth0
576 niro 337
577     # regenerate modprobe.conf
578     [ -x $(which modules-update) ] && modules-update || echo "cannot regen modprobe.conf"
579     evaluate_retval
580     fi
581    
582 niro 282 # set system state to 'already configured'
583 niro 226 touch /etc/alxconfig-ng/state/configured
584 niro 252
585 niro 1715 # install slim desktopmanager configuration
586 niro 1718 config_display_manager
587 niro 1715
588 niro 313 # if only an recheck was forced than abort now
589     [[ ${ALX_FORCED_RECHECK} = true ]] && return 0
590    
591 niro 275 # create a fresh fluxbox directory
592     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
593     install -d ${ALX_UNPRIV_HOME}/.fluxbox
594    
595     # now generate fluxbox config files
596    
597     # fluxbox main config
598     cat ${ALX_SKELETONS}/fluxbox/init \
599     > ${ALX_UNPRIV_HOME}/.fluxbox/init
600    
601 niro 319 # fluxbox autostart
602     cat ${ALX_SKELETONS}/fluxbox/apps \
603     > ${ALX_UNPRIV_HOME}/.fluxbox/apps
604    
605 niro 275 # fluxbox menu header
606     cat ${ALX_SKELETONS}/fluxbox/menu.header \
607     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
608    
609 niro 297 # now fix it with proper messages :P
610     local ver="$(< /etc/mageversion)"
611     sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \
612     ${ALX_UNPRIV_HOME}/.fluxbox/menu
613    
614 niro 275 # add a newline (maybe there is no crlf in the header)
615     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
616    
617     # fluxbox menu footer
618     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
619     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
620    
621     # add a newline (maybe there is no crlf in the footer)
622     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
623    
624 niro 313
625     # setup some standart icons (sysinfo.lnk)
626     # basic config
627     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc
628    
629     # clean desktop icon location
630     [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop
631     install -d ${ALX_UNPRIV_HOME}/.xtdesktop
632    
633     # last but not least gen a icon with some sys informations
634     local sysinfo
635     local osversion
636     local xres
637     local yres
638    
639     osversion="$(< /etc/mageversion)"
640     sysinfo="Hostname: ${ALX_DEFAULT_HOSTNAME} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
641    
642     # at first boot we got always a resolution of 1024x768-16@60
643     # middle of the screen
644     # (no txt - length required, xtdesk manage that itself)
645     xres="$((1024 / 2))"
646     # default y pos (full yres -22 !)
647     yres="$((768 - 22 ))"
648    
649     generate_icon \
650     --name "${sysinfo}" \
651     --command "exit 0" \
652     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
653     --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \
654     --xres "${xres}" \
655     --yres "${yres}" \
656     --icon-width "1" \
657     --icon-height "1"
658    
659 niro 368 # create a xinitrc
660     echo "exec startfluxbox" > ${ALX_UNPRIV_HOME}/.xinitrc
661    
662 niro 282 # set correct permissions
663     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
664     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
665     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
666 niro 348 chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
667     chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
668 niro 368 chmod 0644 ${ALX_UNPRIV_HOME}/.xinitrc
669 niro 221 }
670    
671 niro 282 # start|stop
672 niro 337 preliminary_network()
673     {
674 niro 221 local module
675 niro 1800 local modulesconf
676 niro 226
677     if [ -f /etc/alxconfig-ng/state/configured ]
678 niro 221 then
679 niro 337 # compat for old clients
680     if [ -f ${SETTINGSPATH}/modules ]
681     then
682     # get module name
683     module=$(cat ${SETTINGSPATH}/modules)
684     modprobe ${module}
685     fi
686 niro 1800
687     # check modprobe.conf
688     if [[ $(kernel_major_version) = 2.4 ]]
689     then
690     modulesconf="/etc/modules.conf"
691     else
692     modulesconf="/etc/modprobe.conf"
693     fi
694     if [[ -z $(grep eth0 ${modulesconf}) ]]
695     then
696     /sbin/modules-update force
697     fi
698 niro 221 else
699 niro 282 # vars used by hwdetect
700 niro 221 local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
701     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
702 niro 226
703 niro 282 # get setting from hwdetect
704 niro 221 source /etc/sysconfig/hwsetup/knoppix
705     modprobe ${NETCARD_DRIVER}
706     fi
707 niro 226
708 niro 221 case $1 in
709     start)
710     # keeping like always safe:
711     # no network should be startet here,
712     # so we can delete all pid files if one exists
713     if ps -A|grep dhcpcd > /dev/null
714     then
715     echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT}
716     dhcpcd -k
717     sleep 1
718     else
719     rm -f /var/run/dhcpcd-eth?.pid
720     fi
721 niro 348 [[ ${ALX_CONFD_NETWORKING} = true ]] && [[ ${RUNLEVEL} != S ]] && \
722     ${rc_base}/init.d/network stop
723 niro 226
724 niro 337 echo -e ${COLMAGENTA}"Starting preliminary networking ... "${COLDEFAULT}
725 niro 226
726 niro 337 # start network configured from /etc/conf.d
727     if [[ ${ALX_CONFD_NETWORKING} = true ]]
728     then
729     ${rc_base}/init.d/network start
730     else
731     echo -e ${COLOREDSTAR}"Starting default dhcp based networking ... "${COLDEFAULT}
732     # -t 10 timeout of 10 secs
733     dhcpcd -t 10 &> /dev/null
734     evaluate_retval
735     fi
736 niro 221 ;;
737 niro 226
738 niro 221 stop)
739 niro 337 echo -e ${COLMAGENTA}"Stopping preliminary networking ... "${COLDEFAULT}
740     if [[ ${ALX_CONFD_NETWORKING} = true ]]
741     then
742     ${rc_base}/init.d/network stop
743     else
744     echo -e ${COLOREDSTAR}"Stopping default dhcp based networking ... "${COLDEFAULT}
745     ifconfig eth0 down
746     fi
747 niro 221 if ps -A|grep dhcpcd > /dev/null
748     then
749     dhcpcd -z &> /dev/null
750 niro 1596 sleep 1
751 niro 221 fi
752     evaluate_retval
753     ;;
754 niro 226
755 niro 221 *)
756     echo "Usage: preliminary_network {start|stop}"
757     ;;
758     esac
759     }
760    
761 niro 337 reset_system_settings()
762     {
763     # force load of de kbdkeys
764     loadkeys -q de
765     echo
766     echo -en ${COLRED}
767     echo -n "*** Warning: you are about to reset *all* local settings on this system!"
768     echo -e ${COLDEFAULT}
769     echo "*** Do you really want to continue ?"
770     echo -n "*** Enter 'yes' to continue, anything else to abort: "
771     read kbinsert
772     if [[ ${kbinsert} = yes ]]
773     then
774     echo -en ${COLRED}
775     echo -n "*** OK, you really want it ... killing all settings: "
776     for i in 3 2 1 now
777     do
778     echo -n " ${i}"
779     sleep 1
780     done
781     echo -e ${COLDEFAULT}
782    
783     ## reset all settings:
784     rm -rf ${SETTINGSPATH}/*
785     rm -f /etc/alxconfig-ng/serial
786     rm -rf /etc/alxconfig-ng/state
787    
788 niro 357 # clear all printers & net-shares
789     :> /etc/cups/printers.conf
790     :> /etc/samba/smb.conf
791    
792     # remove inetd, cups & smb from init
793     rc-config del inetd &> /dev/null
794     rc-config del cups &> /dev/null
795     rc-config del samba &> /dev/null
796    
797     # remove all user settings
798     [ -d ${ALX_UNPRIV_HOME} ] && rm -rf ${ALX_UNPRIV_HOME}
799    
800     # remove all ica-sessions
801 niro 359 find ${ALX_ICA_SESSIONS} -type f -name '*.ica' | xargs rm
802 niro 357
803     # remove all old nics and modules configs
804     find /etc/conf.d -type f -name 'net.*' | xargs rm
805     find /etc/modules.d -type f -name 'net.*' | xargs rm
806    
807     # restore default networking
808     cat ${ALX_SKELETONS}/net/net.eth0 > /etc/conf.d/net.eth0
809    
810 niro 337 echo "I am done now, press [Enter] to reboot system ..."
811 niro 348 else
812     echo "Aborted, press [Enter] to reboot system ..."
813 niro 337 fi
814 niro 348 read
815     reboot
816 niro 337 }
817    
818     onboot_interface_list()
819     {
820     local file
821     local devices
822     local iface
823    
824     # get list of all devices
825     for file in $@
826     do
827     if [[ $(read_value ONBOOT ${file}) = yes ]]
828     then
829     iface="$(basename ${file} | sed s/net.//)"
830     # exclude backup files
831     case "${iface}" in
832     *~) ;;
833     *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;
834     esac
835     fi
836     done
837    
838     echo "${devices}"
839     }
840    
841 niro 348 # read values from net.* files
842 niro 337 read_value()
843     {
844     local var="$1"
845     local file="$2"
846     local value
847    
848     # local all possible vars
849     # global
850     local ONBOOT
851     local NETWORKING
852    
853     # static
854     local IP
855     local NETMASK
856     local BROADCAST
857     local NETWORKING
858     local FORCE_MAC_TO
859    
860     # dhcp
861     local DHCP_PROG
862     local DHCP_START
863     local DHCP_STOP
864    
865     # default gw
866     local GATEWAY
867     local GATEWAY_IF
868    
869     # wireless extensions
870     local WIRELESS_AP
871     local WIRELESS_AUTH_MODE
872     local WIRELESS_BITRATE
873     local WIRELESS_CHANNEL
874     local WIRELESS_DEFAULT_KEY
875     local WIRELESS_ESSID
876     local WIRELESS_FREQUENCY
877     local WIRELESS_KEY
878     local WIRELESS_KEY_ASCII
879     local WIRELESS_KEY_0
880     local WIRELESS_KEY_1
881     local WIRELESS_KEY_2
882     local WIRELESS_KEY_3
883     local WIRELESS_KEY_LENGTH
884     local WIRELESS_MODE
885     local WIRELESS_NICK
886     local WIRELESS_NWID
887     local WIRELESS_POWER
888    
889     source ${file}
890     eval value=\$$(echo ${var})
891     echo "${value}"
892     }
893    
894 niro 221 case $1 in
895     start)
896 niro 337 # check for global overrides
897     [ -f ${SETTINGSPATH}/confd-networking ] && ALX_CONFD_NETWORKING=true
898     [ -f /hardware-auto-detection ] && ALX_FORCED_RECHECK=true
899     read_cmdline hardware-auto-detection && ALX_FORCED_RECHECK=true
900     read_cmdline alx-reset-settings && ALX_RESET_SETTINGS=true
901    
902     # kill all settings if requested
903     if [[ ${ALX_RESET_SETTINGS} = true ]]
904     then
905     reset_system_settings
906     fi
907    
908 niro 282 # retrieve or validate current serial
909 niro 221 get_system_serial
910 niro 282 if [[ ${ALX_HW_DETECT} = true ]]
911 niro 221 then
912 niro 282 if [[ ${ALX_FORCED_RECHECK} = true ]]
913     then
914     update_settings_in_db
915     else
916     import_settings_to_db
917     fi
918 niro 221 import_settings_local
919 niro 252
920     # here we should also exchange the ssh keys
921     # or the system cannot be rebooted after
922     # the first start via the alx-webadmin
923     config_ssh_auth
924 niro 221 fi
925 niro 252
926 niro 282 # now setup system configuration
927     # alx_setup_or_whatever_it_will_be_called()
928 niro 348 [[ ${ALX_HW_DETECT} = false ]] && update_system_settings
929 niro 221
930 niro 282 # stop at last the preliminary networking (dhcp)
931 niro 221 preliminary_network stop
932     ;;
933 niro 282
934 niro 221 stop)
935 niro 282 # unset_alx_connected #--> now in alxsetstate-rc6
936 niro 221 # ! important !: del systemstate
937 niro 226 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
938 niro 221 sleep 0.1
939     ;;
940     *)
941     echo "Usage: $0 {start|stop} ..."
942     ;;
943     esac
944 niro 252

Properties

Name Value
svn:executable *