Skip to content

Instantly share code, notes, and snippets.

@tempookian
Created March 15, 2023 13:51
Show Gist options
  • Save tempookian/b5328b64446c68035682d62166e4a2f3 to your computer and use it in GitHub Desktop.
Save tempookian/b5328b64446c68035682d62166e4a2f3 to your computer and use it in GitHub Desktop.
returns the current system to be used to download the correct version of xray
import platform
import sys
def detect_system():
current_system = platform.system().lower()
current_machine = platform.machine().lower()
if current_system == "linux":
if hasattr(sys, "getandroidapilevel"):
return ('android', 'arm64', 'v8a')
if "arm" in current_machine:
if "v5" in current_machine:
return ('linux', 'arm32', 'v5')
elif "v6" in current_machine:
return ('linux', 'arm32', 'v6')
elif "v7" in current_machine:
return ('linux', 'arm32', 'v7a')
elif "aarch64" in current_machine:
return ('linux', 'arm64', 'v8a')
elif "mips" in current_machine:
if "le" in current_machine:
return ('linux', 'mips32le')
else:
return ('linux', 'mips32')
elif "ppc64le" in current_machine:
return ('linux', 'ppc64le')
elif "ppc64" in current_machine:
return ('linux', 'ppc64')
elif "s390x" in current_machine:
return ('linux', 's390x')
elif "riscv64" in current_machine:
return ('linux', 'riscv64')
else:
if "64" in current_machine:
return ('linux', '64')
else:
return ('linux', '32')
elif current_system == "windows":
if "arm" in current_machine:
if "64" in current_machine:
return ('windows', 'arm64', 'v8a')
else:
return ('windows', 'arm32', 'v7a')
else:
if "64" in current_machine:
return ('windows', '64')
else:
return ('windows', '32')
elif current_system == "darwin":
if "arm" in current_machine:
return ('macos', 'arm64', 'v8a')
else:
return ('macos', '64')
elif current_system == "android":
if "arm64" in current_machine:
return ('android', 'arm64', 'v8a')
# add other systems as needed
else:
raise ValueError("Unsupported system: {}".format(current_system))
# example usage
print(detect_system())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment