Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 492 - (show annotations) (download)
Sun Jun 8 11:09:14 2008 UTC (15 years, 10 months ago) by niro
File size: 3404 byte(s)
-removed deprecated checks

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

Properties

Name Value
svn:executable *