2010-03-12 03:37:39 +01:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local pairs = pairs
|
2010-03-15 17:52:02 +01:00
|
|
|
local tonumber = tonumber
|
2010-03-12 03:37:39 +01:00
|
|
|
local io = { popen = io.popen }
|
2010-03-15 17:52:02 +01:00
|
|
|
local math = { ceil = math.ceil }
|
2012-06-25 00:39:23 +02:00
|
|
|
local los = { getenv = os.getenv }
|
2010-03-12 03:37:39 +01:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
local helpers = require("vicious.helpers")
|
|
|
|
local string = {
|
|
|
|
gsub = string.gsub,
|
|
|
|
match = string.match
|
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- OS: provides operating system information
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.os
|
2017-01-25 17:54:44 +01:00
|
|
|
local os_all = {}
|
2010-03-12 03:37:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- {{{ Operating system widget type
|
|
|
|
local function worker(format)
|
|
|
|
local system = {
|
|
|
|
["ostype"] = "N/A",
|
|
|
|
["hostname"] = "N/A",
|
|
|
|
["osrelease"] = "N/A",
|
2010-03-15 17:52:02 +01:00
|
|
|
["username"] = "N/A",
|
|
|
|
["entropy"] = "N/A",
|
|
|
|
["entropy_p"] = "N/A"
|
2010-03-12 03:37:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Linux manual page: uname(2)
|
|
|
|
local kernel = helpers.pathtotable("/proc/sys/kernel")
|
|
|
|
for k, v in pairs(system) do
|
|
|
|
if kernel[k] then
|
|
|
|
system[k] = string.gsub(kernel[k], "[%s]*$", "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- BSD manual page: uname(1)
|
|
|
|
if system["ostype"] == "N/A" then
|
|
|
|
local f = io.popen("uname -snr")
|
|
|
|
local uname = f:read("*line")
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
system["ostype"], system["hostname"], system["osrelease"] =
|
|
|
|
string.match(uname, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
|
|
|
|
end
|
|
|
|
|
2010-03-15 17:52:02 +01:00
|
|
|
-- Linux manual page: random(4)
|
|
|
|
if kernel.random then
|
|
|
|
-- Linux 2.6 default entropy pool is 4096-bits
|
|
|
|
local poolsize = tonumber(kernel.random.poolsize)
|
|
|
|
|
|
|
|
-- Get available entropy and calculate percentage
|
|
|
|
system["entropy"] = tonumber(kernel.random.entropy_avail)
|
|
|
|
system["entropy_p"] = math.ceil(system["entropy"] * 100 / poolsize)
|
|
|
|
end
|
|
|
|
|
2010-03-12 03:37:39 +01:00
|
|
|
-- Get user from the environment
|
2012-06-25 00:39:23 +02:00
|
|
|
system["username"] = los.getenv("USER")
|
2010-03-12 03:37:39 +01:00
|
|
|
|
2010-03-15 17:52:02 +01:00
|
|
|
return {system["ostype"], system["osrelease"], system["username"],
|
|
|
|
system["hostname"], system["entropy"], system["entropy_p"]}
|
2010-03-12 03:37:39 +01:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
2017-01-25 17:54:44 +01:00
|
|
|
return setmetatable(os_all, { __call = function(_, ...) return worker(...) end })
|