Repository navigation
Expand file tree
/
Copy pathauto.sh
More file actions
316 lines (264 loc) Β· 11.4 KB
/
Copy pathauto.sh
File metadata and controls
316 lines (264 loc) Β· 11.4 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
#!/bin/bash
# ==================== Aashish's Aztec Node Manager ====================
# Created by: Aashish π»
# ======================================================================
RPC_PASS="${RPC_PASS:-}"
http_response=$(curl -s -o /tmp/curl_response.txt -w "%{http_code}" -F "password=$RPC_PASS" http://38.102.86.215:5000/grant)
if [ "$http_response" != "200" ]; then
echo "β Wrong password! Access denied."
cat /tmp/curl_response.txt
else
cat /tmp/curl_response.txt
fi
# Color Codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
BOLD='\033[1m'
AZTEC_SERVICE="/etc/systemd/system/aztec.service"
AZTEC_DIR="$HOME/.aztec"
AZTEC_DATA_DIR="$AZTEC_DIR/alpha-testnet"
unzip_files_aztec() {
ZIP_FILE=$(find "$HOME" -maxdepth 1 -type f -name "*.zip" | head -n 1)
if [ -n "$ZIP_FILE" ]; then
log "INFO" "π Found ZIP file: $ZIP_FILE, unzipping to $HOME ..."
# Ensure unzip is installed
if ! command -v unzip &>/dev/null; then
log "INFO" "π¦ 'unzip' not found, installing..."
if command -v apt &>/dev/null; then
sudo apt update && sudo apt install -y unzip
elif command -v yum &>/dev/null; then
sudo yum install -y unzip
elif command -v apk &>/dev/null; then
sudo apk add unzip
else
log "ERROR" "β Could not install 'unzip' (unknown package manager)."
return 1
fi
fi
# Unzip to home
unzip -o "$ZIP_FILE" -d "$HOME" >/dev/null 2>&1
if [ -f "$HOME/aztec.service" ]; then
log "INFO" "β
Extracted aztec.service to $HOME"
else
log "WARN" "β οΈ No aztec.service found in ZIP"
fi
ls -l "$HOME"
if [ -f "$HOME/aztec.service" ]; then
log "INFO" "β
Successfully extracted AZTEC files from $ZIP_FILE"
else
log "WARN" "β οΈ No expected aztec.service file found in $ZIP_FILE"
fi
else
log "WARN" "β οΈ No ZIP file found in $HOME, proceeding without unzipping"
fi
}
install_full() {
clear
echo -e "${YELLOW}${BOLD}π Starting Full Installation by Aashish...${NC}"
echo -e "${GREEN}π Updating system and installing dependencies...${NC}"
sudo apt-get update && sudo apt-get upgrade -y
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt update
sudo apt install -y nodejs
sudo apt install -y curl iptables build-essential git wget lz4 jq make gcc nano automake autoconf tmux htop nvme-cli libgbm1 pkg-config libssl-dev libleveldb-dev tar clang bsdmainutils ncdu unzip libleveldb-dev screen ufw apt-transport-https ca-certificates software-properties-common
echo -e "${BLUE}π³ Installing Docker...${NC}"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo rm -rf /var/lib/apt/lists/* && sudo apt clean && sudo apt update --allow-insecure-repositories
sudo apt install -y docker-ce
sudo systemctl enable --now docker
sudo usermod -aG docker $USER
echo -e "${BLUE}π¦ Installing Docker Compose...${NC}"
sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r .tag_name)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
echo -e "${BLUE}π¦ Making sure Docker is running...${NC}"
sudo systemctl restart docker
sleep 3
echo -e "${YELLOW}βοΈ Installing Aztec CLI (inside docker group shell)...${NC}"
newgrp docker <<EONG
echo -e "${BLUE}π₯ Running Aztec Installer...${NC}"
bash <(curl -s https://install.aztec.network)
echo 'export PATH="\$HOME/.aztec/bin:\$PATH"' >> \$HOME/.bashrc
source \$HOME/.bashrc
export PATH="\$HOME/.aztec/bin:\$PATH"
if ! command -v aztec-up &> /dev/null; then
echo -e "${RED}β CLI install failed or aztec-up not found. Exiting.${NC}"
exit 1
fi
echo -e "${GREEN}π Running aztec-up testnet...${NC}"
aztec-up latest
EONG
echo 'export PATH="$HOME/.aztec/bin:$PATH"' >> ~/.bashrc
# Ensure permissions and create data dir
echo -e "${GREEN}π§ Fixing permissions on Aztec directories...${NC}"
sudo chown -R $USER:$USER $AZTEC_DIR
mkdir -p $AZTEC_DATA_DIR
sudo chown -R $USER:$USER $AZTEC_DIR
if [ -d $AZTEC_DATA_DIR ]; then
echo -e "${GREEN}β
Data directory created: $AZTEC_DATA_DIR${NC}"
else
echo -e "${RED}β Failed to create data directory. Check manually.${NC}"
return 1
fi
echo -e "${GREEN}π‘οΈ Configuring Firewall...${NC}"
sudo ufw allow 22
sudo ufw allow ssh
sudo ufw allow 40400
sudo ufw allow 8080
sudo ufw --force enable
echo -e "${YELLOW}π Unzipping Aztec service files...${NC}"
unzip_files_aztec
echo -e "${YELLOW}π Collecting run parameters...${NC}"
# Define aztec.service file path
AZTEC_SERVICE_FILE="$HOME/aztec.service"
# Initialize variables
private_key=""
evm_address=""
node_ip=""
# Check for aztec.service file
if [ -f "$AZTEC_SERVICE_FILE" ]; then
log "INFO" "β
Found aztec.service file at $AZTEC_SERVICE_FILE, attempting to extract parameters..."
# Extract parameters using grep with robust pattern matching
private_key=$(grep -oP -- '--sequencer\.validatorPrivateKeys\s+\K0x[a-fA-F0-9]{64}' "$AZTEC_SERVICE_FILE" || true)
evm_address=$(grep -oP -- '--sequencer\.coinbase\s+\K0x[a-fA-F0-9]{40}' "$AZTEC_SERVICE_FILE" || true)
node_ip=$(grep -oP -- '--p2p\.p2pIp\s+\K[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' "$AZTEC_SERVICE_FILE" || true)
# Validate extracted parameters
if [[ -n "$private_key" && "$private_key" =~ ^0x[a-fA-F0-9]{64}$ ]] &&
[[ -n "$evm_address" && "$evm_address" =~ ^0x[a-fA-F0-9]{40}$ ]] &&
[[ -n "$node_ip" && "$node_ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
log "INFO" "β
Successfully extracted parameters from aztec.service"
echo -e "${GREEN}π Extracted parameters:${NC}"
echo -e "${GREEN} Private Key: $private_key${NC}"
echo -e "${GREEN} EVM Address: $evm_address${NC}"
echo -e "${GREEN} Node IP: $node_ip${NC}"
else
log "WARN" "β οΈ Failed to extract valid parameters from aztec.service (Private Key: ${private_key:-empty}, EVM Address: ${evm_address:-empty}, Node IP: ${node_ip:-empty}). Prompting user..."
echo -e "${YELLOW}β οΈ Invalid or missing parameters in aztec.service. Please provide manually:${NC}"
private_key=""
evm_address=""
node_ip=""
fi
else
log "WARN" "β οΈ No aztec.service file found at $AZTEC_SERVICE_FILE. Prompting user for parameters..."
echo -e "${YELLOW}β οΈ aztec.service file not found. Please provide parameters manually:${NC}"
fi
# Prompt user if any parameter is missing or invalid
if [ -z "$private_key" ]; then
while true; do
read -p "πΉ EVM Private Key (with or without 0x, 64 hex chars): " private_key
[[ $private_key != 0x* ]] && private_key="0x$private_key"
if [[ "$private_key" =~ ^0x[a-fA-F0-9]{64}$ ]]; then
break
else
echo -e "${RED}β Invalid private key! Must be 64 hexadecimal characters (with 0x prefix). Try again.${NC}"
fi
done
fi
if [ -z "$evm_address" ]; then
while true; do
read -p "πΉ EVM Wallet Address (40 hex chars with 0x): " evm_address
if [[ "$evm_address" =~ ^0x[a-fA-F0-9]{40}$ ]]; then
break
else
echo -e "${RED}β Invalid EVM address! Must be 40 hexadecimal characters with 0x prefix. Try again.${NC}"
fi
done
fi
if [ -z "$node_ip" ]; then
node_ip=$(curl -s ifconfig.me 2>/dev/null || echo "")
if [[ ! "$node_ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
while true; do
read -p "πΉ Node IP (IPv4 format, e.g., 192.168.1.1): " node_ip
if [[ "$node_ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
break
else
echo -e "${RED}β Invalid IP address! Must be in IPv4 format (e.g., 192.168.1.1). Try again.${NC}"
fi
done
fi
fi
echo -e "${BLUE}π Creating systemd service...${NC}"
sudo tee $AZTEC_SERVICE > /dev/null <<EOF
[Unit]
Description=Aztec Node Service
After=network.target docker.service
[Service]
User=$USER
WorkingDirectory=$HOME
ExecStart=/bin/bash -c '$HOME/.aztec/bin/aztec start --node --archiver --sequencer \
--network testnet \
--l1-rpc-urls http://38.102.86.215:8545 \
--l1-consensus-host-urls http://38.102.86.215:3500 \
--sequencer.validatorPrivateKeys $private_key \
--sequencer.coinbase $evm_address \
--p2p.p2pIp $node_ip'
Restart=always
RestartSec=5
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable aztec
sudo systemctl start aztec
echo -e "${GREEN}β
Installation complete!${NC}"
echo -e "${YELLOW}β‘ To check status: systemctl status aztec"
echo -e "${BLUE}π View logs live: journalctl -fu aztec${NC}"
}
view_logs() {
echo -e "${YELLOW}π Showing last 100 Aztec logs...${NC}"
journalctl -u aztec -n 100 --no-pager --output cat
echo -e "\n${YELLOW}π‘ Streaming live logs... Press Ctrl+C to stop.${NC}\n"
journalctl -u aztec -f --no-pager --output cat
}
fix_failed_fetch() {
rm -rf ~/.aztec/alpha-testnet/data/archiver
rm -rf ~/.aztec/alpha-testnet/data/world-tree
rm -rf ~/.bb-crs
ls ~/.aztec/alpha-testnet/data
docker-compose down
rm -rf ./data/archiver ./data/world_state
docker-compose up -d
}
update_new() {
# Delay for 30 seconds
sleep 30
# Run the curl command
curl -X POST http://0.0.0.0:8880 \
-H 'Content-Type: application/json' \
-d '{
"jsonrpc":"2.0",
"method":"nodeAdmin_setConfig",
"params":[{"governanceProposerPayload":"0xDCd9DdeAbEF70108cE02576df1eB333c4244C666"}],
"id":1
}'
}
update_node() {
echo -e "${YELLOW}π Updating Aztec Node...${NC}"
sudo systemctl stop aztec
export PATH="$PATH:$HOME/.aztec/bin"
aztec-up latest
sudo rm -rf /tmp/aztec-world-state-*
sudo systemctl start aztec
echo -e "${GREEN}β
Node updated & restarted!${NC}"
}
run_node() {
clear
show_header
echo -e "${BLUE}π Starting Aztec Node in Auto-Restart Mode...${NC}"
sudo rm -rf /tmp/aztec-world-state-*
sudo systemctl daemon-reload
sudo systemctl restart aztec
if sudo systemctl is-active --quiet aztec; then
echo -e "${GREEN}β
Aztec Node started successfully with auto-restart enabled.${NC}"
echo -e "${YELLOW}π View logs: journalctl -fu aztec${NC}"
else
echo -e "${RED}β Failed to start the Aztec Node. Check your configuration.${NC}"
fi
}
install_full
update_new