Magellan Linux

Diff of /mcore-src/trunk/mcore-tools/src/include/register.global.class.in

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

revision 2441 by niro, Thu Sep 3 13:01:47 2015 UTC revision 2701 by niro, Wed Dec 16 14:42:45 2015 UTC
# Line 3  Line 3 
3  validate_client()  validate_client()
4  {  {
5   local mac_address="$1"   local mac_address="$1"
6     local ip_address="$2"
7   local serial   local serial
8   local mtime   local mtime
9     local serial_id
10     local os
11     local tools
12     local netboot
13    
14   if [[ -z ${mac_address} ]]   if [[ -z ${mac_address} ]]
15   then   then
# Line 12  validate_client() Line 17  validate_client()
17   return 1   return 1
18   fi   fi
19    
20     if [[ -z ${ip_address} ]]
21     then
22     eecho "Error: No ip_address given"
23     return 1
24     fi
25    
26   decho "registering mac_address='${mac_address}'"   decho "registering mac_address='${mac_address}'"
27     decho "registering ip_address='${ip_address}'"
28    
29   # first check if mac is registered   # first check if mac is registered
30   serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'")   serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'")
31    
32     # current mtime
33     mtime=$(date +%s)
34    
35   if [[ -z ${serial} ]]   if [[ -z ${serial} ]]
36   then   then
  mtime=$(date +%s)  
   
37   # request a new serial; one command now (cause must be done in the same session)   # request a new serial; one command now (cause must be done in the same session)
38   serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();")   serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();")
39   fi   fi
# Line 31  validate_client() Line 44  validate_client()
44   else   else
45   decho "serial='${serial}'"   decho "serial='${serial}'"
46   rvecho "${serial}"   rvecho "${serial}"
47    
48     SSLSAY_IP="${ip_address}"
49     SSLSAY_PORT="6666"
50     nsslsay_fingerprint "register '${serial}'"
51    
52     # get netboot state
53     nsslsay_queue_init
54     nsslsay_queue_add "nocolors"
55     nsslsay_queue_add "get version.netboot"
56     netboot=$(control_client "${serial}" run-queue)
57    
58     # register the client as online
59     serial_id=$(mysqldo "select serial from state_connected where serial=${serial};")
60     if [[ -n ${serial_id} ]]
61     then
62     mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}', netboot='${netboot}' where serial=${serial};"
63     else
64     mysqldo "insert into state_connected(serial,ip,mac,mtime,netboot) values('${serial}','${ip_address}','${mac_address}','${mtime}', '${netboot}');"
65     fi
66    
67     # update tools and os version info
68     nsslsay_queue_init
69     nsslsay_queue_add "nocolors"
70     nsslsay_queue_add "get version.os"
71     os=$(control_client "${serial}" run-queue)
72     import_resource client_version "${serial}" os "${os}"
73     nsslsay_queue_init
74     nsslsay_queue_add "nocolors"
75     nsslsay_queue_add "get version.tools"
76     tools=$(control_client "${serial}" run-queue)
77     import_resource client_version "${serial}" utils "${tools}"
78    
79     # run hardware detection
80     if is_provided hardware
81     then
82     run_hardware_detect "${serial}"
83     fi
84    
85   return 0   return 0
86   fi   fi
87  }  }
# Line 53  register_client() Line 104  register_client()
104   decho "mac_address='${mac_address}'"   decho "mac_address='${mac_address}'"
105    
106   decho "register '${mac_address}'"   decho "register '${mac_address}'"
107   nsslsay_fingerprint "register '${mac_address}'"   nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'"
108    }
109    
110    register_client_local()
111    {
112     local serial="$1"
113    
114     if [[ -z ${serial} ]]
115     then
116     eecho "No serial given"
117     return 1
118     fi
119    
120     install -d "${MCORE_CONFIG_PATH}"
121     CONFIG="${MCORE_CONFIG_PATH}/serial"
122     clearconfig
123     addconfig "CLIENT_SERIAL=\"${serial}\""
124  }  }

Legend:
Removed from v.2441  
changed lines
  Added in v.2701