Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 222 - (hide annotations) (download)
Tue Mar 8 23:02:49 2005 UTC (19 years, 2 months ago) by niro
File size: 3086 byte(s)
added header; cleaned whitespaces

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 222 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsetstate,v 1.2 2005-03-08 23:02:49 niro Exp $
13    
14 niro 221 source /etc/sysconfig/rc
15     source $rc_functions
16    
17     #mysql settings
18     source /etc/alx-config/config.rc
19     source /opt/alx-config/functions/mysqlfunctions
20     source /opt/alx-config/functions/alx-mysql-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/alx-config/state/state ]
33     then
34     source /etc/alx-config/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    
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     if [ -f /etc/alx-config/serial ]
128     then
129     source /etc/alx-config/serial
130     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 *