Contents of /alx-src/branches/alxconf-060/init.d/alxsettings
Parent Directory | Revision Log
Revision 252 -
(show annotations)
(download)
Thu Apr 14 19:12:21 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 10605 byte(s)
Thu Apr 14 19:12:21 2005 UTC (19 years, 5 months 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 | #!/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.9 2005-04-14 19:12:21 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_sessions |
34 | source /usr/lib/alxconfig-ng/functions/config_x11 |
35 | source /usr/lib/alxconfig-ng/functions/config_auth |
36 | source /usr/lib/alxconfig-ng/functions/config_ssh_auth |
37 | |
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 | [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state |
50 | |
51 | |
52 | update_system_settings(){ |
53 | echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT} |
54 | |
55 | # imports network settings from db |
56 | config_networking |
57 | |
58 | # imports x11 settings from db |
59 | config_x11 |
60 | |
61 | # imports session settings from db |
62 | config_sessions |
63 | |
64 | # imports printer settings from db |
65 | config_printing |
66 | |
67 | # imports auth settings from db |
68 | config_auth |
69 | |
70 | # exchange ssh rsa keys |
71 | config_ssh_auth |
72 | } |
73 | |
74 | get_system_serial(){ |
75 | |
76 | local CUR_IP CUR_MAC CUR_MTIME |
77 | |
78 | #check if serial file exists |
79 | if [ -f /etc/alxconfig-ng/serial ] |
80 | then |
81 | source /etc/alxconfig-ng/serial |
82 | |
83 | #start preliminary networking (dhcp) |
84 | preliminary_network start |
85 | |
86 | 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 | |
90 | echo -e ${COLOREDSTAR} "Trying to validate my serial ..." |
91 | |
92 | #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 | |
111 | #set hostname to alx_default_hostname |
112 | [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx |
113 | HOSTNAME="${ALX_DEFAULT_HOSTNAME}" |
114 | |
115 | #update the hostname on the system for sure |
116 | echo "${HOSTNAME}" > /etc/hostname |
117 | |
118 | #start preliminary networking (dhcp) |
119 | preliminary_network start |
120 | |
121 | 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 | |
125 | echo -e ${COLOREDSTAR} "Trying to get new serial ..." |
126 | |
127 | #request new serial |
128 | #ALX_REG_DATE="$(date +%F)" |
129 | |
130 | #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 | |
141 | #then validate and retrieve serial |
142 | |
143 | ### 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 | ### you have more than one serial number then ### |
146 | |
147 | #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 | |
158 | #set ALX_STATE to ok so everybody that everything was ok |
159 | ALX_STATE=ok |
160 | |
161 | echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial |
162 | echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial |
163 | |
164 | evaluate_retval |
165 | else |
166 | #print false (works only if this is the first statement here) |
167 | evaluate_retval |
168 | |
169 | #set ALX_STATE to error so everybody sees there was an error |
170 | ALX_STATE=error |
171 | |
172 | #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 | |
180 | #write current state to temp file |
181 | echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state |
182 | } |
183 | |
184 | |
185 | check_is_configured() { |
186 | if [ -f /etc/alxconfig-ng/state/configured ] |
187 | 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 | |
200 | #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 | |
204 | #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 | |
209 | #get setting from hwdetect |
210 | source /etc/sysconfig/hwsetup/knoppix |
211 | source /etc/sysconfig/hwsetup/mouse |
212 | |
213 | echo |
214 | echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT} |
215 | |
216 | #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 | |
235 | #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 | depth, |
244 | monitorid |
245 | ) |
246 | values( |
247 | '${ALX_SERIAL}', |
248 | '${XMODULE}', |
249 | '1024x768', |
250 | '16', |
251 | '0' |
252 | );"; ) |
253 | evaluate_retval |
254 | |
255 | # input |
256 | 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 | evaluate_retval |
260 | |
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 | } |
288 | |
289 | # imports current settings to the local system resolved by the hardware detection |
290 | # we only need the network settings |
291 | import_settings_local(){ |
292 | #note: networking is always 'dhcp' if hw was autodetected |
293 | #note: default_domain/hostname is set in config.rc |
294 | |
295 | #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 | |
299 | #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 | |
307 | echo |
308 | echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT} |
309 | |
310 | [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH} |
311 | echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules |
312 | evaluate_retval |
313 | |
314 | #set system state to 'already configured' |
315 | touch /etc/alxconfig-ng/state/configured |
316 | |
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 | } |
322 | |
323 | #start|stop |
324 | preliminary_network(){ |
325 | local module |
326 | |
327 | if [ -f /etc/alxconfig-ng/state/configured ] |
328 | then |
329 | #get module name |
330 | module=$(cat ${SETTINGSPATH}/modules) |
331 | 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 | |
337 | #get setting from hwdetect |
338 | source /etc/sysconfig/hwsetup/knoppix |
339 | modprobe ${NETCARD_DRIVER} |
340 | fi |
341 | |
342 | 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 | |
356 | echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT} |
357 | dhcpcd &> /dev/null |
358 | |
359 | # aka_fix ######################################## |
360 | #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 | ################################################## |
365 | |
366 | evaluate_retval |
367 | ;; |
368 | |
369 | 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 | |
379 | *) |
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 | |
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 | fi |
399 | |
400 | #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 | [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state |
412 | sleep 0.1 |
413 | ;; |
414 | *) |
415 | echo "Usage: $0 {start|stop} ..." |
416 | ;; |
417 | esac |
418 |
Properties
Name | Value |
---|---|
svn:executable | * |