Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.239  
changed lines
  Added in v.370