Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 274 - (show annotations) (download)
Wed May 11 12:25:39 2005 UTC (18 years, 11 months ago) by niro
File size: 3186 byte(s)
fixed unset_state mac issue

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

Properties

Name Value
svn:executable *