Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *