Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 252 - (hide annotations) (download)
Thu Apr 14 19:12:21 2005 UTC (19 years, 1 month ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 10605 byte(s)
writing some needed default settings to the db (autostart&passwords); added ssh key exchange for remote reboot/shutdown

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 252 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.9 2005-04-14 19:12:21 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 niro 239 source /usr/lib/alxconfig-ng/functions/config_sessions
34 niro 226 source /usr/lib/alxconfig-ng/functions/config_x11
35 niro 248 source /usr/lib/alxconfig-ng/functions/config_auth
36 niro 252 source /usr/lib/alxconfig-ng/functions/config_ssh_auth
37 niro 221
38     #check if mysql is available
39     [ -x /usr/bin/mysql ] && MYSQL_ALX=true
40    
41     #other needed vars
42     ALX_HW_DETECT=false
43    
44     #unset vars which may kill us
45     unset ALX_SERIAL ALX_STATE
46    
47    
48     #setup needed directories
49 niro 226 [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
50 niro 221
51    
52 niro 226 update_system_settings(){
53     echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
54 niro 221
55 niro 226 # imports network settings from db
56     config_networking
57    
58     # imports x11 settings from db
59     config_x11
60    
61 niro 248 # imports session settings from db
62 niro 239 config_sessions
63 niro 226
64     # imports printer settings from db
65     config_printing
66 niro 248
67     # imports auth settings from db
68     config_auth
69 niro 252
70     # exchange ssh rsa keys
71     config_ssh_auth
72 niro 221 }
73    
74     get_system_serial(){
75    
76     local CUR_IP CUR_MAC CUR_MTIME
77    
78     #check if serial file exists
79 niro 226 if [ -f /etc/alxconfig-ng/serial ]
80 niro 221 then
81 niro 226 source /etc/alxconfig-ng/serial
82    
83     #start preliminary networking (dhcp)
84 niro 221 preliminary_network start
85 niro 226
86 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
87     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
88     CUR_MTIME=$(date +%s)
89 niro 226
90 niro 221 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
91 niro 226
92 niro 221 #nice serial output
93     $CURS_UP
94     $SET_WCOL
95     echo "[ SN: ${ALX_SERIAL} ]"
96    
97     if validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
98     then
99     ALX_STATE="ok"
100     else
101     ALX_STATE="invalid serial"
102     fi
103    
104     else
105     #run hardware detection
106     echo
107     echo -e ${COLMAGENTA}"Preparing system for first boot"${COLDEFAULT}
108     ALX_HW_DETECT=true
109     /etc/init.d/hwdetect start
110 niro 226
111 niro 221 #set hostname to alx_default_hostname
112     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
113     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
114 niro 226
115 niro 221 #update the hostname on the system for sure
116 niro 230 echo "${HOSTNAME}" > /etc/hostname
117 niro 226
118 niro 221 #start preliminary networking (dhcp)
119     preliminary_network start
120 niro 226
121 niro 221 CUR_IP=$(/sbin/ifconfig eth0 | sed -n '/addr:/s/ [^r]*..//gp')
122     CUR_MAC=$(/sbin/ifconfig eth0 | grep HWaddr | cut -d ' ' -f11)
123     CUR_MTIME=$(date +%s)
124 niro 226
125 niro 221 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
126 niro 226
127 niro 221 #request new serial
128     #ALX_REG_DATE="$(date +%F)"
129 niro 226
130 niro 221 #we're using the mtime now (better for vaildating the serial)
131     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
132     "insert into client_serials(
133     mtime,
134     mac
135     )
136     values(
137     '${CUR_MTIME}',
138     '${CUR_MAC}'
139     );"
140 niro 226
141 niro 221 #then validate and retrieve serial
142 niro 226
143 niro 221 ### warning must be changed that only the LAST ID will be fetched, ###
144     ### or you get error if the computer name and date are the same ###
145 niro 226 ### you have more than one serial number then ###
146    
147 niro 221 #select highest id only (added max)
148     ALX_SERIAL=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
149     "select max(serial) from client_serials where mtime='${CUR_MTIME}' and mac='${CUR_MAC}'")
150    
151     if [ "${ALX_SERIAL}" != NULL ]
152     then
153     #nice serial output
154     $CURS_UP
155     $SET_WCOL
156     echo "[ SN: ${ALX_SERIAL} ]"
157 niro 226
158 niro 221 #set ALX_STATE to ok so everybody that everything was ok
159     ALX_STATE=ok
160 niro 226
161     echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
162     echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial
163    
164 niro 221 evaluate_retval
165     else
166     #print false (works only if this is the first statement here)
167     evaluate_retval
168 niro 226
169 niro 221 #set ALX_STATE to error so everybody sees there was an error
170     ALX_STATE=error
171 niro 226
172 niro 221 #show an error that no new serial was found
173     #nice serial output
174     $CURS_UP
175     $SET_WCOL
176     echo -e "[ SN: ${COLRED}None, 0${COLDEFAULT} ]"
177     fi
178     fi
179 niro 226
180 niro 221 #write current state to temp file
181 niro 226 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
182 niro 221 }
183    
184    
185     check_is_configured() {
186 niro 226 if [ -f /etc/alxconfig-ng/state/configured ]
187 niro 221 then
188     export ALX_CONFIGURED=true
189     else
190     export ALX_CONFIGURED=false
191     fi
192     }
193    
194    
195     # imports current settings to the database resolved by the hardware detection
196     import_settings_to_db() {
197     #note: networking is always 'dhcp' if hw was autodetected
198     #note: default_domain/hostname is set in config.rc
199 niro 229
200 niro 221 #to be safe, we do some sanity checks
201     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
202     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
203 niro 229
204 niro 221 #vars used by hwdetect
205     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
206     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
207     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
208 niro 229
209 niro 221 #get setting from hwdetect
210     source /etc/sysconfig/hwsetup/knoppix
211     source /etc/sysconfig/hwsetup/mouse
212 niro 229
213 niro 221 echo
214     echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
215 niro 229
216 niro 221 #network
217     echo -e " Network settings ..."
218     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
219     "insert into cfg_network(
220     hostname,
221     serial,
222     module,
223     domain,
224     networking
225     )
226     values(
227     '${ALX_DEFAULT_HOSTNAME}',
228     '${ALX_SERIAL}',
229     '${NETCARD_DRIVER}',
230     '${ALX_DEFAULT_DOMAIN}',
231     'dhcp'
232     );"
233     evaluate_retval
234 niro 229
235 niro 221 #xserver
236     echo -e " Graphic settings ..."
237     #xserver general
238     ( mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
239     "insert into cfg_graphic(
240     serial,
241     module,
242     resolution,
243 niro 229 depth,
244     monitorid
245 niro 221 )
246     values(
247     '${ALX_SERIAL}',
248     '${XMODULE}',
249     '1024x768',
250 niro 229 '16',
251     '0'
252 niro 252 );"; )
253     evaluate_retval
254 niro 229
255 niro 221 # input
256 niro 252 echo -e " Input settings ..."
257     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
258     "insert into cfg_input(serial,mouse) values('${ALX_SERIAL}','${XMOUSETYPE}');"
259 niro 221 evaluate_retval
260 niro 252
261     # auth
262     echo -e " Authentifcation settings ..."
263     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
264     "insert into client_auth(
265     serial,
266     username,
267     shell,
268     vnc,
269     samba,
270     station
271     )
272     values(
273     '${ALX_SERIAL}',
274     '${ALX_UNPRIV_USER}',
275     '',
276     '',
277     '',
278     ''
279     );"
280     evaluate_retval
281    
282     # input
283     echo -e " Autostart settings ..."
284     mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
285     "insert into cfg_autostart(serial,session) values('${ALX_SERIAL}','');"
286     evaluate_retval
287 niro 221 }
288    
289     # imports current settings to the local system resolved by the hardware detection
290 niro 226 # we only need the network settings
291 niro 221 import_settings_local(){
292     #note: networking is always 'dhcp' if hw was autodetected
293     #note: default_domain/hostname is set in config.rc
294 niro 226
295 niro 221 #to be safe, we do some sanity checks
296     [ -z "${ALX_DEFAULT_DOMAIN}" ] && ALX_DEFAULT_DOMAIN=localdomain
297     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
298 niro 226
299 niro 221 #vars used by hwdetect
300     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
301     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
302     local MOUSETYPE XMOUSETYPE FULLNAME DEVICE
303    
304     #get setting from hwdetect
305     source /etc/sysconfig/hwsetup/knoppix
306 niro 226
307 niro 221 echo
308     echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
309    
310 niro 226 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
311     echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
312     evaluate_retval
313 niro 221
314     #set system state to 'already configured'
315 niro 226 touch /etc/alxconfig-ng/state/configured
316 niro 252
317     # default passwords are bad
318     #usermod -p $(perl -e "printf(crypt('foobar','AD'))") root
319     #usermod -p $(perl -e "printf(crypt('foobar','AD'))") ${ALX_UNPRIV_USER}
320     #smbpasswd -a root foobar
321 niro 221 }
322    
323     #start|stop
324     preliminary_network(){
325     local module
326 niro 226
327     if [ -f /etc/alxconfig-ng/state/configured ]
328 niro 221 then
329     #get module name
330 niro 226 module=$(cat ${SETTINGSPATH}/modules)
331 niro 221 modprobe ${module}
332     else
333     #vars used by hwdetect
334     local NETCARD_FULLNAME NETCARD_DRIVER MOUSE_FULLNAME MOUSE_DEVICE SOUND_FULLNAME
335     local SOUND_DRIVER XSERVER XMODULE XDESC FLOPPY_FULLNAME FLOPPY_DEVICE FLOPPY_DRIVER
336 niro 226
337 niro 221 #get setting from hwdetect
338     source /etc/sysconfig/hwsetup/knoppix
339     modprobe ${NETCARD_DRIVER}
340     fi
341 niro 226
342 niro 221 case $1 in
343     start)
344     # keeping like always safe:
345     # no network should be startet here,
346     # so we can delete all pid files if one exists
347     if ps -A|grep dhcpcd > /dev/null
348     then
349     echo -e ${COLMAGENTA}"Forcing network down"${COLDEFAULT}
350     dhcpcd -k
351     sleep 1
352     else
353     rm -f /var/run/dhcpcd-eth?.pid
354     fi
355 niro 226
356 niro 221 echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
357 niro 226 dhcpcd &> /dev/null
358    
359 niro 221 # aka_fix ########################################
360 niro 226 #ifconfig eth0 128.20.222.222 netmask 255.255.0.0 up
361     #route del default gw 128.20.50.13 &> /dev/null
362     #route add default gw 128.20.50.21 &> /dev/null
363     #echo "nameserver 128.20.50.21" > /etc/resolv.conf
364 niro 221 ##################################################
365 niro 226
366 niro 221 evaluate_retval
367     ;;
368 niro 226
369 niro 221 stop)
370     echo -e ${COLMAGENTA}"Stopping preliminary network ... "${COLDEFAULT}
371     ifconfig eth0 down
372     if ps -A|grep dhcpcd > /dev/null
373     then
374     dhcpcd -z &> /dev/null
375     fi
376     evaluate_retval
377     ;;
378 niro 226
379 niro 221 *)
380     echo "Usage: preliminary_network {start|stop}"
381     ;;
382     esac
383     }
384    
385     case $1 in
386     start)
387     #retrieve or validate current serial
388     get_system_serial
389     if [ "${ALX_HW_DETECT}" == "true" ]
390     then
391     import_settings_to_db
392     import_settings_local
393 niro 252
394     # here we should also exchange the ssh keys
395     # or the system cannot be rebooted after
396     # the first start via the alx-webadmin
397     config_ssh_auth
398 niro 221 fi
399 niro 252
400 niro 221 #now setup system configuration
401     #alx_setup_or_whatever_it_will_be_called()
402     [ "${ALX_HW_DETECT}" == "false" ] && update_system_settings
403    
404     #stop at last the preliminary networking (dhcp)
405     preliminary_network stop
406     ;;
407    
408     stop)
409     #unset_alx_connected #--> now in alxsetstate-rc6
410     # ! important !: del systemstate
411 niro 226 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
412 niro 221 sleep 0.1
413     ;;
414     *)
415     echo "Usage: $0 {start|stop} ..."
416     ;;
417     esac
418 niro 252

Properties

Name Value
svn:executable *