Last active
February 25, 2020 13:03
-
-
Save vugi99/878f68a1f3953840090f285c417c7482 to your computer and use it in GitHub Desktop.
Get os and arch for Onset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getOS() | |
local raw_os_name, raw_arch_name = '', '' | |
-- Unix-based OS | |
raw_os_name = io.popen('uname -s','r'):read('*l') | |
raw_arch_name = io.popen('uname -m','r'):read('*l') | |
if raw_os_name == nil and raw_arch_name == nil then | |
-- Windows | |
local env_OS = os.getenv('OS') | |
local env_ARCH = os.getenv('PROCESSOR_ARCHITECTURE') | |
if env_OS and env_ARCH then | |
raw_os_name, raw_arch_name = env_OS, env_ARCH | |
end | |
end | |
raw_os_name = (raw_os_name):lower() | |
raw_arch_name = (raw_arch_name):lower() | |
local os_patterns = { | |
['windows'] = 'Windows', | |
['linux'] = 'Linux', | |
['mac'] = 'Mac', | |
['darwin'] = 'Mac', | |
['^mingw'] = 'Windows', | |
['^cygwin'] = 'Windows', | |
['bsd$'] = 'BSD', | |
['SunOS'] = 'Solaris', | |
} | |
local arch_patterns = { | |
['^x86$'] = 'x86', | |
['i[%d]86'] = 'x86', | |
['amd64'] = 'x86_64', | |
['x86_64'] = 'x86_64', | |
['Power Macintosh'] = 'powerpc', | |
['^arm'] = 'arm', | |
['^mips'] = 'mips', | |
} | |
local os_name, arch_name = 'unknown', 'unknown' | |
for pattern, name in pairs(os_patterns) do | |
if raw_os_name:match(pattern) then | |
os_name = name | |
break | |
end | |
end | |
for pattern, name in pairs(arch_patterns) do | |
if raw_arch_name:match(pattern) then | |
arch_name = name | |
break | |
end | |
end | |
return os_name, arch_name | |
end | |
local os_name, arch_name = getOS() | |
print(os_name .. " " .. arch_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment