-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
198 lines (167 loc) · 6.62 KB
/
setup.py
File metadata and controls
198 lines (167 loc) · 6.62 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
#!/usr/bin/env python3
"""
Monero Mining Controller - Setup Script
This script helps users set up their mining environment by:
1. Downloading XMRig for their platform
2. Creating initial configuration files
3. Installing Python dependencies
"""
import os
import sys
import platform
import subprocess
import urllib.request
import json
import shutil
from pathlib import Path
def run_command(cmd, description=""):
"""Run a command and handle errors"""
try:
print(f"🔧 {description}")
result = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
return True
except subprocess.CalledProcessError as e:
print(f"❌ Error: {e}")
print(f"Command output: {e.stderr}")
return False
def detect_platform():
"""Detect the platform and architecture"""
system = platform.system().lower()
machine = platform.machine().lower()
if system == "darwin":
try:
proc_info = subprocess.check_output(["sysctl", "-n", "machdep.cpu.brand_string"], text=True).strip()
is_intel = "Intel" in proc_info
except:
is_intel = "arm" not in machine and "aarch64" not in machine
return "macos-x64" if is_intel else "macos-arm64"
elif system == "linux":
if "x86_64" in machine or "amd64" in machine:
return "linux-x64"
elif "aarch64" in machine or "arm64" in machine:
return "linux-arm64"
else:
return "linux-x86"
elif system == "windows" or system == "nt":
return "windows-x64"
else:
return None
def download_xmrig(platform_type):
"""Download XMRig for the detected platform"""
print("🚀 Downloading XMRig...")
# Get latest release info
try:
request = urllib.request.Request("https://api.github.com/repos/xmrig/xmrig/releases/latest")
request.add_header("User-Agent", "Python")
with urllib.request.urlopen(request) as response:
release_data = json.loads(response.read().decode())
except:
print("❌ Could not fetch XMRig releases. Please download manually from https://github.com/xmrig/xmrig/releases")
return False
release_version = release_data.get("tag_name", "").lstrip("v")
platform_extensions = {
"macos-arm64": "macos-arm64.tar.gz",
"macos-x64": "macos-x64.tar.gz",
"linux-x64": "linux-x64.tar.gz",
"linux-arm64": "linux-arm64.tar.gz",
"windows-x64": "msvc-win64.zip"
}
ext = platform_extensions.get(platform_type)
if not ext:
print(f"❌ Unsupported platform: {platform_type}")
return False
asset_pattern = f"xmrig-{release_version}" if platform_type != "windows-x64" else f"xmrig-{release_version}-windows"
download_url = None
for asset in release_data.get("assets", []):
asset_name = asset["name"]
if platform_type == "windows-x64":
if f"xmrig-{release_version}" in asset_name and ext in asset_name:
download_url = asset["browser_download_url"]
break
else:
if ext in asset_name and f"xmrig-{release_version}" in asset_name:
download_url = asset["browser_download_url"]
break
if not download_url:
print(f"❌ Could not find download URL for {platform_type}")
return False
filename = f"xmrig-{platform_type}.tar.gz" if platform_type != "windows-x64" else f"xmrig-{platform_type}.zip"
try:
print(f"📥 Downloading from: {download_url}")
request = urllib.request.Request(download_url)
request.add_header("User-Agent", "Python")
with urllib.request.urlopen(request) as response, open(filename, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
except:
print("❌ Download failed. Please download manually.")
return False
# Extract the archive
print("📦 Extracting XMRig...")
if platform_type == "windows-x64":
import zipfile
with zipfile.ZipFile(filename, 'r') as zip_ref:
zip_ref.extractall(".")
else:
run_command(f"tar -xzf {filename}", "Extracting archive")
# Move xmrig binary to project root
xmrig_dirs = [d for d in os.listdir(".") if d.startswith("xmrig-") and os.path.isdir(d)]
if xmrig_dirs:
xmrig_dir = xmrig_dirs[0]
if os.path.exists(f"{xmrig_dir}/xmrig"):
shutil.move(f"{xmrig_dir}/xmrig", "xmrig")
elif os.path.exists(f"{xmrig_dir}/xmrig.exe"):
shutil.move(f"{xmrig_dir}/xmrig.exe", "xmrig.exe")
# Make executable on Unix systems
if platform.system() != "Windows":
os.chmod("xmrig", 0o755)
# Clean up
shutil.rmtree(xmrig_dir)
os.remove(filename)
print("✅ XMRig setup complete!")
return True
def create_config():
"""Create initial config.json from example"""
if os.path.exists("config.json.example") and not os.path.exists("config.json"):
print("📄 Creating config.json from template...")
shutil.copy("config.json.example", "config.json")
print("✅ Config file created! Please edit config.json with your wallet address and pool details.")
return True
return False
def install_dependencies():
"""Install Python dependencies"""
print("📦 Installing Python dependencies...")
return run_command(f"{sys.executable} -m pip install -r requirements.txt", "Installing dependencies")
def main():
print("🚀 Monero Mining Controller Setup")
print("=" * 40)
# Check Python version
if sys.version_info < (3, 8):
print("❌ Python 3.8+ required")
sys.exit(1)
# Detect platform
platform_type = detect_platform()
if not platform_type:
print("❌ Unsupported platform")
sys.exit(1)
print(f"✅ Detected platform: {platform_type}")
# Create config if needed
create_config()
# Install dependencies
if not install_dependencies():
print("❌ Failed to install dependencies")
sys.exit(1)
# Download XMRig
if not os.path.exists("xmrig") and not os.path.exists("xmrig.exe"):
if not download_xmrig(platform_type):
print("❌ Failed to download XMRig")
print("You can download it manually from: https://github.com/xmrig/xmrig/releases")
sys.exit(1)
else:
print("✅ XMRig already exists")
print("\n🎉 Setup complete!")
print("\nNext steps:")
print("1. Edit config.json with your Monero wallet address")
print("2. Run: python mining_controller.py")
print("3. Follow the interactive setup guide")
if __name__ == "__main__":
main()