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