From 9378edc09d4a0b9f19ef4314e0de7efa9634d849 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 3 Aug 2021 04:13:13 +0200 Subject: Support new conky and its dependency lua 5.3 --- README | 11 ++++++-- logs.lua | 3 +- netstat.conf | 2 +- scripts/run_conky.sh | 27 +++++++++++++----- support.lua | 79 +++++++++++++++++++++++++++++++++++----------------- sysinfo.conf | 2 +- 6 files changed, 85 insertions(+), 39 deletions(-) diff --git a/README b/README index 0837e48..df84597 100644 --- a/README +++ b/README @@ -1,4 +1,9 @@ + Requirements - luarocks install md5 - luarocks install luafilesystem - luarocks install lrexlib-pcre \ No newline at end of file + luarocks install md5 --lua-version 5.3 (seems not in rocks, install from gentoo) + luarocks install socket --lua-version 5.3 (seems not in rocks, install from gentoo) + luarocks install luafilesystem --lua-version 5.3 (seems not in rocks, install from gentoo) + luarocks install lrexlib-pcre --lua-version 5.3 + +Environemt: + eval "$(luarocks path --lua-version 5.3)" \ No newline at end of file diff --git a/logs.lua b/logs.lua index 051f2a7..8b50c98 100644 --- a/logs.lua +++ b/logs.lua @@ -1,4 +1,5 @@ -require "luarocks.require" +-- require "luarocks.require" + rex_pcre = require "rex_pcre" do diff --git a/netstat.conf b/netstat.conf index dfd9174..4e463a5 100644 --- a/netstat.conf +++ b/netstat.conf @@ -53,7 +53,7 @@ ${color white}KaaS/Router ${goto 160}${lua_parse check_service_ router iperouter ${color yellow}Servers ${hr}${lua set_width $template2}${lua set_timeout $template3} ${color white}ipepdvsrv1 ${goto 160}${lua_parse check_server_status ipepdvsrv1.ipe.kit.edu} ${color white}ipepdvsrv2 ${goto 160}${lua_parse check_server_status ipepdvsrv2.ipe.kit.edu} -${color white}ipepdvarchive ${goto 160}${lua_parse check_server_status ipepdvarchive.ipe.kit.edu} +#${color white}ipepdvarchive ${goto 160}${lua_parse check_server_status ipepdvarchive.ipe.kit.edu} ${color white}ipekatrin1 ${goto 160}${lua_parse check_server_status ipekatrin1.ipe.kit.edu 22 uptime} ${color white}ipekatrin2 ${goto 160}${lua_parse check_server_status ipekatrin2.ipe.kit.edu 22 uptime} ${color white}ipekatrin3 ${goto 160}${lua_parse check_server_status ipekatrin3.ipe.kit.edu 22 uptime} diff --git a/scripts/run_conky.sh b/scripts/run_conky.sh index 7648259..e718851 100755 --- a/scripts/run_conky.sh +++ b/scripts/run_conky.sh @@ -1,16 +1,19 @@ #!/bin/bash if [ "$1" != "start" ]; then - killall -9 conky - killall -9 rainlendar2 - killall -9 rainlendar2.bin + killall -9 conky &> /dev/null + killall -9 rainlendar2 &> /dev/null + killall -9 rainlendar2.bin &> /dev/null fi if [ "$1" != "stop" ]; then - python2 /opt/scripts/unlock.py gui || exit +#No way to do it anymore + python /opt/scripts/unlock.py gui || exit - killall -9 gpg-agent - pass test + killall -9 gpg-agent &> /dev/null + + /opt/scripts/restart-gpg.sh + pass test > /dev/null conky -q -d -c /etc/conky/sysinfo.conf conky -q -d -c /etc/conky/netstat.conf @@ -20,5 +23,15 @@ if [ "$1" != "stop" ]; then # todo should be loaded before forecast sleep 0.3 conky -q -d -c /etc/conky/forecast.conf - /opt/rainlendar2/rainlendar2 --quiet & + + +# sleep 1 +# ps xa | grep gpg-agent | grep -v gpg &> /dev/null +# if [ $? -ne 0 ]; then +# /opt/scripts/restart-gpg.sh +# fi + + +# Temporarily disabled. Only 2.16 works with google now and we don't have license. Might worth buying if use desktop again. +# /opt/rainlendar2/rainlendar2 --quiet & fi diff --git a/support.lua b/support.lua index 984d677..9b6735b 100644 --- a/support.lua +++ b/support.lua @@ -1,6 +1,7 @@ -require "luarocks.require" -require "md5" -require "lfs" +-- require "luarocks.require" +md5=require "md5" +lfs=require "lfs" +socket=require "socket" home = os.getenv( "HOME" ) @@ -10,10 +11,12 @@ c_timer_init = -1 do function conky_eval(...) + local arg = table.pack(...) return conky_parse(table.concat(arg, " ")) end function conky_multiply_line(times, ...) + local arg = table.pack(...) local str = table.concat(arg, " ") local tbl = {} for i=1,times,1 do @@ -50,7 +53,7 @@ do --]] local list = split(",", ips) for i, item in ipairs(list) do - if (string.match(item, "141\.52\.64")) then + if (string.match(item, "141%.52%.64")) then return item end end @@ -108,6 +111,7 @@ do function conky_check_server_status(server, port, ...) port = port or 22 + local arg = table.pack(...) local name = string.format("%s:%i", server, port); if (c_timer < 0) then @@ -133,6 +137,7 @@ do end f:close() end + if (result_check_server_status[name] == nil) then local res if (math.abs(c_timer)%2 > 0) then @@ -154,12 +159,17 @@ do elseif (c_timer == 0) then result_check_server_status[name] = check_server_status(server, port, arg) end - - return result_check_server_status[name]; + return (result_check_server_status[name] == nil) and "" or result_check_server_status[name] end - function check_server_status(server, port, additional) + function check_server_status(server, port, ...) port = port or 22 + local arg = table.pack(...) + local additional + + if arg ~= nil then + additional = arg[1] + end local res local cmd = string.format("/etc/conky/scripts/ping.pl %s:%i %i", server, port, timeout) @@ -168,7 +178,7 @@ do res = -1 else local data = cmdf:read("*a") - res = tonumber(data) + res = (data == nil) and -1 or tonumber(data) cmdf:close() end @@ -183,6 +193,10 @@ do return "${color red}*" end end + + if res == nil then + res = -1 + end if (res > 0) then online[server] = true @@ -196,13 +210,13 @@ do else local res = {} local line = cmdf:read("*l") - while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + while line do + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end line = cmdf:read("*l") - end + end -- res = cmdf:read("*a") cmdf:close() @@ -217,7 +231,7 @@ do end for i, service in ipairs(additional) - do + do cmd = string.format("ssh -x -p %i -o ConnectTimeout=%i root@%s /opt/scripts/check_%s_status.sh 2>&1 | fold -w %i", port, timeout, server, service, width) cmdf = cmd_popen(server, port, cmd) if (cmdf == nil) then @@ -226,7 +240,7 @@ do local res = {} local line = cmdf:read("*l") while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end @@ -239,9 +253,9 @@ do local s = 0 local extra = "" - local m1, m2 = string.match(info, "^\(%d+\)\(%s.+\)$") + local m1, m2 = string.match(info, "^(%d+)(%s.+)$") if (m1 == nil) then - m1 = string.match(info, "^\%d+$"); + m1 = string.match(info, "^(%d+)"); end if (m1 == nil) then table.insert(res, info) @@ -278,10 +292,11 @@ do online[server] = false res = string.format("${color red}* ") end - for i, service in ipairs(additional) do - res = res .. " " - end - + if (additional ~= nil) then + for i, service in ipairs(additional) do + res = res .. " " + end + end return res end end @@ -331,7 +346,7 @@ do local res = {} line = cmdf:read("*l") while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end @@ -341,7 +356,7 @@ do local info = table.remove(res) - local t1, t2, t3 = string.match(info, "^\(%d+\)%s+\(%d+\)%s+\(%d+\)") + local t1, t2, t3 = string.match(info, "^(%d+)%s+(%d+)%s+(%d+)") local s = tonumber(t1) if (s == nil) then @@ -387,6 +402,7 @@ do function conky_check_server_(service, server, port, ...) port = port or 22 + local arg = table.pack(...) local name = string.format("%s:%i:%s", server, port, service) if (c_timer < 0) then if (c_timer == -1) then @@ -420,6 +436,7 @@ do end function conky_check_service_(service, id, ...) + local arg = table.pack(...) local name = string.format("%s:%s", service, id) if (c_timer < 0) then if (c_timer == -1) then @@ -477,8 +494,14 @@ do local res = {} line = cmdf:read("*l") + if (line == nil) then + -- we can try another iteration? + socket.select(nil, nil, timeout) + line = cmdf:read("*l") + end + while line do - local m1 = string.match(line, "^\(.*[^%s]\)%s*$") + local m1 = string.match(line, "^(.*[^%s])%s*$") if (m1) then table.insert(res, m1) end @@ -488,7 +511,7 @@ do if (service == "traffic") then if (res[1]) then - local t1, t2, t3 = string.match(res[1], "^\(%d+\)%s+\(%d+\)%s+\(%d+\)") + local t1, t2, t3 = string.match(res[1], "^(%d+)%s+(%d+)%s+(%d+)") if (t1 and t2 and t3) then if ((opts) and (opts[1])) then yellow = tonumber(opts[1]) @@ -503,6 +526,8 @@ do else return "${color red}" .. res[1] end + else + return "${color red}?" end end @@ -512,7 +537,8 @@ do function check_service_(service, id, opts) - local cmd = string.format("/etc/conky/service/check_%s.sh %s %s 2>&1", service, id, table.concat(opts, " ")) + local optlist = ((opts == nil) and "" or table.concat(opts, " ")) + local cmd = string.format("/etc/conky/service/check_%s.sh %s %s 2>&1", service, id, optlist) cmdf = cmd_popen(service, id, cmd) if (cmdf == nil) then return "${color red}?" @@ -522,7 +548,7 @@ do local local_res = {} line = cmdf:read("*l") while line do - local t, m1 = string.match(line, "^\(\*?\)\(.*[^%s]\)%s*$") + local t, m1 = string.match(line, "^(%*?)(.*[^%s])%s*$") if (m1) then if (t == nil) or (t == '') then table.insert(res, m1) @@ -541,9 +567,10 @@ do local msg = '' if (info) then - t1, t2, msg = string.match(info, "^\(%d+\)%s+\(%d+\)\(.*\)") + t1, t2, msg = string.match(info, "^(%d+)%s+(%d+)(.*)") end + local s = tonumber(t1) if (s == nil) then table.insert(res, info) diff --git a/sysinfo.conf b/sysinfo.conf index ba0cd4b..ee5a48c 100644 --- a/sysinfo.conf +++ b/sysinfo.conf @@ -38,7 +38,7 @@ lua_load /etc/conky/support.lua # 7 - networking # 8 - ping + remote scripts template2 45 -template3 2 +template3 4 template5 120 template6 300 template7 600 -- cgit v1.2.3