Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 248 - (hide annotations) (download)
Wed Apr 13 16:15:28 2005 UTC (19 years, 1 month ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsettings
File size: 9590 byte(s)
added config_auth and cleaned file

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 248 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsettings,v 1.8 2005-04-13 16:15:28 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 221
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 niro 226 [ ! -d /etc/alxconfig-ng/state ] && install -d /etc/alxconfig-ng/state
49 niro 221
50    
51 niro 226 update_system_settings(){
52     echo -e ${COLMAGENTA}"Checking system setup ..."${COLDEFAULT}
53 niro 221
54 niro 226 # imports network settings from db
55     config_networking
56    
57     # imports x11 settings from db
58     config_x11
59    
60 niro 248 # imports session settings from db
61 niro 239 config_sessions
62 niro 226
63     # imports printer settings from db
64     config_printing
65 niro 248
66     # imports auth settings from db
67     config_auth
68 niro 221 }
69    
70     get_system_serial(){
71    
72     local CUR_IP CUR_MAC CUR_MTIME
73    
74     #check if serial file exists
75 niro 226 if [ -f /etc/alxconfig-ng/serial ]
76 niro 221 then
77 niro 226 source /etc/alxconfig-ng/serial
78    
79     #start preliminary networking (dhcp)
80 niro 221 preliminary_network start
81 niro 226
82 niro 221 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 niro 226
86 niro 221 echo -e ${COLOREDSTAR} "Trying to validate my serial ..."
87 niro 226
88 niro 221 #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 niro 226
107 niro 221 #set hostname to alx_default_hostname
108     [ -z "${ALX_DEFAULT_HOSTNAME}" ] && ALX_DEFAULT_HOSTNAME=magellan-alx
109     HOSTNAME="${ALX_DEFAULT_HOSTNAME}"
110 niro 226
111 niro 221 #update the hostname on the system for sure
112 niro 230 echo "${HOSTNAME}" > /etc/hostname
113 niro 226
114 niro 221 #start preliminary networking (dhcp)
115     preliminary_network start
116 niro 226
117 niro 221 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 niro 226
121 niro 221 echo -e ${COLOREDSTAR} "Trying to get new serial ..."
122 niro 226
123 niro 221 #request new serial
124     #ALX_REG_DATE="$(date +%F)"
125 niro 226
126 niro 221 #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 niro 226
137 niro 221 #then validate and retrieve serial
138 niro 226
139 niro 221 ### 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 niro 226 ### you have more than one serial number then ###
142    
143 niro 221 #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 niro 226
154 niro 221 #set ALX_STATE to ok so everybody that everything was ok
155     ALX_STATE=ok
156 niro 226
157     echo "ALX_SERIAL=${ALX_SERIAL}" > /etc/alxconfig-ng/serial
158     echo "ALX_REG_DATE=${CUR_MTIME}" >> /etc/alxconfig-ng/serial
159    
160 niro 221 evaluate_retval
161     else
162     #print false (works only if this is the first statement here)
163     evaluate_retval
164 niro 226
165 niro 221 #set ALX_STATE to error so everybody sees there was an error
166     ALX_STATE=error
167 niro 226
168 niro 221 #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 niro 226
176 niro 221 #write current state to temp file
177 niro 226 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
178 niro 221 }
179    
180    
181     check_is_configured() {
182 niro 226 if [ -f /etc/alxconfig-ng/state/configured ]
183 niro 221 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 niro 229
196 niro 221 #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 niro 229
200 niro 221 #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 niro 229
205 niro 221 #get setting from hwdetect
206     source /etc/sysconfig/hwsetup/knoppix
207     source /etc/sysconfig/hwsetup/mouse
208 niro 229
209 niro 221 echo
210     echo -e ${COLMAGENTA}"Importing detected settings to database"${COLDEFAULT}
211 niro 229
212 niro 221 #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 niro 229
231 niro 221 #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 niro 229 depth,
240     monitorid
241 niro 221 )
242     values(
243     '${ALX_SERIAL}',
244     '${XMODULE}',
245     '1024x768',
246 niro 229 '16',
247     '0'
248 niro 221 );";
249 niro 229
250 niro 221 # 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 niro 226 # we only need the network settings
258 niro 221 import_settings_local(){
259     #note: networking is always 'dhcp' if hw was autodetected
260     #note: default_domain/hostname is set in config.rc
261 niro 226
262 niro 221 #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 niro 226
266 niro 221 #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 niro 226
274 niro 221 echo
275     echo -e ${COLMAGENTA}"Importing detected settings to local system"${COLDEFAULT}
276    
277 niro 226 [ ! -d ${SETTINGSPATH} ] && install -d ${SETTINGSPATH}
278     echo "${NETCARD_DRIVER}" > ${SETTINGSPATH}/modules
279     evaluate_retval
280 niro 221
281     #set system state to 'already configured'
282 niro 226 touch /etc/alxconfig-ng/state/configured
283 niro 221 }
284    
285     #start|stop
286     preliminary_network(){
287     local module
288 niro 226
289     if [ -f /etc/alxconfig-ng/state/configured ]
290 niro 221 then
291     #get module name
292 niro 226 module=$(cat ${SETTINGSPATH}/modules)
293 niro 221 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 niro 226
299 niro 221 #get setting from hwdetect
300     source /etc/sysconfig/hwsetup/knoppix
301     modprobe ${NETCARD_DRIVER}
302     fi
303 niro 226
304 niro 221 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 niro 226
318 niro 221 echo -e ${COLMAGENTA}"Starting preliminary network ... "${COLDEFAULT}
319 niro 226 dhcpcd &> /dev/null
320    
321 niro 221 # aka_fix ########################################
322 niro 226 #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 niro 221 ##################################################
327 niro 226
328 niro 221 evaluate_retval
329     ;;
330 niro 226
331 niro 221 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 niro 226
341 niro 221 *)
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 niro 226 [ -f /etc/alxconfig-ng/state/state ] && rm /etc/alxconfig-ng/state/state
369 niro 221 sleep 0.1
370     ;;
371     *)
372     echo "Usage: $0 {start|stop} ..."
373     ;;
374     esac

Properties

Name Value
svn:executable *