6 |
local ip_address="$2" |
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 |
|
local location |
14 |
|
|
15 |
if [[ -z ${mac_address} ]] |
if [[ -z ${mac_address} ]] |
16 |
then |
then |
30 |
# first check if mac is registered |
# first check if mac is registered |
31 |
serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") |
serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") |
32 |
|
|
33 |
|
# current mtime |
34 |
|
mtime=$(date +%s) |
35 |
|
|
36 |
if [[ -z ${serial} ]] |
if [[ -z ${serial} ]] |
37 |
then |
then |
|
mtime=$(date +%s) |
|
|
|
|
38 |
# 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) |
39 |
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();") |
40 |
fi |
fi |
50 |
SSLSAY_PORT="6666" |
SSLSAY_PORT="6666" |
51 |
nsslsay_fingerprint "register '${serial}'" |
nsslsay_fingerprint "register '${serial}'" |
52 |
|
|
53 |
|
# register the client as online |
54 |
|
serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") |
55 |
|
if [[ -n ${serial_id} ]] |
56 |
|
then |
57 |
|
mysqldo "update state_connected set ip='${ip_address}', mac='${mac_address}', mtime='${mtime}' where serial=${serial};" |
58 |
|
else |
59 |
|
mysqldo "insert into state_connected(serial,ip,mac,mtime) values('${serial}','${ip_address}','${mac_address}','${mtime}');" |
60 |
|
fi |
61 |
|
|
62 |
|
# get netboot state |
63 |
|
nsslsay_queue_init |
64 |
|
nsslsay_queue_add "nocolors" |
65 |
|
nsslsay_queue_add "get version.netboot" |
66 |
|
netboot=$(control_client "${serial}" run-queue) |
67 |
|
# update netboot state |
68 |
|
serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") |
69 |
|
if [[ -n ${serial_id} ]] |
70 |
|
then |
71 |
|
mysqldo "update state_connected set netboot='${netboot}' where serial=${serial};" |
72 |
|
fi |
73 |
|
|
74 |
|
# get location from cmdline and update the client_serials.location entry |
75 |
|
nsslsay_queue_init |
76 |
|
nsslsay_queue_add "nocolors" |
77 |
|
nsslsay_queue_add "get system.cmdline MCORE_LOCATION=" |
78 |
|
location=$(control_client "${serial}" run-queue) |
79 |
|
# update location |
80 |
|
if [[ -n ${location} ]] |
81 |
|
then |
82 |
|
mysqldo "update client_serials set location='${location}' where serial=${serial};" |
83 |
|
fi |
84 |
|
|
85 |
|
# update tools and os version info |
86 |
|
nsslsay_queue_init |
87 |
|
nsslsay_queue_add "nocolors" |
88 |
|
nsslsay_queue_add "get version.os" |
89 |
|
os=$(control_client "${serial}" run-queue) |
90 |
|
import_resource client_version "${serial}" os "${os}" |
91 |
|
nsslsay_queue_init |
92 |
|
nsslsay_queue_add "nocolors" |
93 |
|
nsslsay_queue_add "get version.tools" |
94 |
|
tools=$(control_client "${serial}" run-queue) |
95 |
|
import_resource client_version "${serial}" utils "${tools}" |
96 |
|
|
97 |
|
# run hardware detection |
98 |
|
if is_provided hardware |
99 |
|
then |
100 |
|
run_hardware_detect "${serial}" |
101 |
|
fi |
102 |
|
|
103 |
return 0 |
return 0 |
104 |
fi |
fi |
105 |
} |
} |
112 |
local mac_address |
local mac_address |
113 |
|
|
114 |
control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) |
control_server_ip=$(dns_to_ip ${MCORE_CONTROL_SERVER}) |
115 |
|
if [[ -z ${control_server_ip} ]] |
116 |
|
then |
117 |
|
decho "Could not resolve control server ip, dns_to_ip(${MCORE_CONTROL_SERVER}) failed" |
118 |
|
return 1 |
119 |
|
fi |
120 |
iface_ip=$(iface_for_remote_addr ${control_server_ip}) |
iface_ip=$(iface_for_remote_addr ${control_server_ip}) |
121 |
|
if [[ -z ${iface_ip} ]] |
122 |
|
then |
123 |
|
decho "Could not resolve interface ip, iface_ip(${control_server_ip}) failed" |
124 |
|
return 1 |
125 |
|
fi |
126 |
iface=$(iface_for_ip ${iface_ip}) |
iface=$(iface_for_ip ${iface_ip}) |
127 |
|
if [[ -z ${iface} ]] |
128 |
|
then |
129 |
|
decho "Could not resolve interface for referencing ip address, iface_for_ip(${iface_ip}) failed" |
130 |
|
return 1 |
131 |
|
fi |
132 |
mac_address=$(mac_for_iface ${iface}) |
mac_address=$(mac_for_iface ${iface}) |
133 |
|
if [[ -z ${mac_address} ]] |
134 |
|
then |
135 |
|
decho "Could not resolve mac address, mac_for_iface(${iface}) failed" |
136 |
|
return 1 |
137 |
|
fi |
138 |
|
|
139 |
decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" |
decho "MCORE_CONTROL_SERVER='${MCORE_CONTROL_SERVER}'" |
140 |
decho "iface_ip='${iface_ip}'" |
decho "iface_ip='${iface_ip}'" |
141 |
decho "iface='${iface}'" |
decho "iface='${iface}'" |
142 |
decho "mac_address='${mac_address}'" |
decho "mac_address='${mac_address}'" |
143 |
|
|
144 |
decho "register '${mac_address}'" |
decho "register '${mac_address}' '${iface_ip}'" |
145 |
nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" |
nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" |
146 |
} |
} |
147 |
|
|
155 |
return 1 |
return 1 |
156 |
fi |
fi |
157 |
|
|
158 |
|
install -d "${MCORE_CONFIG_PATH}" |
159 |
CONFIG="${MCORE_CONFIG_PATH}/serial" |
CONFIG="${MCORE_CONFIG_PATH}/serial" |
160 |
clearconfig |
clearconfig |
161 |
addconfig "CLIENT_SERIAL=\"${serial}\"" |
addconfig "CLIENT_SERIAL=\"${serial}\"" |