Magellan Linux

Diff of /alx-src/branches/alxconf-060/init.d/alxsetstate

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

revision 3479 by niro, Mon Apr 16 08:33:55 2012 UTC revision 3483 by niro, Mon Apr 16 08:42:19 2012 UTC
# Line 42  fi Line 42  fi
42  # nice name is alx_connected_state or sth like this  # nice name is alx_connected_state or sth like this
43  set_current_network_state()  set_current_network_state()
44  {  {
45   local CUR_IP CUR_MAC ID   local cur_ip cur_mac cur_mtime id
46    
47   rc_mecho "Register system to database"   rc_mecho "Register system to database"
48    
49   CUR_IP=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')   cur_ip=$(/sbin/ifconfig ${ALX_IFACE} | sed -n '/addr:/s/ [^r]*..//gp')
50   CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)   cur_mac=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
51   CUR_MTIME=$(date +%s)   cur_mtime=$(date +%s)
52    
53   # validate current serial   # validate current serial
54   if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${CUR_MAC}"   if ! validate_serial "${ALX_SERIAL}" "${ALX_REG_DATE}" "${cur_mac}"
55   then   then
56   # abort on non valid serial   # abort on non valid serial
57   ALX_STATE="invalid serial"   ALX_STATE="invalid serial"
58   echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state   local CONFIG="/etc/alxconfig-ng/state/state"
59     clearconfig
60     addconfig "ALX_STATE=\"${ALX_STATE}\""
61   show_invalid_serial_msg   show_invalid_serial_msg
62   exit 1   exit 1
63   fi   fi
64    
65   # first check if an entry exist with my serial   # first check if an entry exist with my serial
66   # if it exist update this entry else insert a new one   # if it exist update this entry else insert a new one
67   ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")   id=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
68    
69   if [ -n "${ID}" ]   if [[ -n ${id} ]]
70   then   then
71   # run an update   # run an update
72    
# Line 75  set_current_network_state() Line 77  set_current_network_state()
77    
78   mysqldo "update state_connected set   mysqldo "update state_connected set
79   hostname='${HOSTNAME}',   hostname='${HOSTNAME}',
80   ip='${CUR_IP}',   ip='${cur_ip}',
81   mac='${CUR_MAC}',   mac='${cur_mac}',
82   state='${ALX_STATE}',   state='${ALX_STATE}',
83   mtime='${CUR_MTIME}'   mtime='${cur_mtime}'
84   where serial=${ALX_SERIAL};"   where serial=${ALX_SERIAL};"
85   else   else
86   # run an insert   # run an insert
# Line 99  set_current_network_state() Line 101  set_current_network_state()
101   values(   values(
102   '${ALX_SERIAL}',   '${ALX_SERIAL}',
103   '${HOSTNAME}',   '${HOSTNAME}',
104   '${CUR_IP}',   '${cur_ip}',
105   '${CUR_MAC}',   '${cur_mac}',
106   '${ALX_STATE}',   '${ALX_STATE}',
107   '${CUR_MTIME}'   '${cur_mtime}'
108   );"   );"
109   fi   fi
110  }  }
111    
   
112  # need to put this to an extra init script which will  # need to put this to an extra init script which will
113  # be executed first when the system is going down.  # be executed first when the system is going down.
114  # nice name is alx_connected_state or sth like this  # nice name is alx_connected_state or sth like this
115  unset_alx_connected()  unset_alx_connected()
116  {  {
117   local SQL_OPTS   local cur_mac
118   local CUR_MAC   cur_mac=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
   
  CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)  
119    
120   rc_mecho "Unregister system from database"   rc_mecho "Unregister system from database"
121    
# Line 125  unset_alx_connected() Line 124  unset_alx_connected()
124   $SET_WCOL   $SET_WCOL
125   rc_echo "[ SN: ${ALX_SERIAL} ]"   rc_echo "[ SN: ${ALX_SERIAL} ]"
126    
127   mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${CUR_MAC}';"   mysqldo "delete from state_connected where serial='${ALX_SERIAL}' and mac='${cur_mac}';"
128   evaluate_retval   evaluate_retval
129  }  }
130    
   
131  ########### starts here ################  ########### starts here ################
132    
133  # first of all get current system serial  # first of all get current system serial
# Line 158  case $1 in Line 156  case $1 in
156   unset_alx_connected   unset_alx_connected
157   evaluate_retval   evaluate_retval
158   ;;   ;;
159    
160   *)   *)
161   rc_echo "Usage: $0 {start|stop} ..."   rc_echo "Usage: $0 {start|stop} ..."
162   ;;   ;;
163  esac  esac
   

Legend:
Removed from v.3479  
changed lines
  Added in v.3483