From 74451f4977ed4ab79f1ca7e2f6023f88cd9d5f49 Mon Sep 17 00:00:00 2001
From: onefang
Date: Sat, 28 Dec 2019 03:49:40 +1000
Subject: Refactor the executers into an actual class type thingy.
---
apt-panopticommon.lua | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
(limited to 'apt-panopticommon.lua')
diff --git a/apt-panopticommon.lua b/apt-panopticommon.lua
index c9194fa..a19f1e3 100644
--- a/apt-panopticommon.lua
+++ b/apt-panopticommon.lua
@@ -450,6 +450,65 @@ APT.fork = function(s)
os.execute(s .. " &")
end
+
+APT.exe = function(c)
+ local exe = {status = 0, result = ''}
+ exe.cmd = c .. ' '
+ exe.log = false
+
+ function exe:log()
+ self.log = true
+ return self
+ end
+ function exe:Nice(c)
+ self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' '
+ return self
+ end
+ function exe:And(c)
+ if nil == c then c = '' else c = ' ' .. c end
+ self.cmd = self.cmd .. '&&' .. c .. ' '
+ return self
+ end
+ function exe:Or(c)
+ if nil == c then c = '' end
+ self.cmd = self.cmd .. '|| ' .. c .. ' '
+ return self
+ end
+ function exe:noErr()
+ self.cmd = self.cmd .. '2>/dev/null '
+ return self
+ end
+ function exe:wait(w)
+ self.cmd = self.cmd .. '&& touch ' .. w .. ' '
+ return self
+ end
+ function exe:Do()
+ if self.log then D(" executing - " .. self.cmd .. "
") end
+ --[[ Damn os.execute()
+ Lua 5.1 says it returns "a status code, which is system-dependent"
+ Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
+ I'm getting 7168 or 0. No idea what the fuck that is.
+ local ok, rslt, status = os.execute(s)
+ ]]
+ local f = io.popen(self.cmd .. ' ; echo "$?"', 'r')
+ -- The last line will be the command's returned status, collect everything else in result.
+ for l in f:lines() do
+ self.result = self.result .. self.status .. "\n"
+ self.status = l
+ end
+ self.status = tonumber(self.status)
+ return self
+ end
+ function exe:fork()
+ self.cmd = '{ ' .. self.cmd .. '; } &'
+ if self.log then D(" forking - " .. self.cmd .. "
") end
+ os.execute(self.cmd)
+ return self
+ end
+ return exe
+end
+
+
APT.checkExes = function (exe)
local count = io.popen('ps x | grep "' .. exe .. '" | grep -v " grep " | grep -v "flock -n apt-panopticon.lock " | wc -l'):read("*l")
D(count .. " " .. exe .. " commands still running.")
--
cgit v1.1