forked from Scottcjn/Rustchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·485 lines (426 loc) · 16.2 KB
/
install.sh
File metadata and controls
executable file
·485 lines (426 loc) · 16.2 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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/bin/bash
#
# RustChain Miner - One-Line Installer
# curl -sSL https://raw.githubusercontent.com/Scottcjn/Rustchain/main/install.sh | bash
#
# Supports: Linux (x86_64, ppc64le), macOS (Intel, Apple Silicon, PPC), POWER8
# Features: virtualenv isolation, systemd/launchd auto-start, clean uninstall
#
set -e
REPO_BASE="https://raw.githubusercontent.com/Scottcjn/Rustchain/main/miners"
INSTALL_DIR="$HOME/.rustchain"
VENV_DIR="$INSTALL_DIR/venv"
NODE_URL="https://50.28.86.131"
SERVICE_NAME="rustchain-miner"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Parse command line arguments
UNINSTALL=false
WALLET_ARG=""
while [[ $# -gt 0 ]]; do
case $1 in
--uninstall)
UNINSTALL=true
shift
;;
--wallet)
WALLET_ARG="$2"
shift 2
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--uninstall] [--wallet WALLET_NAME]"
exit 1
;;
esac
done
# Uninstall mode
if [ "$UNINSTALL" = true ]; then
echo -e "${CYAN}[*] Uninstalling RustChain miner...${NC}"
# Stop and remove systemd service (Linux)
if [ "$(uname -s)" = "Linux" ] && command -v systemctl &>/dev/null; then
if systemctl --user list-unit-files | grep -q "$SERVICE_NAME.service"; then
echo -e "${YELLOW}[*] Stopping systemd service...${NC}"
systemctl --user stop "$SERVICE_NAME.service" 2>/dev/null || true
systemctl --user disable "$SERVICE_NAME.service" 2>/dev/null || true
rm -f "$HOME/.config/systemd/user/$SERVICE_NAME.service"
systemctl --user daemon-reload 2>/dev/null || true
echo -e "${GREEN}[+] Systemd service removed${NC}"
fi
fi
# Stop and remove launchd service (macOS)
if [ "$(uname -s)" = "Darwin" ]; then
PLIST_PATH="$HOME/Library/LaunchAgents/com.rustchain.miner.plist"
if [ -f "$PLIST_PATH" ]; then
echo -e "${YELLOW}[*] Stopping launchd service...${NC}"
launchctl unload "$PLIST_PATH" 2>/dev/null || true
rm -f "$PLIST_PATH"
echo -e "${GREEN}[+] Launchd service removed${NC}"
fi
fi
# Remove installation directory
if [ -d "$INSTALL_DIR" ]; then
echo -e "${YELLOW}[*] Removing installation directory...${NC}"
rm -rf "$INSTALL_DIR"
echo -e "${GREEN}[+] Installation directory removed${NC}"
fi
# Remove symlink
if [ -L "/usr/local/bin/rustchain-mine" ]; then
rm -f "/usr/local/bin/rustchain-mine" 2>/dev/null || true
fi
echo -e "${GREEN}[✓] RustChain miner uninstalled successfully${NC}"
exit 0
fi
echo -e "${CYAN}"
echo "╔═══════════════════════════════════════════════════════════════╗"
echo "║ RustChain Miner - Proof of Antiquity ║"
echo "║ Earn RTC by running vintage & modern hardware ║"
echo "╚═══════════════════════════════════════════════════════════════╝"
echo -e "${NC}"
# Detect platform
detect_platform() {
local os=$(uname -s)
local arch=$(uname -m)
case "$os" in
Linux)
case "$arch" in
x86_64)
# Check for POWER8 running in ppc64le mode
if grep -q "POWER8" /proc/cpuinfo 2>/dev/null; then
echo "power8"
else
echo "linux"
fi
;;
ppc64le|ppc64)
if grep -q "POWER8" /proc/cpuinfo 2>/dev/null; then
echo "power8"
else
echo "ppc"
fi
;;
ppc|powerpc)
echo "ppc"
;;
*)
echo "linux"
;;
esac
;;
Darwin)
case "$arch" in
arm64)
echo "macos" # Apple Silicon
;;
x86_64)
echo "macos" # Intel Mac
;;
Power*|ppc*)
echo "ppc" # PowerPC Mac
;;
*)
echo "macos"
;;
esac
;;
*)
echo "unknown"
;;
esac
}
# Check Python
check_python() {
if command -v python3 &>/dev/null; then
echo "python3"
elif command -v python &>/dev/null; then
# Check if it's Python 2.5+ (for vintage Macs)
local ver=$(python -c "import sys; print(sys.version_info[0])" 2>/dev/null)
if [ "$ver" = "2" ] || [ "$ver" = "3" ]; then
echo "python"
else
echo ""
fi
else
echo ""
fi
}
# Install dependencies
install_deps() {
local python_cmd=$1
echo -e "${YELLOW}[*] Setting up Python virtual environment...${NC}"
# Create virtualenv
if ! $python_cmd -m venv "$VENV_DIR" 2>/dev/null; then
echo -e "${YELLOW}[*] venv module not available, trying virtualenv...${NC}"
# Try installing virtualenv if not available
$python_cmd -m pip install --user virtualenv 2>/dev/null || pip install --user virtualenv 2>/dev/null || true
$python_cmd -m virtualenv "$VENV_DIR" 2>/dev/null || {
echo -e "${RED}[!] Could not create virtual environment${NC}"
echo -e "${RED}[!] Please install python3-venv or virtualenv${NC}"
exit 1
}
fi
echo -e "${GREEN}[+] Virtual environment created${NC}"
# Activate virtualenv and install dependencies
local venv_python="$VENV_DIR/bin/python"
local venv_pip="$VENV_DIR/bin/pip"
echo -e "${YELLOW}[*] Installing dependencies in virtualenv...${NC}"
$venv_pip install --upgrade pip 2>/dev/null || true
$venv_pip install requests 2>/dev/null || {
echo -e "${RED}[!] Could not install requests. Please check your internet connection.${NC}"
exit 1
}
echo -e "${GREEN}[+] Dependencies installed in isolated environment${NC}"
}
# Download miner files
download_miner() {
local platform=$1
echo -e "${YELLOW}[*] Downloading miner for: ${platform}${NC}"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
# Download main miner (using actual repo filenames)
case "$platform" in
linux)
curl -sSL "$REPO_BASE/linux/rustchain_linux_miner.py" -o rustchain_miner.py
curl -sSL "$REPO_BASE/linux/fingerprint_checks.py" -o fingerprint_checks.py
;;
macos)
curl -sSL "$REPO_BASE/macos/rustchain_mac_miner_v2.4.py" -o rustchain_miner.py
curl -sSL "$REPO_BASE/linux/fingerprint_checks.py" -o fingerprint_checks.py 2>/dev/null || true
;;
ppc)
curl -sSL "$REPO_BASE/ppc/rustchain_powerpc_g4_miner_v2.2.2.py" -o rustchain_miner.py
# PPC Macs may not support all fingerprint checks
;;
power8)
curl -sSL "$REPO_BASE/power8/rustchain_power8_miner.py" -o rustchain_miner.py
curl -sSL "$REPO_BASE/power8/fingerprint_checks_power8.py" -o fingerprint_checks.py
;;
*)
echo -e "${RED}[!] Unknown platform. Downloading generic Linux miner.${NC}"
curl -sSL "$REPO_BASE/linux/rustchain_linux_miner.py" -o rustchain_miner.py
curl -sSL "$REPO_BASE/linux/fingerprint_checks.py" -o fingerprint_checks.py
;;
esac
chmod +x rustchain_miner.py
}
# Configure wallet (sets WALLET_NAME global)
configure_wallet() {
local wallet_name=""
# Use wallet from argument if provided
if [ -n "$WALLET_ARG" ]; then
wallet_name="$WALLET_ARG"
echo -e "${GREEN}[+] Using wallet: ${wallet_name}${NC}"
else
echo ""
echo -e "${CYAN}[?] Enter your wallet name (or press Enter for auto-generated):${NC}"
read -r wallet_name < /dev/tty
if [ -z "$wallet_name" ]; then
wallet_name="miner-$(hostname)-$(date +%s | tail -c 6)"
echo -e "${YELLOW}[*] Using auto-generated wallet: ${wallet_name}${NC}"
fi
fi
if [[ ! "$wallet_name" =~ ^[a-zA-Z0-9_-]+$ ]]; then
echo -e "${RED}[!] Wallet name must be alphanumeric (hyphens and underscores allowed)${NC}"
exit 1
fi
# Set global for use by other functions
WALLET_NAME="$wallet_name"
}
# Create start script
create_start_script() {
local wallet=$1
local venv_python="$VENV_DIR/bin/python"
cat > "$INSTALL_DIR/start.sh" << EOF
#!/bin/bash
cd "$INSTALL_DIR"
$venv_python rustchain_miner.py --wallet "$wallet"
EOF
chmod +x "$INSTALL_DIR/start.sh"
# Also create a convenience symlink if possible
if [ -w "/usr/local/bin" ]; then
ln -sf "$INSTALL_DIR/start.sh" /usr/local/bin/rustchain-mine 2>/dev/null || true
fi
}
# Setup systemd service (Linux)
setup_systemd_service() {
local wallet=$1
local venv_python="$VENV_DIR/bin/python"
echo -e "${YELLOW}[*] Setting up systemd service for auto-start...${NC}"
# Create systemd user directory if it doesn't exist
mkdir -p "$HOME/.config/systemd/user"
# Create service file
cat > "$HOME/.config/systemd/user/$SERVICE_NAME.service" << EOF
[Unit]
Description=RustChain Miner - Proof of Antiquity
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=$INSTALL_DIR
ExecStart=$venv_python $INSTALL_DIR/rustchain_miner.py --wallet $wallet
Restart=always
RestartSec=10
StandardOutput=append:$INSTALL_DIR/miner.log
StandardError=append:$INSTALL_DIR/miner.log
[Install]
WantedBy=default.target
EOF
# Reload systemd and enable service
systemctl --user daemon-reload
systemctl --user enable "$SERVICE_NAME.service"
systemctl --user start "$SERVICE_NAME.service"
echo -e "${GREEN}[+] Systemd service installed and started${NC}"
echo -e "${CYAN}[i] Service commands:${NC}"
echo -e " Start: systemctl --user start $SERVICE_NAME"
echo -e " Stop: systemctl --user stop $SERVICE_NAME"
echo -e " Status: systemctl --user status $SERVICE_NAME"
echo -e " Logs: journalctl --user -u $SERVICE_NAME -f"
}
# Setup launchd service (macOS)
setup_launchd_service() {
local wallet=$1
local venv_python="$VENV_DIR/bin/python"
echo -e "${YELLOW}[*] Setting up launchd service for auto-start...${NC}"
# Create LaunchAgents directory if it doesn't exist
mkdir -p "$HOME/Library/LaunchAgents"
# Create plist file
cat > "$HOME/Library/LaunchAgents/com.rustchain.miner.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.rustchain.miner</string>
<key>ProgramArguments</key>
<array>
<string>$venv_python</string>
<string>-u</string> <!-- Unbuffered output for real-time logging -->
<string>$INSTALL_DIR/rustchain_miner.py</string>
<string>--wallet</string>
<string>$wallet</string>
</array>
<key>WorkingDirectory</key>
<string>$INSTALL_DIR</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>$INSTALL_DIR/miner.log</string>
<key>StandardErrorPath</key>
<string>$INSTALL_DIR/miner.log</string>
</dict>
</plist>
EOF
# Load the service
launchctl load "$HOME/Library/LaunchAgents/com.rustchain.miner.plist"
echo -e "${GREEN}[+] Launchd service installed and started${NC}"
echo -e "${CYAN}[i] Service commands:${NC}"
echo -e " Start: launchctl start com.rustchain.miner"
echo -e " Stop: launchctl stop com.rustchain.miner"
echo -e " Status: launchctl list | grep rustchain"
echo -e " Logs: tail -f $INSTALL_DIR/miner.log"
}
# Test connection
test_connection() {
echo -e "${YELLOW}[*] Testing connection to RustChain node...${NC}"
# Note: Using -k to bypass SSL verification as node may use self-signed cert
if curl -sSk "$NODE_URL/health" | grep -q '"ok":true'; then
echo -e "${GREEN}[+] Node connection successful!${NC}"
return 0
else
echo -e "${RED}[!] Could not connect to node. Check your internet connection.${NC}"
return 1
fi
}
# Main install
main() {
# Detect platform
local platform=$(detect_platform)
echo -e "${GREEN}[+] Detected platform: ${platform}${NC}"
# Check Python
local python_cmd=$(check_python)
if [ -z "$python_cmd" ]; then
echo -e "${RED}[!] Python not found. Please install Python 2.5+ or Python 3.${NC}"
exit 1
fi
echo -e "${GREEN}[+] Using: ${python_cmd}${NC}"
# Install deps in virtualenv
install_deps "$python_cmd"
# Download miner
download_miner "$platform"
# Configure
configure_wallet
# Create start script (now uses virtualenv python)
create_start_script "$WALLET_NAME"
# Test connection
test_connection
# Setup auto-start service
echo ""
echo -e "${CYAN}[?] Set up auto-start on boot? (y/n):${NC}"
read -r setup_autostart < /dev/tty
if [ "$setup_autostart" = "y" ] || [ "$setup_autostart" = "Y" ]; then
local os=$(uname -s)
case "$os" in
Linux)
if command -v systemctl &>/dev/null; then
setup_systemd_service "$WALLET_NAME"
else
echo -e "${YELLOW}[!] systemd not found. Auto-start not configured.${NC}"
fi
;;
Darwin)
setup_launchd_service "$WALLET_NAME"
;;
*)
echo -e "${YELLOW}[!] Auto-start not supported on this platform${NC}"
;;
esac
fi
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ Installation Complete! ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${CYAN}To start mining manually:${NC}"
echo -e " ${YELLOW}cd $INSTALL_DIR && ./start.sh${NC}"
echo ""
if [ -L "/usr/local/bin/rustchain-mine" ]; then
echo -e "${CYAN}Or use the convenience command:${NC}"
echo -e " ${YELLOW}rustchain-mine${NC}"
echo ""
fi
echo -e "${CYAN}Check your wallet balance:${NC}"
echo -e " ${YELLOW}curl -sk \"$NODE_URL/wallet/balance?miner_id=$WALLET_NAME\"${NC}"
echo ""
echo -e "${CYAN}View active miners:${NC}"
echo -e " ${YELLOW}curl -sk $NODE_URL/api/miners${NC}"
echo ""
echo -e "${CYAN}Check node health:${NC}"
echo -e " ${YELLOW}curl -sk $NODE_URL/health${NC}"
echo ""
echo -e "${CYAN}Check current epoch:${NC}"
echo -e " ${YELLOW}curl -sk $NODE_URL/epoch${NC}"
echo ""
echo -e "${CYAN}Miner files installed to:${NC} $INSTALL_DIR"
echo -e "${CYAN}Python environment:${NC} Isolated virtualenv at $VENV_DIR"
echo ""
echo -e "${CYAN}To uninstall:${NC}"
echo -e " ${YELLOW}curl -sSL https://raw.githubusercontent.com/Scottcjn/Rustchain/main/install.sh | bash -s -- --uninstall${NC}"
echo ""
# Ask to start now if service wasn't set up
if [ "$setup_autostart" != "y" ] && [ "$setup_autostart" != "Y" ]; then
echo -e "${CYAN}[?] Start mining now? (y/n):${NC}"
read -r start_now < /dev/tty
if [ "$start_now" = "y" ] || [ "$start_now" = "Y" ]; then
echo -e "${GREEN}[+] Starting miner...${NC}"
cd "$INSTALL_DIR"
exec "$VENV_DIR/bin/python" rustchain_miner.py --wallet "$WALLET_NAME"
fi
fi
}
main "$@"