Magellan Linux

Annotation of /alx-src/trunk/alxconfig-ng/init.d/alxsetstate

Parent Directory Parent Directory | Revision Log Revision Log


Revision 347 - (hide annotations) (download)
Sun Oct 9 21:35:27 2005 UTC (18 years, 7 months ago) by niro
File size: 3381 byte(s)
- fixed whitespaces
- using now mysqldo from mysqlfunctions
- added support mutiple ifaces support

1 niro 221 #!/bin/bash
2    
3     #%rlevels: 3:s 4:s 5:s 0:k 6:k
4     #%start: 99
5     #%stop: 01
6    
7     #deps
8     #%needs:
9     #%before:
10     #%after:
11    
12 niro 347 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsetstate,v 1.9 2005-10-09 21:35:27 niro Exp $
13 niro 222
14 niro 221 source /etc/sysconfig/rc
15     source $rc_functions
16    
17 niro 347 # mysql settings
18 niro 226 source /etc/alxconfig-ng/config.rc
19     source /usr/lib/alxconfig-ng/functions/mysqlfunctions
20     source /usr/lib/alxconfig-ng/functions/serial_functions
21 niro 221
22 niro 347 # check if mysql is available
23 niro 221 [ -x /usr/bin/mysql ] && MYSQL_ALX=true
24    
25 niro 347 # other needed vars
26 niro 221 ALX_HW_DETECT=false
27    
28 niro 347 # unset vars which may kill us
29     unset ALX_SERIAL ALX_STATE ALX_IFACE
30 niro 221
31 niro 347 # get current system state
32 niro 228 if [ -f /etc/alxconfig-ng/state/state ]
33 niro 221 then
34 niro 228 source /etc/alxconfig-ng/state/state
35 niro 221 else
36     ALX_STATE=error
37     fi
38    
39 niro 347 [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0
40    
41 niro 221 # need to put this to an extra init script which will be
42     # executed when the real network is up and not the preliminary.
43     # nice name is alx_connected_state or sth like this
44 niro 347 set_current_network_state()
45     {
46 niro 221 local CUR_IP CUR_MAC ID
47    
48     echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}
49    
50 niro 347 CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
51     CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
52 niro 221 CUR_MTIME=$(date +%s)
53    
54     # validate current serial
55     if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"
56     then
57 niro 306 # abort on non valid serial
58 niro 221 ALX_STATE="invalid serial"
59 niro 306 echo "ALX_STATE=${ALX_STATE}" > /etc/alxconfig-ng/state/state
60     show_invalid_serial_msg
61     exit 1
62 niro 221 fi
63    
64 niro 347 # first check if an entry exist with my serial
65 niro 221 # if it exist update this entry else insert a new one
66 niro 347 ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
67 niro 221
68     if [ -n "${ID}" ]
69     then
70 niro 347 # run an update
71 niro 221
72 niro 347 # nice status
73 niro 221 $CURS_UP
74     $SET_WCOL
75     echo "[ U, State: ${ALX_STATE} ]"
76    
77 niro 347 mysqldo "update state_connected set
78 niro 221 hostname='${HOSTNAME}',
79     ip='${CUR_IP}',
80     mac='${CUR_MAC}',
81     state='${ALX_STATE}',
82     mtime='${CUR_MTIME}'
83     where serial=${ALX_SERIAL};"
84     else
85 niro 347 # run an insert
86 niro 221
87 niro 347 # nice status
88 niro 221 $CURS_UP
89     $SET_WCOL
90     echo "[ N, State: ${ALX_STATE} ]"
91    
92 niro 347 mysqldo "insert into state_connected(
93 niro 221 serial,
94     hostname,
95     ip,
96     mac,
97     state,
98     mtime
99     )
100     values(
101     '${ALX_SERIAL}',
102     '${HOSTNAME}',
103     '${CUR_IP}',
104     '${CUR_MAC}',
105     '${ALX_STATE}',
106     '${CUR_MTIME}'
107     );"
108     fi
109     }
110    
111    
112     # need to put this to an extra init script which will
113     # be executed first when the system is going down.
114     # nice name is alx_connected_state or sth like this
115 niro 347 unset_alx_connected()
116     {
117 niro 221 local SQL_OPTS
118 niro 274 local CUR_MAC
119 niro 221
120 niro 347 CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
121 niro 274
122 niro 221 echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}
123    
124 niro 347 mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';"
125 niro 221 evaluate_retval
126     }
127    
128 niro 347
129 niro 221 ########### starts here ################
130    
131 niro 347 # first of all get current system serial
132 niro 228 if [ -f /etc/alxconfig-ng/serial ]
133 niro 221 then
134 niro 228 source /etc/alxconfig-ng/serial
135 niro 221 else
136     ALX_SERIAL=0
137     fi
138    
139     case $1 in
140     start)
141 niro 283 # check if mysql server is reachable
142     # if not abort this script
143     reach_mysql_server || exit 1
144    
145 niro 221 set_current_network_state
146 niro 283 evaluate_retval
147 niro 221 ;;
148    
149     stop)
150 niro 283 # check if mysql server is reachable
151     # if not abort this script
152     reach_mysql_server || exit 1
153    
154 niro 221 unset_alx_connected
155 niro 283 evaluate_retval
156 niro 221 ;;
157     *)
158     echo "Usage: $0 {start|stop} ..."
159     ;;
160 niro 274 esac
161 niro 283

Properties

Name Value
svn:executable *