Magellan Linux

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

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

alx-src/trunk/alxconfig-ng/init.d/alxsetstate revision 347 by niro, Sun Oct 9 21:35:27 2005 UTC alx-src/branches/alxconf-060/init.d/alxsetstate revision 3481 by niro, Mon Apr 16 08:37:27 2012 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    # $Id$
3    
4  #%rlevels: 3:s 4:s 5:s 0:k 6:k  #%rlevels: 3:s 0:k
5  #%start: 99  #%start: 99
6  #%stop: 01  #%stop: 01
7    
# Line 9  Line 10 
10  #%before:  #%before:
11  #%after:  #%after:
12    
13  # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/init.d/alxsetstate,v 1.9 2005-10-09 21:35:27 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  # helper functions
19  source /usr/lib/alxconfig-ng/functions/serial_functions  source ${ALX_FUNCTIONS}/mysqlfunctions
20    source ${ALX_FUNCTIONS}/serial_functions
21  # check if mysql is available  source ${ALX_FUNCTIONS}/common
 [ -x /usr/bin/mysql ] && MYSQL_ALX=true  
   
 # other needed vars  
 ALX_HW_DETECT=false  
22    
23  # unset vars which may kill us  # unset vars which may kill us
24  unset ALX_SERIAL ALX_STATE ALX_IFACE  unset ALX_SERIAL ALX_STATE ALX_IFACE
# Line 36  else Line 31  else
31   ALX_STATE=error   ALX_STATE=error
32  fi  fi
33    
34    if [ -f ${SETTINGSPATH}/confd-networking ]
35    then
36     ALX_IFACE="$(< ${SETTINGSPATH}/confd-networking)"
37    fi
38  [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0  [[ -z ${ALX_IFACE} ]] && export ALX_IFACE=eth0
39    
40  # need to put this to an extra init script which will be  # need to put this to an extra init script which will be
# Line 43  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   echo -e ${COLMAGENTA}"Register system to database"${COLDEFAULT}   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   echo "ALX_STATE=\"${ALX_STATE}\"" > /etc/alxconfig-ng/state/state
59   show_invalid_serial_msg   show_invalid_serial_msg
60   exit 1   exit 1
61   fi   fi
62    
63   # first check if an entry exist with my serial   # first check if an entry exist with my serial
64   # if it exist update this entry else insert a new one   # if it exist update this entry else insert a new one
65   ID=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")   id=$(mysqldo "select serial from state_connected where serial=${ALX_SERIAL};")
66    
67   if [ -n "${ID}" ]   if [ -n "${id}" ]
68   then   then
69   # run an update   # run an update
70    
71   # nice status   # nice status
72   $CURS_UP   $CURS_UP
73   $SET_WCOL   $SET_WCOL
74   echo "[ U, State: ${ALX_STATE} ]"   rc_echo "[ SN: ${ALX_SERIAL}, U, ${ALX_STATE} ]"
75    
76   mysqldo "update state_connected set   mysqldo "update state_connected set
77   hostname='${HOSTNAME}',   hostname='${HOSTNAME}',
78   ip='${CUR_IP}',   ip='${cur_ip}',
79   mac='${CUR_MAC}',   mac='${cur_mac}',
80   state='${ALX_STATE}',   state='${ALX_STATE}',
81   mtime='${CUR_MTIME}'   mtime='${cur_mtime}'
82   where serial=${ALX_SERIAL};"   where serial=${ALX_SERIAL};"
83   else   else
84   # run an insert   # run an insert
# Line 87  set_current_network_state() Line 86  set_current_network_state()
86   # nice status   # nice status
87   $CURS_UP   $CURS_UP
88   $SET_WCOL   $SET_WCOL
89   echo "[ N, State: ${ALX_STATE} ]"   rc_echo "[ SN: ${ALX_SERIAL}, N, ${ALX_STATE} ]"
90    
91   mysqldo "insert into state_connected(   mysqldo "insert into state_connected(
92   serial,   serial,
# Line 100  set_current_network_state() Line 99  set_current_network_state()
99   values(   values(
100   '${ALX_SERIAL}',   '${ALX_SERIAL}',
101   '${HOSTNAME}',   '${HOSTNAME}',
102   '${CUR_IP}',   '${cur_ip}',
103   '${CUR_MAC}',   '${cur_mac}',
104   '${ALX_STATE}',   '${ALX_STATE}',
105   '${CUR_MTIME}'   '${cur_mtime}'
106   );"   );"
107   fi   fi
108  }  }
# Line 114  set_current_network_state() Line 113  set_current_network_state()
113  # nice name is alx_connected_state or sth like this  # nice name is alx_connected_state or sth like this
114  unset_alx_connected()  unset_alx_connected()
115  {  {
116   local SQL_OPTS   local cur_mac
117   local CUR_MAC  
118     cur_mac=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)
119    
120   CUR_MAC=$(/sbin/ifconfig ${ALX_IFACE} | grep HWaddr | cut -d ' ' -f11)   rc_mecho "Unregister system from database"
121    
122   echo -e ${COLMAGENTA}"Unregister system from database"${COLDEFAULT}   # nice status
123     $CURS_UP
124     $SET_WCOL
125     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    
# Line 155  case $1 in Line 158  case $1 in
158   evaluate_retval   evaluate_retval
159   ;;   ;;
160   *)   *)
161   echo "Usage: $0 {start|stop} ..."   rc_echo "Usage: $0 {start|stop} ..."
162   ;;   ;;
163  esac  esac
164    

Legend:
Removed from v.347  
changed lines
  Added in v.3481