-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall-validator.sh
More file actions
executable file
Β·456 lines (383 loc) Β· 13 KB
/
Copy pathinstall-validator.sh
File metadata and controls
executable file
Β·456 lines (383 loc) Β· 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
#!/bin/bash
#
# install-validator.sh - HookProbe Cortex Validator Installation
#
# CRITICAL: This script can ONLY be run AFTER mesh Cloud is deployed.
# Validators require KYC verification and mesh cloud infrastructure.
#
# Prerequisites:
# 1. mesh Cloud must be deployed and operational
# 2. KYC documentation prepared
# 3. Hardware meets minimum requirements
#
# Usage:
# sudo ./install-validator.sh --mesh-url https://mssp.hookprobe.com
#
set -e
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
mesh_URL=""
VALIDATOR_ID=""
KYC_EMAIL=""
INSTALL_DIR="/opt/hookprobe"
CONFIG_DIR="/etc/hookprobe"
DATA_DIR="/var/lib/hookprobe"
# ============================================================
# BANNER
# ============================================================
show_banner() {
echo -e "${BLUE}"
cat << "EOF"
β¦ β¦βββββββ¦ββββββ¦βββββββ βββ
β ββ£β ββ ββ β©ββ βββ β¦ββ ββ β©βββ£
β© β©βββββββ© β©β© β©βββββββββββ
LIBERTY VALIDATOR INSTALLATION
Production-Ready Distributed Validation
EOF
echo -e "${NC}"
}
# ============================================================
# PREREQUISITE CHECKS
# ============================================================
check_root() {
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}ERROR: This script must be run as root${NC}"
echo "Please run: sudo $0"
exit 1
fi
}
check_mesh_url() {
if [ -z "$mesh_URL" ]; then
echo -e "${RED}ERROR: mesh URL not provided${NC}"
echo "Usage: $0 --mesh-url https://mssp.hookprobe.com"
exit 1
fi
}
check_mesh_cloud_deployed() {
echo -e "${YELLOW}Checking mesh Cloud deployment...${NC}"
# Try to connect to mesh API
if ! curl -f -s -o /dev/null --connect-timeout 10 "${mesh_URL}/api/v1/health"; then
echo -e "${RED}β CRITICAL ERROR: mesh Cloud is NOT deployed or unreachable${NC}"
echo ""
echo "Validators CANNOT be installed without mesh Cloud infrastructure."
echo ""
echo "Required steps:"
echo " 1. Deploy mesh Cloud first: sudo ./install.sh --role cloud"
echo " 2. Verify mesh is running: ${mesh_URL}/api/v1/health"
echo " 3. Then retry validator installation"
echo ""
exit 1
fi
echo -e "${GREEN}β mesh Cloud is operational${NC}"
# Get mesh version
mesh_VERSION=$(curl -s "${mesh_URL}/api/v1/version" | jq -r '.version' 2>/dev/null || echo "unknown")
echo " mesh Version: ${mesh_VERSION}"
}
check_hardware_requirements() {
echo -e "${YELLOW}Checking hardware requirements...${NC}"
# CPU cores
CPU_CORES=$(nproc)
if [ "$CPU_CORES" -lt 4 ]; then
echo -e "${RED}β Insufficient CPU cores: ${CPU_CORES} (minimum: 4)${NC}"
exit 1
fi
echo -e "${GREEN}β CPU: ${CPU_CORES} cores${NC}"
# RAM
RAM_GB=$(free -g | awk '/^Mem:/{print $2}')
if [ "$RAM_GB" -lt 8 ]; then
echo -e "${RED}β Insufficient RAM: ${RAM_GB}GB (minimum: 8GB)${NC}"
exit 1
fi
echo -e "${GREEN}β RAM: ${RAM_GB}GB${NC}"
# Disk space
DISK_GB=$(df / | tail -1 | awk '{print int($4/1024/1024)}')
if [ "$DISK_GB" -lt 100 ]; then
echo -e "${YELLOW}β Low disk space: ${DISK_GB}GB (recommended: 100GB+)${NC}"
else
echo -e "${GREEN}β Disk: ${DISK_GB}GB available${NC}"
fi
}
# ============================================================
# KYC COLLECTION
# ============================================================
collect_kyc_information() {
echo ""
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${BLUE}β KYC VERIFICATION REQUIRED FOR VALIDATORS β${NC}"
echo -e "${BLUE}ββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
echo "Validators require KYC (Know Your Customer) verification to ensure"
echo "network integrity and comply with security policies."
echo ""
read -p "Organization Name: " ORG_NAME
read -p "Contact Email: " KYC_EMAIL
read -p "Country: " COUNTRY
read -p "Geographic Region (e.g., us-east, eu-west): " GEO_REGION
echo ""
echo -e "${YELLOW}KYC Documentation:${NC}"
echo " Organization: ${ORG_NAME}"
echo " Email: ${KYC_EMAIL}"
echo " Country: ${COUNTRY}"
echo " Region: ${GEO_REGION}"
echo ""
read -p "Is this information correct? (yes/no): " CONFIRM
if [ "$CONFIRM" != "yes" ]; then
echo -e "${RED}KYC collection cancelled${NC}"
exit 1
fi
}
# ============================================================
# HARDWARE FINGERPRINT
# ============================================================
generate_hardware_fingerprint() {
echo -e "${YELLOW}Generating hardware fingerprint...${NC}"
# Create fingerprint script
cat > /tmp/hw_fingerprint.py << 'HWFP_SCRIPT'
import sys
sys.path.insert(0, '/opt/hookprobe/src')
from neuro.identity.hardware_fingerprint import HardwareFingerprintGenerator
import json
generator = HardwareFingerprintGenerator()
fingerprint = generator.generate()
print(json.dumps({
'fingerprint_id': fingerprint.fingerprint_id,
'cpu_id': fingerprint.cpu_id,
'mac_addresses': fingerprint.mac_addresses,
'disk_serials': fingerprint.disk_serials,
'dmi_uuid': fingerprint.dmi_uuid,
'hostname': fingerprint.hostname
}))
HWFP_SCRIPT
HW_FP_JSON=$(python3 /tmp/hw_fingerprint.py)
HW_FINGERPRINT=$(echo "$HW_FP_JSON" | jq -r '.fingerprint_id')
echo -e "${GREEN}β Hardware Fingerprint: ${HW_FINGERPRINT:0:32}...${NC}"
rm -f /tmp/hw_fingerprint.py
}
# ============================================================
# REGISTRATION WITH mesh
# ============================================================
register_with_mesh() {
echo -e "${YELLOW}Registering validator with mesh...${NC}"
# Generate validator ID
VALIDATOR_ID="validator-$(uuidgen | cut -d'-' -f1)"
# Generate Ed25519 key pair
python3 << KEYGEN
from cryptography.hazmat.primitives.asymmetric import ed25519
import json
private_key = ed25519.Ed25519PrivateKey.generate()
public_key = private_key.public_key()
# Save keys
with open('$CONFIG_DIR/validator_private_key.pem', 'wb') as f:
from cryptography.hazmat.primitives import serialization
f.write(private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption()
))
with open('$CONFIG_DIR/validator_public_key.pem', 'wb') as f:
f.write(public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
))
print(public_key.public_bytes_raw().hex())
KEYGEN
PUBLIC_KEY=$(cat $CONFIG_DIR/validator_public_key.pem | grep -v "BEGIN\|END" | tr -d '\n')
# Get IP address
IP_ADDRESS=$(curl -s ifconfig.me)
# Register with mesh
REGISTRATION_DATA=$(cat <<EOF
{
"device_id": "${VALIDATOR_ID}",
"device_type": "validator",
"hardware_fingerprint": "${HW_FINGERPRINT}",
"public_key_ed25519": "${PUBLIC_KEY}",
"firmware_version": "1.0.0",
"location": {
"ip_address": "${IP_ADDRESS}",
"country": "${COUNTRY}",
"region": "${GEO_REGION}",
"city": "",
"latitude": 0.0,
"longitude": 0.0,
"asn": 0,
"isp": ""
},
"kyc": {
"organization": "${ORG_NAME}",
"email": "${KYC_EMAIL}",
"country": "${COUNTRY}"
}
}
EOF
)
RESPONSE=$(curl -s -X POST \
-H "Content-Type: application/json" \
-d "$REGISTRATION_DATA" \
"${mesh_URL}/api/v1/devices/register")
STATUS=$(echo "$RESPONSE" | jq -r '.status' 2>/dev/null || echo "error")
if [ "$STATUS" != "pending" ]; then
echo -e "${RED}β Registration failed${NC}"
echo "Response: $RESPONSE"
exit 1
fi
echo -e "${GREEN}β Validator registered (status: PENDING)${NC}"
echo " Validator ID: ${VALIDATOR_ID}"
echo ""
echo -e "${YELLOW}IMPORTANT: Your validator is pending KYC approval${NC}"
echo " 1. mesh admin will review your KYC documentation"
echo " 2. You will receive email confirmation at: ${KYC_EMAIL}"
echo " 3. Once approved, your validator will become ACTIVE"
echo ""
}
# ============================================================
# INSTALLATION
# ============================================================
install_dependencies() {
echo -e "${YELLOW}Installing dependencies...${NC}"
apt-get update -qq
apt-get install -y -qq \
python3-pip \
python3-dev \
build-essential \
libssl-dev \
libffi-dev \
sqlite3 \
jq \
curl \
net-tools \
uuid-runtime
pip3 install -q \
cryptography \
chacha20poly1305 \
maxminddb \
geoip2
echo -e "${GREEN}β Dependencies installed${NC}"
}
install_hookprobe_validator() {
echo -e "${YELLOW}Installing HookProbe Cortex Validator...${NC}"
# Create directories
mkdir -p $INSTALL_DIR
mkdir -p $CONFIG_DIR
mkdir -p $DATA_DIR/validator
mkdir -p $DATA_DIR/merkle-log
# Copy source files (assume we're in hookprobe repo)
if [ -d "core" ]; then
cp -r core/* $INSTALL_DIR/
cp -r shared/* $INSTALL_DIR/
echo -e "${GREEN}β Source files installed${NC}"
else
echo -e "${RED}β Core directory not found${NC}"
exit 1
fi
# Create validator configuration
cat > $CONFIG_DIR/validator.conf << CONF
[validator]
validator_id = ${VALIDATOR_ID}
mesh_url = ${mesh_URL}
listen_port = 4478
[hardware]
fingerprint = ${HW_FINGERPRINT}
[kyc]
organization = ${ORG_NAME}
email = ${KYC_EMAIL}
country = ${COUNTRY}
region = ${GEO_REGION}
[network]
heartbeat_interval = 30
session_timeout = 300
[paths]
data_dir = ${DATA_DIR}/validator
merkle_log = ${DATA_DIR}/merkle-log
keys_dir = ${CONFIG_DIR}
CONF
echo -e "${GREEN}β Validator configured${NC}"
}
create_systemd_service() {
echo -e "${YELLOW}Creating systemd service...${NC}"
cat > /etc/systemd/system/hookprobe-validator.service << SERVICE
[Unit]
Description=HookProbe Cortex Validator
After=network.target
Wants=network-online.target
[Service]
Type=simple
User=root
WorkingDirectory=${INSTALL_DIR}
ExecStart=/usr/bin/python3 -m neuro.validation.validator_service
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
SERVICE
systemctl daemon-reload
systemctl enable hookprobe-validator.service
echo -e "${GREEN}β Systemd service created${NC}"
}
# ============================================================
# POST-INSTALL
# ============================================================
show_post_install_instructions() {
echo ""
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo -e "${GREEN}β VALIDATOR INSTALLATION COMPLETE β${NC}"
echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"
echo ""
echo -e "${BLUE}Validator ID:${NC} ${VALIDATOR_ID}"
echo -e "${BLUE}Status:${NC} PENDING (awaiting KYC approval)"
echo -e "${BLUE}Hardware FP:${NC} ${HW_FINGERPRINT:0:32}..."
echo ""
echo -e "${YELLOW}Next Steps:${NC}"
echo ""
echo " 1. Wait for KYC approval email at: ${KYC_EMAIL}"
echo " 2. Once approved, start the validator:"
echo " ${GREEN}sudo systemctl start hookprobe-validator${NC}"
echo " 3. Monitor logs:"
echo " ${GREEN}sudo journalctl -u hookprobe-validator -f${NC}"
echo " 4. Check status:"
echo " ${GREEN}curl ${mesh_URL}/api/v1/validators/${VALIDATOR_ID}${NC}"
echo ""
echo -e "${YELLOW}Configuration:${NC}"
echo " Config: ${CONFIG_DIR}/validator.conf"
echo " Keys: ${CONFIG_DIR}/validator_*.pem"
echo " Data: ${DATA_DIR}/validator"
echo ""
echo -e "${BLUE}HookProbe Cortex Validator - Production Ready${NC}"
echo ""
}
# ============================================================
# MAIN
# ============================================================
main() {
show_banner
# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--mesh-url)
mesh_URL="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Run checks and installation
check_root
check_mesh_url
check_mesh_cloud_deployed
check_hardware_requirements
collect_kyc_information
install_dependencies
generate_hardware_fingerprint
install_hookprobe_validator
register_with_mesh
create_systemd_service
show_post_install_instructions
}
main "$@"