aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-x.aataaj_JACK.lua132
-rwxr-xr-xaataaj.lua5
2 files changed, 137 insertions, 0 deletions
diff --git a/.aataaj_JACK.lua b/.aataaj_JACK.lua
new file mode 100755
index 0000000..b8b32a2
--- /dev/null
+++ b/.aataaj_JACK.lua
@@ -0,0 +1,132 @@
1#!/usr/bin/env luajit
2
3-- An example users .aataaj_JACK.lua script that just starts qsynth.
4
5
6-- Most of this APT stuff was copied from apt-panopticon.
7local APT = {}
8
9APT.readCmd = function(cmd)
10 local result = {}
11 local output = io.popen(cmd)
12 if nil ~= output then
13 for l in output:lines() do
14 table.insert(result, l)
15 end
16 end
17 return result
18end
19
20
21APT.exe = function(c)
22 local exe = {status = 0, result = '', lines = {}, log = true, cmd = c .. ' ', command = c}
23
24 function exe:log()
25 self.log = true
26 return self
27 end
28 function exe:Nice(c)
29 if nil == c then
30 self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd
31 else
32 self.cmd = self.cmd .. 'ionice -c3 nice -n 19 ' .. c .. ' '
33 end
34 return self
35 end
36 function exe:timeout(c)
37 -- timeout returns a status of - command status if --preserve-status; "128+9" (actually 137) if --kill-after ends up being done; 124 if it had to TERM; command status if all went well.
38 -- --kill-after means "send KILL after TERM fails.
39 if nil == c then
40 self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd
41 else
42 self.cmd = 'timeout --kill-after=10.0 --foreground ' .. c .. ' ' .. self.cmd
43 end
44 return self
45 end
46 function exe:also(c)
47 if nil == c then c = '' else c = ' ' .. c end
48 self.cmd = self.cmd .. ';' .. c .. ' '
49 return self
50 end
51 function exe:And(c)
52 if nil == c then c = '' else c = ' ' .. c end
53 self.cmd = self.cmd .. '&&' .. c .. ' '
54 return self
55 end
56 function exe:Or(c)
57 if nil == c then c = '' end
58 self.cmd = self.cmd .. '|| ' .. c .. ' '
59 return self
60 end
61 function exe:noErr()
62 self.cmd = self.cmd .. '2>/dev/null '
63 return self
64 end
65 function exe:wait(w)
66 self.cmd = self.cmd .. '&& touch ' .. w .. ' '
67 return self
68 end
69 function exe:Do()
70 --[[ "The condition expression of a control structure can return any
71 value. Both false and nil are considered false. All values different
72 from nil and false are considered true (in particular, the number 0
73 and the empty string are also true)."
74 says the docs, I beg to differ.]]
75 if true == self.log then D(" executing - &nbsp; <code>" .. self.cmd .. "</code>") end
76 --[[ Damn os.execute()
77 Lua 5.1 says it returns "a status code, which is system-dependent"
78 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
79 I'm getting 7168 or 0. No idea what the fuck that is.
80 local ok, rslt, status = os.execute(s)
81 ]]
82 local f = APT.readCmd(self.cmd, 'r')
83 -- The last line will be the command's returned status, collect everything else in result.
84 self.status = '' -- Otherwise the result starts with 0.
85 self.result = '\n'
86 self.lines = f
87 for i,l in ipairs(f) do
88 self.result = self.result .. l .. "\n"
89 end
90 f = APT.readCmd('echo "$?"', 'r')
91 for i,l in ipairs(f) do
92 self.status = tonumber(l)
93 if (137 == self.status) or (124 == self.status) then
94 print("timeout killed " .. self.status .. ' ' .. self.command)
95 E("timeout killed " .. self.status .. ' ' .. self.command)
96 elseif (0 ~= self.status) then
97 print("status |" .. self.status .. '| ' .. self.command)
98 E("status |" .. self.status .. '| ' .. self.command)
99 end
100 end
101 return self
102 end
103 function exe:fork(host)
104 if nil ~= host then self.cmd = self.cmd .. '; r=$?; if [ $r -ge 124 ]; then echo "$r ' .. host .. ' failed forked command ' .. string.gsub(self.cmd, '"', "'") .. '"; fi' end
105 self.cmd = '{ ' .. self.cmd .. '; } &'
106 if true == self.log then D(" forking - &nbsp; <code>" .. self.cmd .. "</code>") end
107 os.execute(self.cmd)
108 return self
109 end
110 return exe
111end
112
113APT.exists = function(c)
114 if 0 == APT.exe('which ' .. c):Do().status then return true end
115 return false
116end
117
118APT.killEmAll = function(all)
119 for i,l in ipairs(all) do
120 local c = 0
121 while 0 ~= tonumber(APT.exe("pgrep -u $USER -xc " .. l):Do().result) do
122 local s = 'TERM'
123 if c > 0 then s = 'KILL'; APT.exe("sleep " .. c):Do() end
124 print( "pkill -" .. s .. " -u $USER -x " .. l)
125 APT.exe("pkill -" .. s .. " -u $USER -x " .. l):Do()
126 c = c + 1
127 end
128 end
129end
130
131
132if APT.exists('qsynth') then APT.exe('qsynth'):fork() end
diff --git a/aataaj.lua b/aataaj.lua
index 5ba719b..5cc9423 100755
--- a/aataaj.lua
+++ b/aataaj.lua
@@ -567,4 +567,9 @@ elseif 'JACK' == args[1] then
567 APT.exe('sleep 4'):Do() 567 APT.exe('sleep 4'):Do()
568 APT.killEmAll{"jack-plumbing"} 568 APT.killEmAll{"jack-plumbing"}
569 end 569 end
570
571 if APT.exists('~/.aataaj_JACK.lua') then
572 print('Running users aataaj_JACK.lua')
573 APT.exe('~/.aataaj_JACK.lua'):Do()
574 end
570end 575end