Added auto-intall of xmrig support for Windows OS (gross).

This commit is contained in:
justin committed 2025-11-20 15:54:51 -07:00
1 parent ab417b09ec
commit 7e922317b1
1 file changed
+82 -32
+82 -32
View File
@@ -13,6 +13,7 @@ import signal
import platform import platform
import urllib.request import urllib.request
import tarfile import tarfile
import zipfile
import re import re
from pathlib import Path from pathlib import Path
from typing import Dict, Optional, Tuple from typing import Dict, Optional, Tuple
@@ -43,6 +44,8 @@ class MoneroMiner:
return 'arm64' return 'arm64'
elif machine in ['x86_64', 'amd64', 'x64']: elif machine in ['x86_64', 'amd64', 'x64']:
return 'x64' return 'x64'
elif machine in ['i386', 'i686', 'x86']:
return 'x86'
else: else:
return machine return machine
@@ -82,6 +85,13 @@ class MoneroMiner:
patterns = ['linux-static-x64.tar.gz', 'linux-x64.tar.gz', 'linux-x86_64.tar.gz'] patterns = ['linux-static-x64.tar.gz', 'linux-x64.tar.gz', 'linux-x86_64.tar.gz']
else: else:
return None return None
elif os_type == 'windows':
if arch == 'x64':
patterns = ['msvc-win64.zip', 'win64.zip', 'windows-x64.zip']
elif arch == 'x86':
patterns = ['msvc-win32.zip', 'win32.zip', 'windows-x86.zip']
else:
return None
else: else:
return None return None
@@ -102,19 +112,31 @@ class MoneroMiner:
] ]
for path in local_paths: for path in local_paths:
if os.path.exists(path) and os.access(path, os.X_OK): if os.path.exists(path) and os.access(path, os.X_OK if os.name != 'nt' else os.F_OK):
return True return True
# Check in system PATH # Check in system PATH (Unix-like systems)
try: if os.name != 'nt':
result = subprocess.run(['which', 'xmrig'], try:
capture_output=True, result = subprocess.run(['which', 'xmrig'],
text=True, capture_output=True,
timeout=5) text=True,
if result.returncode == 0: timeout=5)
return True if result.returncode == 0:
except: return True
pass except:
pass
else:
# Windows - check with 'where' command
try:
result = subprocess.run(['where', 'xmrig.exe'],
capture_output=True,
text=True,
timeout=5)
if result.returncode == 0:
return True
except:
pass
return False return False
@@ -126,8 +148,8 @@ class MoneroMiner:
print(f"\nDetected OS: {os_type}") print(f"\nDetected OS: {os_type}")
print(f"Detected Architecture: {arch}") print(f"Detected Architecture: {arch}")
if os_type not in ['macos', 'linux']: if os_type not in ['macos', 'linux', 'windows']:
print(f"\nAutomatic installation is currently only supported for macOS and Linux.") print(f"\nAutomatic installation is not supported for this OS.")
print(f"Please install XMRig manually from: https://github.com/xmrig/xmrig/releases") print(f"Please install XMRig manually from: https://github.com/xmrig/xmrig/releases")
return False return False
@@ -151,7 +173,7 @@ class MoneroMiner:
print(f"\nCould not find a compatible XMRig release for {os_type} {arch}") print(f"\nCould not find a compatible XMRig release for {os_type} {arch}")
print(f"Available files:") print(f"Available files:")
for asset in assets: for asset in assets:
if asset.endswith('.tar.gz'): if asset.endswith(('.tar.gz', '.zip')):
print(f" - {asset}") print(f" - {asset}")
print("\nPlease download manually from: https://github.com/xmrig/xmrig/releases") print("\nPlease download manually from: https://github.com/xmrig/xmrig/releases")
return False return False
@@ -163,12 +185,14 @@ class MoneroMiner:
print(f"\nReady to download: {filename}") print(f"\nReady to download: {filename}")
print(f"URL: {download_url}") print(f"URL: {download_url}")
# Prompt user # Prompt user (default to Yes)
while True: while True:
response = input("\nDownload and install XMRig? (Y/N): ").strip().upper() response = input("\nDownload and install XMRig? (Y/N) [Y]: ").strip().upper()
if response == '':
response = 'Y'
if response in ['Y', 'N']: if response in ['Y', 'N']:
break break
print("Please enter Y or N") print("Please enter Y or N (or press ENTER for Yes)")
if response == 'N': if response == 'N':
print("Installation cancelled.") print("Installation cancelled.")
@@ -226,19 +250,44 @@ class MoneroMiner:
# Extract # Extract
print("Extracting archive...") print("Extracting archive...")
try: try:
with tarfile.open(local_filename, 'r:gz') as tar: is_zip = filename.endswith('.zip')
# Find the xmrig binary in the archive
for member in tar.getmembers():
if member.name.endswith('/xmrig') or member.name == 'xmrig':
member.name = 'xmrig'
tar.extract(member, self.script_dir)
break
xmrig_path = os.path.join(self.script_dir, 'xmrig') if is_zip:
# Windows ZIP file
with zipfile.ZipFile(local_filename, 'r') as zip_ref:
# Find the xmrig.exe binary in the archive
xmrig_found = False
for member in zip_ref.namelist():
if member.endswith('xmrig.exe') or member == 'xmrig.exe':
# Extract to script directory with name 'xmrig.exe'
with zip_ref.open(member) as source:
target_path = os.path.join(self.script_dir, 'xmrig.exe')
with open(target_path, 'wb') as target:
target.write(source.read())
xmrig_found = True
break
# Make executable if not xmrig_found:
os.chmod(xmrig_path, 0o755) print("Could not find xmrig.exe in the archive")
print(f"XMRig installed successfully at: {xmrig_path}") return False
xmrig_path = os.path.join(self.script_dir, 'xmrig.exe')
print(f"XMRig installed successfully at: {xmrig_path}")
else:
# Unix TAR.GZ file
with tarfile.open(local_filename, 'r:gz') as tar:
# Find the xmrig binary in the archive
for member in tar.getmembers():
if member.name.endswith('/xmrig') or member.name == 'xmrig':
member.name = 'xmrig'
tar.extract(member, self.script_dir)
break
xmrig_path = os.path.join(self.script_dir, 'xmrig')
# Make executable (Unix-like systems)
os.chmod(xmrig_path, 0o755)
print(f"XMRig installed successfully at: {xmrig_path}")
# Clean up # Clean up
os.remove(local_filename) os.remove(local_filename)
@@ -281,11 +330,12 @@ class MoneroMiner:
# Get wallet address from user # Get wallet address from user
wallet_address = self.prompt_wallet_address() wallet_address = self.prompt_wallet_address()
# Determine xmrig path - use ./xmrig for both macOS and Linux # Determine xmrig path based on OS
if os_type in ['macos', 'linux']: if os_type == 'windows':
miner_executable = "./xmrig" miner_executable = "xmrig.exe"
else: else:
miner_executable = "xmrig.exe" # Windows # macOS and Linux
miner_executable = "./xmrig"
config = { config = {
"wallet_address": wallet_address, "wallet_address": wallet_address,