| 1 | -- operating system widget type for GNU/Linux |
| 2 | -- Copyright (C) 2010 Adrian C. <[email protected]> |
| 3 | -- Copyright (C) 2019 Nguyễn Gia Phong <[email protected]m> |
| 4 | -- Copyright (C) 2019 mutlusun <[email protected]> |
| 5 | -- |
| 6 | -- This file is part of Vicious. |
| 7 | -- |
| 8 | -- Vicious is free software: you can redistribute it and/or modify |
| 9 | -- it under the terms of the GNU General Public License as |
| 10 | -- published by the Free Software Foundation, either version 2 of the |
| 11 | -- License, or (at your option) any later version. |
| 12 | -- |
| 13 | -- Vicious is distributed in the hope that it will be useful, |
| 14 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | -- GNU General Public License for more details. |
| 17 | -- |
| 18 | -- You should have received a copy of the GNU General Public License |
| 19 | -- along with Vicious. If not, see <https://www.gnu.org/licenses/>. |
| 20 | |
| 21 | -- {{{ Grab environment |
| 22 | local pairs = pairs |
| 23 | local tonumber = tonumber |
| 24 | local math = { ceil = math.ceil } |
| 25 | local los = { getenv = os.getenv } |
| 26 | local string = { gsub = string.gsub } |
| 27 | |
| 28 | local helpers = require"vicious.helpers" |
| 29 | -- }}} |
| 30 | |
| 31 | -- {{{ Operating system widget type |
| 32 | return helpers.setcall(function () |
| 33 | local system = { |
| 34 | ["ostype"] = "N/A", |
| 35 | ["hostname"] = "N/A", |
| 36 | ["osrelease"] = "N/A", |
| 37 | ["username"] = "N/A", |
| 38 | ["entropy"] = "N/A", |
| 39 | ["entropy_p"] = "N/A" |
| 40 | } |
| 41 | |
| 42 | -- Linux manual page: uname(2) |
| 43 | local kernel = helpers.pathtotable("/proc/sys/kernel") |
| 44 | for k, _ in pairs(system) do |
| 45 | if kernel[k] then |
| 46 | system[k] = string.gsub(kernel[k], "[%s]*$", "") |
| 47 | end |
| 48 | end |
| 49 | |
| 50 | -- Linux manual page: random(4) |
| 51 | if kernel.random then |
| 52 | -- Linux 2.6 default entropy pool is 4096-bits |
| 53 | local poolsize = tonumber(kernel.random.poolsize) |
| 54 | |
| 55 | -- Get available entropy and calculate percentage |
| 56 | system["entropy"] = tonumber(kernel.random.entropy_avail) |
| 57 | system["entropy_p"] = math.ceil(system["entropy"] * 100 / poolsize) |
| 58 | end |
| 59 | |
| 60 | -- Get user from the environment |
| 61 | system["username"] = los.getenv("USER") |
| 62 | |
| 63 | return {system["ostype"], system["osrelease"], system["username"], |
| 64 | system["hostname"], system["entropy"], system["entropy_p"]} |
| 65 | end) |
| 66 | -- }}} |