forked from Scottcjn/Rustchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·372 lines (325 loc) · 13.5 KB
/
setup.sh
File metadata and controls
executable file
·372 lines (325 loc) · 13.5 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
#!/usr/bin/env bash
# =============================================================================
# RustChain Miner Setup Wizard
# Installs and configures a RustChain miner in under 60 seconds.
# Supports: Ubuntu, Debian, Fedora, macOS (Intel + Apple Silicon + PowerPC)
# Usage: curl -sSL https://raw.githubusercontent.com/Scottcjn/Rustchain/main/setup.sh | bash
# =============================================================================
set -euo pipefail
RC_NODE_PRIMARY="https://50.28.86.131"
RC_NODE_BACKUP="https://50.28.86.153"
RC_MINER_URL="https://raw.githubusercontent.com/Scottcjn/Rustchain/main/rustchain_linux_miner.py"
RC_FP_URL="https://raw.githubusercontent.com/Scottcjn/Rustchain/main/fingerprint_checks.py"
INSTALL_DIR="$HOME/.rustchain"
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; BOLD='\033[1m'; NC='\033[0m'
banner() {
echo -e "${BOLD}${BLUE}"
echo " ██████╗ ██╗ ██╗███████╗████████╗ ██████╗██╗ ██╗ █████╗ ██╗███╗ ██╗"
echo " ██╔══██╗██║ ██║██╔════╝╚══██╔══╝██╔════╝██║ ██║██╔══██╗██║████╗ ██║"
echo " ██████╔╝██║ ██║███████╗ ██║ ██║ ███████║███████║██║██╔██╗ ██║"
echo " ██╔══██╗██║ ██║╚════██║ ██║ ██║ ██╔══██║██╔══██║██║██║╚██╗██║"
echo " ██║ ██║╚██████╔╝███████║ ██║ ╚██████╗██║ ██║██║ ██║██║██║ ╚████║"
echo " ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝"
echo -e "${NC}"
echo -e " ${BOLD}Miner Setup Wizard${NC} — From Zero to Mining in 60 Seconds"
echo ""
}
info() { echo -e " ${GREEN}✓${NC} $1"; }
warn() { echo -e " ${YELLOW}⚠${NC} $1"; }
error() { echo -e " ${RED}✗ ERROR:${NC} $1"; exit 1; }
heading() { echo -e "\n${BOLD}[$1]${NC}"; }
# ---------------------------------------------------------------------------- #
# 1. Detect Platform
# ---------------------------------------------------------------------------- #
detect_platform() {
heading "Detecting Platform"
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Linux*) PLATFORM="linux" ;;
Darwin*) PLATFORM="macos" ;;
*) error "Unsupported OS: $OS" ;;
esac
# CPU architecture and antiquity multiplier
case "$ARCH" in
x86_64) ARCH_NAME="x86_64 (modern)" ; MULTIPLIER="1.0" ;;
aarch64|arm64) ARCH_NAME="ARM64/Apple Silicon" ; MULTIPLIER="1.2" ;;
ppc64|ppc64le) ARCH_NAME="PowerPC 64-bit" ; MULTIPLIER="3.5" ;;
ppc) ARCH_NAME="PowerPC 32-bit" ; MULTIPLIER="3.2" ;;
*) ARCH_NAME="$ARCH (unknown)" ; MULTIPLIER="1.0" ;;
esac
# Core count
if [ "$PLATFORM" = "linux" ]; then
CPU_CORES=$(nproc 2>/dev/null || echo 2)
CPU_THREADS=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || echo "$CPU_CORES")
RAM_GB=$(awk '/MemTotal/ { printf "%.0f\n", $2/1024/1024 }' /proc/meminfo 2>/dev/null || echo "?")
# Detect distro
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO="${ID:-linux}"
else
DISTRO="linux"
fi
else
CPU_CORES=$(sysctl -n hw.physicalcpu 2>/dev/null || echo 2)
CPU_THREADS=$(sysctl -n hw.logicalcpu 2>/dev/null || echo "$CPU_CORES")
RAM_GB=$(( $(sysctl -n hw.memsize 2>/dev/null || echo 2147483648) / 1073741824 ))
DISTRO="macos"
fi
# Recommend threads (leave 2 for OS)
RECOMMENDED_THREADS=$(( CPU_CORES > 2 ? CPU_CORES - 2 : 1 ))
info "Platform: $PLATFORM ($DISTRO)"
info "CPU: $ARCH_NAME — $CPU_CORES cores, $CPU_THREADS threads"
info "RAM: ${RAM_GB} GB"
echo -e " ${BOLD}Antiquity multiplier: ${MULTIPLIER}x${NC}"
echo -e " ${BOLD}Recommended threads: $RECOMMENDED_THREADS${NC}"
if [ "$ARCH" = "ppc" ] || [ "$ARCH" = "ppc64" ] || [ "$ARCH" = "ppc64le" ]; then
echo -e "\n ${YELLOW}★ Running on PowerPC? You earn ${MULTIPLIER}x rewards! You're a rare miner. ★${NC}"
fi
}
# ---------------------------------------------------------------------------- #
# 2. Check Python
# ---------------------------------------------------------------------------- #
check_python() {
heading "Checking Python"
PYTHON=""
for cmd in python3.12 python3.11 python3.10 python3.9 python3.8 python3; do
if command -v "$cmd" >/dev/null 2>&1; then
VER=$("$cmd" -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
MAJOR=$(echo "$VER" | cut -d. -f1)
MINOR=$(echo "$VER" | cut -d. -f2)
if [ "$MAJOR" -ge 3 ] && [ "$MINOR" -ge 8 ]; then
PYTHON="$cmd"
info "Python $VER found at $(command -v $cmd)"
break
fi
fi
done
if [ -z "$PYTHON" ]; then
warn "Python 3.8+ not found. Attempting to install..."
case "$DISTRO" in
ubuntu|debian) sudo apt-get install -y python3 python3-pip ;;
fedora|rhel|centos) sudo dnf install -y python3 python3-pip ;;
macos) brew install python3 ;;
*) error "Could not install Python. Please install Python 3.8+ manually." ;;
esac
PYTHON="python3"
fi
# Install requests if needed
if ! "$PYTHON" -c "import requests" >/dev/null 2>&1; then
info "Installing requests library..."
"$PYTHON" -m pip install requests --quiet 2>/dev/null || true
fi
}
# ---------------------------------------------------------------------------- #
# 3. Download Miner Files
# ---------------------------------------------------------------------------- #
download_files() {
heading "Downloading Miner Files"
mkdir -p "$INSTALL_DIR"
if command -v curl >/dev/null 2>&1; then
DL="curl -sSL -o"
elif command -v wget >/dev/null 2>&1; then
DL="wget -qO"
else
error "Neither curl nor wget found. Please install one."
fi
info "Downloading rustchain_linux_miner.py..."
$DL "$INSTALL_DIR/rustchain_linux_miner.py" "$RC_MINER_URL" 2>/dev/null || \
warn "Could not download miner (may not exist yet in upstream)"
info "Downloading fingerprint_checks.py..."
$DL "$INSTALL_DIR/fingerprint_checks.py" "$RC_FP_URL" 2>/dev/null || \
warn "Could not download fingerprint checks"
info "Files saved to $INSTALL_DIR/"
}
# ---------------------------------------------------------------------------- #
# 4. Create Wallet
# ---------------------------------------------------------------------------- #
setup_wallet() {
heading "Wallet Setup"
if [ -f "$INSTALL_DIR/config.json" ]; then
EXISTING_WALLET=$(python3 -c "import json; d=json.load(open('$INSTALL_DIR/config.json')); print(d.get('wallet_name',''))" 2>/dev/null || echo "")
if [ -n "$EXISTING_WALLET" ]; then
info "Existing wallet found: $EXISTING_WALLET"
read -p " Use existing wallet? [Y/n] " USE_EXISTING
if [ "${USE_EXISTING:-Y}" != "n" ] && [ "${USE_EXISTING:-Y}" != "N" ]; then
WALLET_NAME="$EXISTING_WALLET"
return
fi
fi
fi
echo ""
echo -e " Choose a wallet name (letters, numbers, hyphens). This is your identity on the network."
while true; do
read -p " Wallet name: " WALLET_NAME
if echo "$WALLET_NAME" | grep -qE '^[a-zA-Z0-9][a-zA-Z0-9_-]{2,31}$'; then
break
else
warn "Invalid name. Use 3-32 chars: letters, numbers, hyphens, underscores."
fi
done
info "Wallet name set: $WALLET_NAME"
}
# ---------------------------------------------------------------------------- #
# 5. Test Connectivity
# ---------------------------------------------------------------------------- #
test_connectivity() {
heading "Testing Node Connectivity"
NODE_URL=""
for node in "$RC_NODE_PRIMARY" "$RC_NODE_BACKUP"; do
echo -n " Testing $node ... "
STATUS=$(curl -sk --max-time 8 "$node/health" 2>/dev/null | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('status','?'))" 2>/dev/null || echo "timeout")
if [ "$STATUS" = "ok" ] || [ "$STATUS" = "unknown" ]; then
echo -e "${GREEN}OK${NC} (status: $STATUS)"
NODE_URL="$node"
break
else
echo -e "${YELLOW}$STATUS${NC}"
fi
done
if [ -z "$NODE_URL" ]; then
warn "Could not reach any node. Check your internet connection."
NODE_URL="$RC_NODE_PRIMARY"
warn "Using $NODE_URL as fallback (may fail at mining time)"
else
info "Using node: $NODE_URL"
fi
}
# ---------------------------------------------------------------------------- #
# 6. Write Config
# ---------------------------------------------------------------------------- #
write_config() {
heading "Writing Configuration"
cat > "$INSTALL_DIR/config.json" << JSONEOF
{
"wallet_name": "$WALLET_NAME",
"node_url": "$NODE_URL",
"threads": $RECOMMENDED_THREADS,
"arch": "$ARCH",
"platform": "$PLATFORM",
"multiplier": "$MULTIPLIER",
"install_dir": "$INSTALL_DIR"
}
JSONEOF
info "Config saved: $INSTALL_DIR/config.json"
}
# ---------------------------------------------------------------------------- #
# 7. Run Fingerprint Test
# ---------------------------------------------------------------------------- #
run_fingerprint() {
heading "Fingerprint Test"
if [ ! -f "$INSTALL_DIR/fingerprint_checks.py" ]; then
warn "fingerprint_checks.py not found, skipping fingerprint test"
return
fi
echo " Running hardware fingerprint checks..."
cd "$INSTALL_DIR"
"$PYTHON" fingerprint_checks.py 2>&1 | while IFS= read -r line; do echo " $line"; done
cd - >/dev/null
}
# ---------------------------------------------------------------------------- #
# 8. Install Service (optional)
# ---------------------------------------------------------------------------- #
install_service() {
heading "Service Installation (Optional)"
read -p " Install as system service (auto-start on boot)? [y/N] " INSTALL_SVC
if [ "${INSTALL_SVC:-N}" != "y" ] && [ "${INSTALL_SVC:-N}" != "Y" ]; then
info "Skipping service installation"
return
fi
if [ "$PLATFORM" = "linux" ]; then
SERVICE_FILE="$HOME/.config/systemd/user/rustchain-miner.service"
mkdir -p "$(dirname "$SERVICE_FILE")"
cat > "$SERVICE_FILE" << SVCEOF
[Unit]
Description=RustChain Miner — $WALLET_NAME
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=$INSTALL_DIR
ExecStart=$PYTHON $INSTALL_DIR/rustchain_linux_miner.py
Restart=on-failure
RestartSec=30
Environment="WALLET_NAME=$WALLET_NAME"
Environment="NODE_URL=$NODE_URL"
Environment="THREADS=$RECOMMENDED_THREADS"
[Install]
WantedBy=default.target
SVCEOF
systemctl --user daemon-reload
systemctl --user enable rustchain-miner.service
info "Systemd service installed (user session)"
info "Start with: systemctl --user start rustchain-miner"
elif [ "$PLATFORM" = "macos" ]; then
PLIST_FILE="$HOME/Library/LaunchAgents/ai.rustchain.miner.plist"
mkdir -p "$(dirname "$PLIST_FILE")"
cat > "$PLIST_FILE" << PLISTEOF
<?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>ai.rustchain.miner</string>
<key>ProgramArguments</key>
<array>
<string>$PYTHON</string>
<string>$INSTALL_DIR/rustchain_linux_miner.py</string>
</array>
<key>RunAtLoad</key> <true/>
<key>KeepAlive</key> <true/>
<key>WorkingDirectory</key> <string>$INSTALL_DIR</string>
<key>EnvironmentVariables</key>
<dict>
<key>WALLET_NAME</key> <string>$WALLET_NAME</string>
<key>NODE_URL</key> <string>$NODE_URL</string>
<key>THREADS</key> <string>$RECOMMENDED_THREADS</string>
</dict>
<key>StandardOutPath</key> <string>$INSTALL_DIR/miner.log</string>
<key>StandardErrorPath</key> <string>$INSTALL_DIR/miner-error.log</string>
</dict>
</plist>
PLISTEOF
launchctl load "$PLIST_FILE" 2>/dev/null || true
info "launchd service installed"
info "Start with: launchctl start ai.rustchain.miner"
fi
}
# ---------------------------------------------------------------------------- #
# 9. Summary
# ---------------------------------------------------------------------------- #
summary() {
heading "Setup Complete"
echo ""
echo -e " ${BOLD}Your Miner${NC}"
echo -e " Wallet: ${GREEN}$WALLET_NAME${NC}"
echo -e " Node: ${GREEN}$NODE_URL${NC}"
echo -e " Threads: ${GREEN}$RECOMMENDED_THREADS${NC}"
echo -e " Arch: ${GREEN}$ARCH_NAME${NC}"
echo -e " Multiplier:${GREEN} ${MULTIPLIER}x${NC}"
echo ""
echo -e " ${BOLD}To start mining:${NC}"
echo -e " cd $INSTALL_DIR && $PYTHON rustchain_linux_miner.py"
echo ""
echo -e " ${BOLD}Check your balance:${NC}"
echo -e " curl -sk '$NODE_URL/wallet/$WALLET_NAME' | python3 -m json.tool"
echo ""
echo -e " ${BOLD}Join the community:${NC}"
echo -e " Discord: https://discord.gg/rustchain"
echo -e " GitHub: https://github.com/Scottcjn/Rustchain"
echo ""
echo -e " ${GREEN}Happy mining! ⛏️${NC}"
echo ""
}
# ---------------------------------------------------------------------------- #
# Main
# ---------------------------------------------------------------------------- #
banner
detect_platform
check_python
download_files
setup_wallet
test_connectivity
write_config
run_fingerprint
install_service
summary