Repository navigation
Expand file tree
/
Copy pathmenu.sh
More file actions
465 lines (394 loc) Β· 18.1 KB
/
Copy pathmenu.sh
File metadata and controls
465 lines (394 loc) Β· 18.1 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
457
458
459
460
461
462
463
464
465
#!/bin/bash
set -euo pipefail
trap 'echo -e "\033[1;31mβ Error occurred at line $LINENO. Exiting.\033[0m"' ERR
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
CYAN="\033[1;36m"
WHITE="\033[1;37m"
NC="\033[0m" # Reset / No Color
BOLD="\033[1m"
BASE_DIR="$HOME/sepolia-node"
JWT_PATH="$BASE_DIR/jwt.hex"
# Fetch IP safely
IP_ADDR="$(curl -s ifconfig.me || true)"
if [ -z "$IP_ADDR" ]; then
IP_ADDR="$(hostname -I | awk '{print $1}')"
fi
print_banner() {
clear
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β"
echo "β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β"
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"
echo -e "${YELLOW} π Aztec Node Manager by Aashish π${NC}"
echo -e "${YELLOW} GitHub: https://github.com/HustleAirdrops${NC}"
echo -e "${YELLOW} Telegram: https://t.me/Hustle_Airdrops${NC}"
echo -e "${GREEN}===============================================================================${NC}"
echo -e " π‘ Ethereum Sepolia Full Node Setup Menu"
echo -e " π Geth (Execution) + Prysm (Beacon Chain)"
echo -e "==============================================${NC}"
echo "1) π Install & Start Rpc Sync"
echo "2) π View Logs"
echo "3) πΆ Check Node Status"
echo "4) π Get RPC URLs"
echo "5) π Rpc Access Controller"
echo "6) β Exit"
echo -e "==============================================${NC}"
echo -en "${NC}Choose an option [1-5]: "
}
install_dependencies() {
echo -e "${YELLOW}π§ Installing required packages...${NC}"
sudo apt update -y && sudo apt upgrade -y
# Fix common lock issues
sudo rm -f /var/lib/apt/lists/lock /var/cache/apt/archives/lock /var/lib/dpkg/lock-frontend
sudo dpkg --configure -a
local packages=(
curl jq net-tools iptables build-essential git wget lz4 make gcc nano
automake autoconf tmux htop nvme-cli libgbm1 pkg-config libssl-dev
libleveldb-dev tar clang bsdmainutils ncdu unzip ufw openssl
)
for pkg in "${packages[@]}"; do
if ! dpkg -s "$pkg" >/dev/null 2>&1; then
echo -e "${BLUE}π Installing $pkg...${NC}"
sudo apt-get install -y "$pkg"
echo -e "${GREEN}β
$pkg installed${NC}"
else
echo -e "${CYAN}βοΈ $pkg already present${NC}"
fi
done
}
install_docker() {
if ! command -v docker &>/dev/null; then
echo -e "${CYAN}π³ Installing Docker...${NC}"
sudo apt-get remove -y docker docker-engine docker.io containerd runc || true
sudo apt-get install -y ca-certificates gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable docker
sudo systemctl restart docker
echo -e "${GREEN}β
Docker installed successfully${NC}"
else
echo -e "${CYAN}βΉοΈ Docker already installed. Skipping.${NC}"
fi
}
check_ports() {
echo -e "${YELLOW}π΅οΈ Checking required ports...${NC}"
local conflicts
conflicts=$(sudo netstat -tuln | grep -E '30303|8545|8546|8551|4000|3500' || true)
if [ -n "$conflicts" ]; then
echo -e "${RED}β Ports already in use:\n$conflicts${NC}"
exit 1
else
echo -e "${GREEN}β
All required ports are available.${NC}"
fi
}
create_directories() {
echo -e "${YELLOW}π Creating directory structure...${NC}"
sudo mkdir -p "$BASE_DIR/execution" "$BASE_DIR/consensus"
sudo rm -f "$JWT_PATH"
sudo openssl rand -hex 32 | sudo tee "$JWT_PATH" > /dev/null
echo -e "${GREEN}β
JWT created at $JWT_PATH${NC}"
}
write_compose_file() {
echo -e "${YELLOW}π Writing docker-compose.yml...${NC}"
sudo tee "$BASE_DIR/docker-compose.yml" > /dev/null <<EOF
version: '3.8'
services:
execution:
image: ethereum/client-go:stable
container_name: geth
network_mode: host
restart: unless-stopped
volumes:
- ./execution:/data
- ./jwt.hex:/data/jwt.hex
command:
- --sepolia
- --http
- --http.addr=0.0.0.0
- --http.api=eth,net,web3
- --authrpc.addr=0.0.0.0
- --authrpc.jwtsecret=/data/jwt.hex
- --authrpc.port=8551
- --authrpc.vhosts=*
- --syncmode=snap
- --datadir=/data
consensus:
image: gcr.io/prysmaticlabs/prysm/beacon-chain:stable
container_name: prysm
network_mode: host
restart: unless-stopped
depends_on:
- execution
volumes:
- ./consensus:/data
- ./jwt.hex:/data/jwt.hex
command:
- --sepolia
- --accept-terms-of-use
- --datadir=/data
- --disable-monitoring
- --rpc-host=0.0.0.0
- --rpc-port=4000
- --grpc-gateway-host=0.0.0.0
- --grpc-gateway-port=3500
- --execution-endpoint=http://127.0.0.1:8551
- --jwt-secret=/data/jwt.hex
- --checkpoint-sync-url=https://checkpoint-sync.sepolia.ethpandaops.io
- --genesis-beacon-api-url=https://checkpoint-sync.sepolia.ethpandaops.io
EOF
echo -e "${GREEN}β
docker-compose.yml written${NC}"
}
start_services() {
echo -e "${CYAN}π Starting Ethereum Sepolia services...${NC}"
cd "$BASE_DIR"
sudo docker compose up -d
echo -e "${GREEN}β
Services started.${NC}"
echo -e "${GREEN}β
Node is syncing now... Check Status in 2-3 mins... Estimated Completion time: 4-5 hours${NC}"
}
print_endpoints() {
echo -e "${CYAN}\nπ Ethereum Sepolia RPC Endpoints:${NC}"
echo -e "${GREEN}π Geth: http://$IP_ADDR:8545${NC}"
echo -e "${GREEN}π Prysm: http://$IP_ADDR:3500${NC}"
echo -e "${BLUE}\nπ Setup complete β Powered by Aashishπ β¨${NC}"
}
check_node_status() {
while true; do
clear
echo -e "${CYAN}π Ethereum Sepolia Node Sync Status Checker${NC}"
echo -e "${YELLOW}π‘ Fetching Execution (Geth) Sync Status...${NC}"
SYNC=$(curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
-H "Content-Type: application/json" http://localhost:8545)
CURRENT=$(echo "$SYNC" | jq -r '.result.currentBlock // 0' | xargs printf "%d\n")
HIGHEST=$(echo "$SYNC" | jq -r '.result.highestBlock // 0' | xargs printf "%d\n")
START=$(echo "$SYNC" | jq -r '.result.startingBlock // 0' | xargs printf "%d\n")
if [[ "$CURRENT" == "0" || "$HIGHEST" == "0" ]]; then
echo -e "β Node is not syncing or not started properly."
else
PROGRESS=$(awk "BEGIN {printf \"%.2f\", ($CURRENT/$HIGHEST)*100}")
echo -e "π§± Starting Block : $START"
echo -e "β³ Current Block : $CURRENT"
echo -e "π Highest Block : $HIGHEST"
echo -e "π Sync Progress : ${GREEN}$PROGRESS%${NC}"
fi
echo -e "\n${YELLOW}π¦ Fetching Current Block Number (via eth_blockNumber)...${NC}"
BLOCK_HEX=$(curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
-H "Content-Type: application/json" http://localhost:8545 | jq -r '.result')
BLOCK_DEC=$((16#${BLOCK_HEX:2}))
echo -e "π’ Block Number : ${CYAN}$BLOCK_DEC${NC}"
echo -e "\n${YELLOW}π£ Beacon Node Status (Prysm)...${NC}"
curl -s http://localhost:3500/eth/v1/node/syncing | jq
echo -e "\nβ²οΈ Auto-refreshing every 10 seconds... (Press Enter to return to menu early)"
read -t 10 -n 1 key
if [[ $key == "" ]]; then
break
fi
done
clear
echo -e "${GREEN}β
Sync monitoring stopped.${NC}"
read -rp "π Press Enter to return to menu..." dummy
}
print_rpc_endpoints() {
IP_ADDR=$(curl -s ifconfig.me)
echo -e "${CYAN}\nπ Ethereum Sepolia RPC Endpoints:${NC}"
echo -e "${GREEN}π Geth: http://$IP_ADDR:8545${NC}"
echo -e "${GREEN}π Prysm: http://$IP_ADDR:3500${NC}"
echo -e "\n${CYAN}π Checking Ethereum Sepolia Node Sync Status...${NC}"
# === Geth Sync Check ===
geth_sync=$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' http://$IP_ADDR:8545)
is_syncing=$(echo "$geth_sync" | jq -r '.result != false')
if [[ "$is_syncing" == "true" ]]; then
current_hex=$(echo "$geth_sync" | jq -r '.result.currentBlock // "0x0"')
highest_hex=$(echo "$geth_sync" | jq -r '.result.highestBlock // "0x0"')
current_hex="${current_hex:-0x0}"
highest_hex="${highest_hex:-0x1}"
current_dec=$((16#${current_hex:2}))
highest_dec=$((16#${highest_hex:2}))
remaining=$(( highest_dec > current_dec ? highest_dec - current_dec : 0 ))
percent=$(awk "BEGIN { if ($highest_dec > 0) printf \"%.2f\", ($current_dec/$highest_dec)*100; else print \"0.00\" }")
echo -e "π ${YELLOW}Geth Syncing...${NC}"
echo -e " β³ Current Block : $current_dec"
echo -e " π Highest Block : $highest_dec"
echo -e " β Remaining : $remaining blocks"
echo -e " π Progress : ${GREEN}$percent%${NC}"
geth_synced=false
else
# fully synced
block_data=$(curl -s -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' http://$IP_ADDR:8545)
current_hex=$(echo "$block_data" | jq -r '.result // "0x0"')
current_hex="${current_hex:-0x0}"
current_dec=$((16#${current_hex:2}))
echo -e "β
${GREEN}Geth (Execution Layer): Fully Synced at Block $current_dec!${NC}"
geth_synced=true
fi
# === Prysm Sync Check ===
prysm_sync=$(curl -s http://$IP_ADDR:3500/eth/v1/node/syncing)
distance=$(echo "$prysm_sync" | jq -r '.data.sync_distance // "0"' 2>/dev/null)
head_slot=$(echo "$prysm_sync" | jq -r '.data.head_slot // "0"' 2>/dev/null)
distance="${distance:-0}"
head_slot="${head_slot:-0}"
if [[ "$distance" == "0" ]]; then
echo -e "β
${GREEN}Prysm (Consensus Layer): Fully Synced${NC}"
prysm_synced=true
else
echo -e "π ${YELLOW}Prysm Syncing...${NC}"
echo -e " π Sync Distance : $distance slots"
echo -e " π§ Head Slot : $head_slot"
prysm_synced=false
fi
# === Final Combined Status ===
if [[ "$geth_synced" == true && "$prysm_synced" == true ]]; then
echo -e "\n${BLUE}π Node is Fully Synced & Operational! β Powered by Aashish π β¨${NC}"
else
echo -e "\n${RED}β οΈ Node is still syncing... please wait until both layers are ready.${NC}"
fi
}
access_controller() {
trap 'echo -e "\n${RED}π Exiting Access Controller...${NC}"; return' SIGINT
while true; do
clear
echo -e "\n${CYAN}${BOLD}=============================================="
echo -e " π ETHEREUM RPC ACCESS CONTROLLER "
echo -e "==============================================${NC}"
echo -e "${WHITE}${BOLD}π Main Menu β Select Action:${NC}"
echo "1) Grant access"
echo "2) Revoke access"
echo "3) Show current access list"
echo "4) Show RPC links"
echo "5) Back"
echo -n -e "${CYAN}Choose option: ${NC}"
read mainopt
case $mainopt in
1|2)
ACTION=$([[ $mainopt == 1 ]] && echo "grant" || echo "revoke")
echo -ne "${CYAN}π Enter IP to $ACTION access (or type 'all'): ${NC}"
read IP
[[ "$IP" == "all" ]] && IP="0.0.0.0/0" && echo -e "${YELLOW}β οΈ Allowing ALL access β use with caution!${NC}"
while true; do
echo -e "\n${YELLOW}${BOLD}β‘οΈ Which RPC do you want to $ACTION access for?${NC}"
echo "1) Sepolia (8545)"
echo "2) Beacon (3500)"
echo "3) Both"
echo "4) Back"
echo -n -e "${CYAN}Choose option: ${NC}"
read rpcopt
case $rpcopt in
1) ports=(8545) ;;
2) ports=(3500) ;;
3) ports=(8545 3500) ;;
4) break ;;
*) echo -e "${RED}β Invalid choice. Try again.${NC}"; continue ;;
esac
for PORT in "${ports[@]}"; do
if [[ "$ACTION" == "grant" ]]; then
sudo iptables -I INPUT -p tcp --dport "$PORT" -s "$IP" -j ACCEPT 2>/dev/null
echo -e "${GREEN}β
Granted access to $IP on port $PORT${NC}"
else
sudo iptables -D INPUT -p tcp --dport "$PORT" -s "$IP" -j ACCEPT 2>/dev/null
echo -e "${RED}β Revoked access for $IP on port $PORT${NC}"
fi
done
echo -e "${CYAN}\nReturning to main menu in 2s...${NC}"
sleep 2
break
done
;;
3)
echo -e "\n${YELLOW}${BOLD}π‘ Current Access List:${NC}"
ips_8545=$(sudo iptables -L INPUT -n | grep "tcp dpt:8545" | grep ACCEPT | awk '{print $4}')
ips_3500=$(sudo iptables -L INPUT -n | grep "tcp dpt:3500" | grep ACCEPT | awk '{print $4}')
mapfile -t list_8545 <<< "$ips_8545"
mapfile -t list_3500 <<< "$ips_3500"
both_ports=(); only_8545=(); only_3500=()
for ip in "${list_8545[@]}"; do
[[ " ${list_3500[*]} " == *" $ip "* ]] && both_ports+=("$ip") || only_8545+=("$ip")
done
for ip in "${list_3500[@]}"; do
[[ ! " ${list_8545[*]} " == *" $ip "* ]] && only_3500+=("$ip")
done
if [[ ${#both_ports[@]} -eq 0 && ${#only_8545[@]} -eq 0 && ${#only_3500[@]} -eq 0 ]]; then
echo -e "${RED}β No IPs have access.${NC}"
else
[[ ${#both_ports[@]} -gt 0 ]] && echo -e "${CYAN}π Both Ports (8545 & 3500):${NC}" && for ip in "${both_ports[@]}"; do echo -e " ${GREEN}- $ip"; done
[[ ${#only_8545[@]} -gt 0 ]] && echo -e "${CYAN}πΈ Port 8545 only:${NC}" && for ip in "${only_8545[@]}"; do echo -e " ${GREEN}- $ip"; done
[[ ${#only_3500[@]} -gt 0 ]] && echo -e "${CYAN}πΈ Port 3500 only:${NC}" && for ip in "${only_3500[@]}"; do echo -e " ${GREEN}- $ip"; done
fi
read -p $'\nPress enter to return to menu...' dummy
;;
4)
DETECTED_IP=$(curl -s ifconfig.me)
echo -e "${CYAN}π Detected Public IP: ${GREEN}$DETECTED_IP${NC}"
echo -ne "${CYAN}π₯ Press Enter to use it, or type your own IP/domain: ${NC}"
read custom_ip
[[ -z "$custom_ip" ]] && IP="$DETECTED_IP" || IP="$custom_ip"
echo -e "\n${GREEN}π RPC Endpoints:"
echo -e " β’ Sepolia : ${CYAN}http://$IP:8545${NC}"
echo -e " β’ Beacon : ${CYAN}http://$IP:3500${NC}\n"
read -p $'Press enter to return to menu...' dummy
;;
5) break ;;
*) echo -e "${RED}β Invalid choice. Try again.${NC}" ;;
esac
done
}
handle_choice() {
case "$1" in
1)
install_dependencies
install_docker
check_ports
create_directories
write_compose_file
start_services
;;
2)
if [ -f "$BASE_DIR/docker-compose.yml" ]; then
cd "$BASE_DIR"
echo -e "${YELLOW}π Showing logs... Ctrl+C to exit.${NC}"
sudo docker compose logs -f
else
echo -e "${RED}β No docker-compose.yml found. Please run installation first.${NC}"
fi
;;
3)
check_node_status
;;
4)
print_rpc_endpoints
;;
5)
access_controller
;;
6)
echo -e "${CYAN}π Goodbye!${NC}"
exit 0
;;
*)
echo -e "${RED}β Invalid input. Enter 1, 2, 3, or 4.${NC}"
;;
esac
}
main() {
while true; do
print_banner
read -r choice
handle_choice "$choice"
echo ""
read -rp "Press Enter to return to the menu..."
done
}
main