2017-12-01 00:21:33 -06:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
|
|
|
---------------------------------------------------
|
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local pairs = pairs
|
|
|
|
local tonumber = tonumber
|
|
|
|
local io = { popen = io.popen }
|
|
|
|
local math = { ceil = math.ceil }
|
|
|
|
local los = { getenv = os.getenv }
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local helpers = require("vicious.helpers")
|
|
|
|
local string = {
|
2017-12-17 12:06:39 -06:00
|
|
|
gsub = string.gsub,
|
|
|
|
match = string.match
|
2017-12-01 00:21:33 -06:00
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- OS: provides operating system information
|
|
|
|
-- vicious.widgets.os
|
|
|
|
local os = {}
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ Operating system widget type
|
|
|
|
local function worker(format)
|
2017-12-17 12:06:39 -06:00
|
|
|
local system = {
|
|
|
|
["ostype"] = "N/A",
|
|
|
|
["hostname"] = "N/A",
|
|
|
|
["osrelease"] = "N/A",
|
|
|
|
["username"] = "N/A",
|
|
|
|
["entropy"] = "N/A",
|
|
|
|
["entropy_p"] = "N/A"
|
|
|
|
}
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06: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]*$", "")
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
2017-12-17 12:06:39 -06:00
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
-- BSD manual page: uname(1)
|
|
|
|
if system["ostype"] == "N/A" then
|
|
|
|
local f = io.popen("uname -snr")
|
|
|
|
local uname = f:read("*line")
|
|
|
|
f:close()
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
system["ostype"], system["hostname"], system["osrelease"] =
|
|
|
|
string.match(uname, "([%w]+)[%s]([%w%p]+)[%s]([%w%p]+)")
|
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06: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)
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
-- Get available entropy and calculate percentage
|
|
|
|
system["entropy"] = tonumber(kernel.random.entropy_avail)
|
|
|
|
system["entropy_p"] = math.ceil(system["entropy"] * 100 / poolsize)
|
|
|
|
end
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
-- Get user from the environment
|
|
|
|
system["username"] = los.getenv("USER")
|
2017-12-01 00:21:33 -06:00
|
|
|
|
2017-12-17 12:06:39 -06:00
|
|
|
return {system["ostype"], system["osrelease"], system["username"],
|
|
|
|
system["hostname"], system["entropy"], system["entropy_p"]}
|
2017-12-01 00:21:33 -06:00
|
|
|
end
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
return setmetatable(os, { __call = function(_, ...) return worker(...) end })
|