-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·323 lines (283 loc) · 9.46 KB
/
setup.sh
File metadata and controls
executable file
·323 lines (283 loc) · 9.46 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
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LIB_DIR="${SCRIPT_DIR}/lib"
# Source helper libraries
source "${LIB_DIR}/colors.sh"
# Default values
DEFAULT_INSTALL_DIR="./bsv"
DEFAULT_DATA_DIR="./bsv-data"
NETWORK="mainnet"
NODE_TYPE="pruned"
SYNC_METHOD="snapshot"
BSV_VERSION="1.2.1"
# Configuration variables
INSTALL_DIR=""
DATA_DIR=""
RPC_USER=""
RPC_PASSWORD=""
print_banner() {
echo_blue "=================================================="
echo_blue " SVNode Quick Setup Script "
echo_blue "=================================================="
echo ""
}
prompt_yes_no() {
local prompt="$1"
local default="${2:-n}"
local response
if [[ "$default" == "y" ]]; then
prompt="$prompt [Y/n]: "
else
prompt="$prompt [y/N]: "
fi
read -p "$(echo_yellow "$prompt")" response
response=${response:-$default}
[[ "$response" =~ ^[Yy]$ ]]
}
menu_select() {
local prompt="$1"
shift
local options=("$@")
local selected=0
local key
# Hide cursor
tput civis
while true; do
# Clear screen and show menu
clear
echo_blue "=================================================="
echo_blue " SVNode Quick Setup Script "
echo_blue "=================================================="
echo ""
echo_yellow "$prompt"
echo ""
# Display options with selection indicator
for i in "${!options[@]}"; do
if [ $i -eq $selected ]; then
echo_green " → ${options[$i]}"
else
echo " ${options[$i]}"
fi
done
echo ""
echo_yellow "Use ↑/↓ arrow keys to navigate, Enter to select"
# Read single character
read -rsn1 key
case "$key" in
$'\x1b') # Escape sequence
read -rsn2 key
case "$key" in
'[A') # Up arrow
if [ $selected -gt 0 ]; then
selected=$((selected - 1))
fi
;;
'[B') # Down arrow
if [ $selected -lt $((${#options[@]} - 1)) ]; then
selected=$((selected + 1))
fi
;;
esac
;;
'') # Enter key
break
;;
'q'|'Q') # Quit
echo ""
echo_red "Setup cancelled."
tput cnorm # Show cursor
exit 1
;;
esac
done
# Show cursor again
tput cnorm
# Clear screen one more time and show selection
clear
echo_blue "=================================================="
echo_blue " SVNode Quick Setup Script "
echo_blue "=================================================="
echo ""
# Return the selected index (don't re-enable set -e here as it will exit on non-zero return)
return $selected
}
collect_user_preferences() {
echo_green "=== Configuration Setup ==="
echo ""
# Network selection
set +e
menu_select "Select network:" "Mainnet" "Testnet" "Regtest"
local network_choice=$?
set -e
case $network_choice in
0) NETWORK="mainnet" ;;
1) NETWORK="testnet" ;;
2) NETWORK="regtest" ;;
esac
echo_info "Network: $NETWORK"
echo ""
# Sync method selection first (not for regtest)
if [[ "$NETWORK" != "regtest" ]]; then
set +e
menu_select "Select sync method:" "Download snapshot (faster)" "Sync from genesis block (slower)"
local sync_choice=$?
set -e
case $sync_choice in
0)
SYNC_METHOD="snapshot"
# Auto-select node type based on network and snapshot choice
# Both mainnet and testnet snapshots are pruned
NODE_TYPE="pruned"
if [[ "$NETWORK" == "mainnet" ]]; then
echo_info "Mainnet snapshot selected - using pruned mode (200GB)"
else # testnet
echo_info "Testnet snapshot selected - using pruned mode (300GB)"
fi
;;
1)
SYNC_METHOD="genesis"
# For genesis sync, allow user to choose node type
if [[ "$NETWORK" == "mainnet" ]]; then
set +e
menu_select "Select node type:" "Pruned (minimal disk space ~200GB)" "Full (complete blockchain ~15TB)"
local node_choice=$?
set -e
case $node_choice in
0) NODE_TYPE="pruned" ;;
1) NODE_TYPE="full" ;;
esac
else # testnet
set +e
menu_select "Select node type:" "Pruned (minimal disk space ~200GB)" "Full (complete blockchain ~300GB)"
local node_choice=$?
set -e
case $node_choice in
0) NODE_TYPE="pruned" ;;
1) NODE_TYPE="full" ;;
esac
fi
;;
esac
echo_info "Sync method: $SYNC_METHOD"
echo_info "Node type: $NODE_TYPE"
echo ""
else
# Regtest is always full
NODE_TYPE="full"
SYNC_METHOD="genesis"
echo_info "Regtest mode - using full node configuration"
echo ""
fi
# Use default directories (relative to script location)
INSTALL_DIR="$DEFAULT_INSTALL_DIR"
DATA_DIR="$DEFAULT_DATA_DIR"
echo_info "Installation directory: $INSTALL_DIR"
echo_info "Data directory: $DATA_DIR"
echo ""
# RPC credentials
if prompt_yes_no "Generate random RPC credentials?" "y"; then
RPC_USER="bsv_rpc_$(openssl rand -hex 4)"
RPC_PASSWORD="bsv_pass_$(openssl rand -hex 16)"
echo_info "Generated RPC username: $RPC_USER"
echo_info "Generated RPC password: $RPC_PASSWORD"
echo_warning "Please save these credentials securely!"
else
read -p "$(echo_yellow "RPC username: ")" RPC_USER
read -s -p "$(echo_yellow "RPC password: ")" RPC_PASSWORD
echo ""
fi
echo ""
}
confirm_settings() {
echo_green "=== Configuration Summary ==="
echo "Network: $NETWORK"
echo "Node type: $NODE_TYPE"
[[ "$NETWORK" != "regtest" ]] && echo "Sync method: $SYNC_METHOD"
echo "Installation dir: $INSTALL_DIR"
echo "Data directory: $DATA_DIR"
echo "RPC username: $RPC_USER"
echo ""
if ! prompt_yes_no "Proceed with installation?" "y"; then
echo_red "Installation cancelled."
exit 1
fi
}
main() {
print_banner
# Check if running as root (warn but don't prevent)
if [[ $EUID -eq 0 ]]; then
echo_warning "Running as root. It's recommended to run as a regular user with sudo access."
if ! prompt_yes_no "Continue anyway?" "n"; then
exit 1
fi
fi
# Collect user preferences first (to determine node type)
collect_user_preferences
# Check system requirements after we know the node type
echo_info "Checking system requirements..."
if ! bash "${LIB_DIR}/check_requirements.sh" "$NODE_TYPE" "$NETWORK"; then
echo_red "System requirements check failed."
if ! prompt_yes_no "Continue anyway?" "n"; then
exit 1
fi
fi
echo_green "System requirements check complete."
echo ""
# Confirm settings
confirm_settings
# Create directories
echo_info "Creating directories..."
mkdir -p "$INSTALL_DIR"
mkdir -p "$DATA_DIR"
# Download and install SVNode
echo_info "Downloading SVNode v${BSV_VERSION}..."
bash "${LIB_DIR}/download_node.sh" "$BSV_VERSION" "$INSTALL_DIR"
# Generate configuration
echo_info "Generating bitcoin.conf..."
bash "${LIB_DIR}/config_generator.sh" \
"$NETWORK" \
"$NODE_TYPE" \
"$DATA_DIR" \
"$RPC_USER" \
"$RPC_PASSWORD"
# Sync snapshot if requested
if [[ "$SYNC_METHOD" == "snapshot" ]]; then
echo_info "Syncing blockchain snapshot..."
bash "${LIB_DIR}/snapshot_sync.sh" "$NETWORK" "$DATA_DIR"
fi
# Make helper scripts executable
echo_info "Setting up helper scripts..."
chmod +x "${SCRIPT_DIR}"/*.sh
echo ""
echo_green "=== Installation Complete ==="
echo ""
echo "Management Commands:"
echo " Start SVNode: ./start.sh"
echo " Stop SVNode: ./stop.sh"
echo " Restart SVNode: ./restart.sh"
echo " Use CLI: ./cli.sh <command>"
# Show network-specific log path
local log_path
if [[ "$NETWORK" == "testnet" ]]; then
log_path="${DATA_DIR}/testnet3/bitcoind.log"
elif [[ "$NETWORK" == "regtest" ]]; then
log_path="${DATA_DIR}/regtest/bitcoind.log"
else
log_path="${DATA_DIR}/bitcoind.log"
fi
echo " View logs: tail -f ${log_path}"
echo ""
echo "Examples:"
echo " ./cli.sh getblockchaininfo"
echo " ./cli.sh getpeerinfo"
echo " ./cli.sh help"
echo ""
echo_info "Configuration file: ${DATA_DIR}/bitcoin.conf"
echo_info "Data directory: ${DATA_DIR}"
echo ""
echo_green "Setup complete! Your SVNode is ready to use."
echo_info "Start with: ./start.sh"
}
# Run main function
main "$@"