Magellan Linux

Contents of /alx-src/trunk/alxconfig-ng/init.d/alxsettings

Parent Directory Parent Directory | Revision Log Revision Log


Revision 248 - (show annotations) (download)
Wed Apr 13 16:15:28 2005 UTC (19 years ago) by niro
File size: 9590 byte(s)
added config_auth and cleaned file

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

Properties

Name Value
svn:executable *