Annotation of /mcore-src/trunk/mcore-tools/src/include/register.global.class.in
Parent Directory | Revision Log
Revision 2832 -
(hide annotations)
(download)
Wed Aug 30 13:54:01 2017 UTC (6 years, 8 months ago) by niro
File size: 4447 byte(s)
Wed Aug 30 13:54:01 2017 UTC (6 years, 8 months ago) by niro
File size: 4447 byte(s)
-support arch sys information to be able to detect which arch of the os is running
1 | niro | 2435 | # $Id$ |
2 | niro | 2430 | |
3 | validate_client() | ||
4 | { | ||
5 | local mac_address="$1" | ||
6 | niro | 2442 | local ip_address="$2" |
7 | niro | 2430 | local serial |
8 | niro | 2431 | local mtime |
9 | niro | 2457 | local serial_id |
10 | niro | 2506 | local os |
11 | local tools | ||
12 | niro | 2699 | local netboot |
13 | niro | 2768 | local location |
14 | niro | 2430 | |
15 | if [[ -z ${mac_address} ]] | ||
16 | then | ||
17 | eecho "Error: No mac_address given" | ||
18 | return 1 | ||
19 | fi | ||
20 | |||
21 | niro | 2442 | if [[ -z ${ip_address} ]] |
22 | then | ||
23 | eecho "Error: No ip_address given" | ||
24 | return 1 | ||
25 | fi | ||
26 | |||
27 | niro | 2439 | decho "registering mac_address='${mac_address}'" |
28 | niro | 2445 | decho "registering ip_address='${ip_address}'" |
29 | niro | 2439 | |
30 | niro | 2430 | # first check if mac is registered |
31 | serial=$(mysqldo "select serial from client_serials where mac='${mac_address}'") | ||
32 | |||
33 | niro | 2476 | # current mtime |
34 | mtime=$(date +%s) | ||
35 | |||
36 | niro | 2430 | if [[ -z ${serial} ]] |
37 | then | ||
38 | # request a new serial; one command now (cause must be done in the same session) | ||
39 | niro | 2431 | serial=$(mysqldo "insert into client_serials (mtime, mac) values('${mtime}','${mac_address}'); select last_insert_id();") |
40 | niro | 2430 | fi |
41 | |||
42 | niro | 2433 | if [[ -z ${serial} ]] |
43 | then | ||
44 | return 1 | ||
45 | else | ||
46 | niro | 2441 | decho "serial='${serial}'" |
47 | rvecho "${serial}" | ||
48 | niro | 2442 | |
49 | niro | 2445 | SSLSAY_IP="${ip_address}" |
50 | niro | 2442 | SSLSAY_PORT="6666" |
51 | niro | 2447 | nsslsay_fingerprint "register '${serial}'" |
52 | niro | 2442 | |
53 | niro | 2719 | # 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 | niro | 2701 | # 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 | niro | 2719 | # update netboot state |
68 | niro | 2457 | serial_id=$(mysqldo "select serial from state_connected where serial=${serial};") |
69 | if [[ -n ${serial_id} ]] | ||
70 | then | ||
71 | niro | 2719 | mysqldo "update state_connected set netboot='${netboot}' where serial=${serial};" |
72 | niro | 2457 | fi |
73 | |||
74 | niro | 2768 | # 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 | niro | 2506 | # 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 | niro | 2507 | tools=$(control_client "${serial}" run-queue) |
95 | niro | 2506 | import_resource client_version "${serial}" utils "${tools}" |
96 | niro | 2832 | nsslsay_queue_init |
97 | nsslsay_queue_add "nocolors" | ||
98 | nsslsay_queue_add "get system.arch" | ||
99 | osarch=$(control_client "${serial}" run-queue) | ||
100 | import_resource client_version "${serial}" arch "${osarch}" | ||
101 | niro | 2506 | |
102 | niro | 2497 | # run hardware detection |
103 | if is_provided hardware | ||
104 | then | ||
105 | niro | 2499 | run_hardware_detect "${serial}" |
106 | niro | 2497 | fi |
107 | |||
108 | niro | 2433 | return 0 |
109 | fi | ||
110 | niro | 2430 | } |
111 | |||
112 | register_client() | ||
113 | { | ||
114 | niro | 2787 | local control_server |
115 | niro | 2430 | local control_server_ip |
116 | local iface_ip | ||
117 | local iface | ||
118 | local mac_address | ||
119 | |||
120 | niro | 2787 | control_server=$(mcore-controlserver) |
121 | if [[ $? != 0 ]] | ||
122 | then | ||
123 | decho "Could not communicate with the controlserver" | ||
124 | return 1 | ||
125 | fi | ||
126 | |||
127 | control_server_ip=$(dns_to_ip ${control_server}) | ||
128 | niro | 2784 | if [[ -z ${control_server_ip} ]] |
129 | then | ||
130 | niro | 2787 | decho "Could not resolve control server ip, dns_to_ip(${control_server}) failed" |
131 | niro | 2784 | return 1 |
132 | fi | ||
133 | niro | 2816 | |
134 | niro | 2819 | iface=$(iface_for_remote_addr ${control_server_ip}) |
135 | if [[ -z ${iface} ]] | ||
136 | niro | 2784 | then |
137 | niro | 2819 | decho "Could not resolve interface for referencing ip address, iface_for_remote_addr(${control_server_ip}) failed" |
138 | niro | 2784 | return 1 |
139 | fi | ||
140 | niro | 2816 | |
141 | niro | 2819 | iface_ip=$(get_iface_ip ${iface}) |
142 | if [[ -z ${iface_ip} ]] | ||
143 | niro | 2784 | then |
144 | niro | 2819 | decho "Could not resolve interface ip, get_ip(${iface}) failed" |
145 | niro | 2784 | return 1 |
146 | fi | ||
147 | niro | 2816 | |
148 | niro | 2430 | mac_address=$(mac_for_iface ${iface}) |
149 | niro | 2784 | if [[ -z ${mac_address} ]] |
150 | then | ||
151 | decho "Could not resolve mac address, mac_for_iface(${iface}) failed" | ||
152 | return 1 | ||
153 | fi | ||
154 | niro | 2430 | |
155 | niro | 2787 | decho "control_server='${control_server}'" |
156 | niro | 2439 | decho "iface_ip='${iface_ip}'" |
157 | decho "iface='${iface}'" | ||
158 | decho "mac_address='${mac_address}'" | ||
159 | niro | 2430 | |
160 | niro | 2719 | decho "register '${mac_address}' '${iface_ip}'" |
161 | niro | 2447 | nsslsay_fingerprint "register '${mac_address}' '${iface_ip}'" |
162 | niro | 2430 | } |
163 | niro | 2442 | |
164 | register_client_local() | ||
165 | { | ||
166 | local serial="$1" | ||
167 | |||
168 | if [[ -z ${serial} ]] | ||
169 | then | ||
170 | eecho "No serial given" | ||
171 | return 1 | ||
172 | fi | ||
173 | |||
174 | niro | 2461 | install -d "${MCORE_CONFIG_PATH}" |
175 | niro | 2442 | CONFIG="${MCORE_CONFIG_PATH}/serial" |
176 | clearconfig | ||
177 | addconfig "CLIENT_SERIAL=\"${serial}\"" | ||
178 | } |