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 222 by niro, Tue Mar 8 23:02:49 2005 UTC alx-src/branches/alxconf-060/init.d/alxsetstate revision 1975 by niro, Sat May 7 11:06:33 2011 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 4:s 5:s 0:k 6:k
5  #%start: 99  #%start: 99
# 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.2 2005-03-08 23:02:49 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/alx-config/config.rc  source /etc/alxconfig-ng/config.rc
18  source /opt/alx-config/functions/mysqlfunctions  source /usr/lib/alxconfig-ng/functions/mysqlfunctions
19  source /opt/alx-config/functions/alx-mysql-functions  source /usr/lib/alxconfig-ng/functions/serial_functions
   
 #check if mysql is available  
 [ -x /usr/bin/mysql ] && MYSQL_ALX=true  
   
 #other needed vars  
 ALX_HW_DETECT=false  
20    
21  #unset vars which may kill us  # unset vars which may kill us
22  unset ALX_SERIAL ALX_STATE  unset ALX_SERIAL ALX_STATE ALX_IFACE
23    
24  #get current system state  # get current system state
25  if [ -f /etc/alx-config/state/state ]  if [ -f /etc/alxconfig-ng/state/state ]
26  then  then
27   source /etc/alx-config/state/state   source /etc/alxconfig-ng/state/state
28  else  else
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}',
78   state='${ALX_STATE}',   state='${ALX_STATE}',
79   mtime='${CUR_MTIME}'   mtime='${CUR_MTIME}'
80   where serial=${ALX_SERIAL};"   where serial=${ALX_SERIAL};"
   
  evaluate_retval  
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,
# Line 103  set_current_network_state(){ Line 102  set_current_network_state(){
102   '${ALX_STATE}',   '${ALX_STATE}',
103   '${CUR_MTIME}'   '${CUR_MTIME}'
104   );"   );"
  evaluate_retval  
105   fi   fi
106  }  }
107    
# Line 111  set_current_network_state(){ Line 109  set_current_network_state(){
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
116    
117     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/alx-config/serial ]  if [ -f /etc/alxconfig-ng/serial ]
130  then  then
131   source /etc/alx-config/serial   source /etc/alxconfig-ng/serial
132  else  else
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
139     # if not abort this script
140     reach_mysql_server || exit 1
141    
142   set_current_network_state   set_current_network_state
143     evaluate_retval
144   ;;   ;;
145    
146   stop)   stop)
147     # check if mysql server is reachable
148     # if not abort this script
149     reach_mysql_server || exit 1
150    
151   unset_alx_connected   unset_alx_connected
152     evaluate_retval
153   ;;   ;;
154   *)   *)
155   echo "Usage: $0 {start|stop} ..."   echo "Usage: $0 {start|stop} ..."
156   ;;   ;;
 esac  
157    esac
158    

Legend:
Removed from v.222  
changed lines
  Added in v.1975