Annotation of /alx-src/branches/alxconf-060/init.d/alxsetstate
Parent Directory | Revision Log
Revision 239 -
(hide annotations)
(download)
Tue Apr 12 20:46:52 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3105 byte(s)
Tue Apr 12 20:46:52 2005 UTC (19 years, 5 months ago) by niro
Original Path: alx-src/trunk/alxconfig-ng/init.d/alxsetstate
File size: 3105 byte(s)
import from aka-cvs
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 | 239 | # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsetstate,v 1.5 2005-04-12 20:45:55 niro Exp $ |
13 | niro | 222 | |
14 | niro | 221 | source /etc/sysconfig/rc |
15 | source $rc_functions | ||
16 | |||
17 | #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 | #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 | 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 | # 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 | |||
117 | echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT} | ||
118 | |||
119 | mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \ | ||
120 | "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';" | ||
121 | evaluate_retval | ||
122 | } | ||
123 | |||
124 | ########### starts here ################ | ||
125 | |||
126 | #first of all get current system serial | ||
127 | niro | 228 | if [ -f /etc/alxconfig-ng/serial ] |
128 | niro | 221 | then |
129 | niro | 228 | source /etc/alxconfig-ng/serial |
130 | niro | 221 | else |
131 | ALX_SERIAL=0 | ||
132 | fi | ||
133 | |||
134 | |||
135 | case $1 in | ||
136 | start) | ||
137 | |||
138 | set_current_network_state | ||
139 | ;; | ||
140 | |||
141 | stop) | ||
142 | unset_alx_connected | ||
143 | ;; | ||
144 | *) | ||
145 | echo "Usage: $0 {start|stop} ..." | ||
146 | ;; | ||
147 | esac |
Properties
Name | Value |
---|---|
svn:executable | * |