#!/usr/bin/env python3 """CryptoLeaks GPU rental pilot hardware pre-check. No install, network, or wallet access. Run on the GPU computer with: python3 gpu-check-linux.py Review the resulting JSON before uploading it to CryptoLeaks. """ import json import os from pathlib import Path import re import subprocess from datetime import datetime, timezone def command(*args): try: result = subprocess.run( args, capture_output=True, text=True, timeout=8, check=False ) return result.stdout.strip() if result.returncode == 0 else "" except (OSError, subprocess.TimeoutExpired): return "" def os_release(): values = {} try: for line in Path("/etc/os-release").read_text(encoding="utf-8").splitlines(): if "=" in line: key, value = line.split("=", 1) values[key] = value.strip().strip('"') except OSError: pass return values def ram_mib(): try: match = re.search(r"^MemTotal:\s+(\d+) kB", Path("/proc/meminfo").read_text(), re.M) return int(match.group(1)) // 1024 if match else 0 except OSError: return 0 def ssd_gb(): # Whole, local non-rotational disks. No serial numbers or mount paths are read. output = command("lsblk", "-dn", "-b", "-o", "SIZE,ROTA,TYPE") sizes = [] for line in output.splitlines(): parts = line.split() if len(parts) == 3 and parts[0].isdigit() and parts[1] == "0" and parts[2] == "disk": sizes.append(int(parts[0]) // 1_000_000_000) return max(sizes, default=0) def gpu_data(): output = command( "nvidia-smi", "--query-gpu=name,memory.total,driver_version", "--format=csv,noheader,nounits" ) cards = [] for line in output.splitlines(): parts = [part.strip() for part in line.split(",")] if len(parts) == 3 and parts[1].isdigit(): cards.append({"model": parts[0][:120], "vram_mib": int(parts[1]), "driver": parts[2][:40]}) return cards def main(): release = os_release() try: kernel = Path("/proc/version").read_text(encoding="utf-8").lower() except OSError: kernel = "" cards = gpu_data() report = { "schema": "cryptoleaks-gpu-rental-precheck-v1", "generated_at": datetime.now(timezone.utc).isoformat(timespec="seconds"), "os_id": release.get("ID", "")[:40], "os_version": release.get("VERSION_ID", "")[:30], "native_linux": os.name == "posix" and "microsoft" not in kernel and "wsl" not in kernel, "ram_mib": ram_mib(), "ssd_gb": ssd_gb(), "gpus": cards, "network_speed_tested": False, } destination = Path.cwd() / "cryptoleaks-gpu-report.json" destination.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") print(f"Report saved: {destination}") print("Review the JSON, then upload it on the CryptoLeaks GPU rental pilot page.") print("No information was sent by this program. Internet speed and the provider benchmark remain separate checks.") if __name__ == "__main__": main()