aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xPolygLua.lua405
-rwxr-xr-xaataaj.lua104
-rwxr-xr-xtest_.lua186
3 files changed, 65 insertions, 630 deletions
diff --git a/PolygLua.lua b/PolygLua.lua
deleted file mode 100755
index 17abd88..0000000
--- a/PolygLua.lua
+++ /dev/null
@@ -1,405 +0,0 @@
1#!/usr/bin/env luajit
2
3--[[ PolygLua. Gluing things onto Lua, making it a polyglot language.
4
5TODO - Make the parsing recursive. So the command '--fancy' could have it's own options table.
6 --fancy option0 opt1=foo 'Random string!' --somethingElse
7 When to stop and hand back? First time we see a ' -bar' or ' --foo'?
8
9TODO - Add some sort of alias mechanism for the #! thing. _.bash'echo "This is bash."':Do()
10 The user can define their own aliases in a table, with defaults for bash, sh, luajit, and maybe some others.
11 Then extend it to changing language on the fly _.bash'echo "This is bash."':luajit("print('This is Lua.')"):Do()
12
13TODO - APT also has +/- for adding and removing option values into an options entry.
14 Not sure if that is being used.
15
16]]
17
18-- Most of this _ stuff was copied from apt-panopticon.
19local _ = {}
20_.version = '0.0 crap'
21
22
23_.verbosity = 2
24local log = function(v, t, s)
25 if v <= _.verbosity then
26 if 3 <= _.verbosity then t = os.date('!%F %T') .. ' ' .. t end
27 print(t .. ': ' .. s)
28 end
29 io.flush()
30end
31
32-- This sets the global values, here and in the caller. The "_G." part isn't needed, it's just there to make things more obvious to the reader.
33_G.D = function(s) log(4, 'DEBUG ', s) end
34_G.I = function(s) log(3, 'INFO ', s) end
35_G.T = function(s) log(2, 'TIMEOUT ', s) end
36_G.W = function(s) log(1, 'WARNING ', s) end
37_G.E = function(s) log(0, 'ERROR ', s) end
38_G.C = function(s) log(-1, 'CRITICAL ', s) end
39
40
41local optionsCommon =
42{
43 help = {help = 'Print the help text.',
44 func = function(self, options, a, args, i, name)
45 for i,v in ipairs{'/usr/share/doc/' .. name, '/usr/local/share/doc/' .. name, './'} do
46 local p = v .. 'README.md'
47 local h = io.open(p, 'r')
48 if nil ~= h then
49 D('Found README file '.. p)
50 Help = h:read('*a')
51 h:close()
52 end
53 end
54
55 print(Help)
56 _.usage(args, options, true)
57 os.exit(0)
58 end
59 },
60 version = {help = 'Print the version details.',
61 func = function(self, options, a, args, i)
62 print('This is version ' ..Version .. ' of ' .. args[0])
63 os.exit(0)
64 end
65 },
66 ['-q'] = {help = 'Decrease verbosity level.',
67 func = function(self, options, a, args, i)
68 if _.verbosity > -1 then _.verbosity = _.verbosity - 1 end
69 print('New verbosity level is ' .. _.verbosity)
70 end
71 },
72 ['-v'] = {help = 'Increase verbosity level.',
73 func = function(self, options, a, args, i)
74 if _.verbosity < 4 then _.verbosity = _.verbosity + 1 end
75 print('New verbosity level is ' .. _.verbosity)
76 end
77 },
78}
79
80_.usage = function(args, options, all)
81 local h = ''
82 for k, v in pairs(options) do
83 if 'table' == type(v) then h = h .. k .. ' | ' end
84 end
85 for k, v in pairs(optionsCommon) do
86 if 'table' == type(v) then h = h .. k .. ' | ' end
87 end
88 print('Usage: ' .. args[0] .. ' {' .. string.sub(h, 1, -2) .. '}')
89 if true == all then
90 for k, v in pairs(options) do
91 if 'table' == type(v) then
92 if nil ~= v.help then print(k .. '\t\t' .. v.help) end
93 end
94 end
95 for k, v in pairs(optionsCommon) do
96 if 'table' == type(v) then
97 if nil ~= v.help then print(k .. '\t\t' .. v.help) end
98 end
99 end
100 end
101end
102
103_.parse = function(args, options, name)
104 local o = nil
105
106 local doIt = function(name, val, a, args, i)
107 local o = options[name]
108 if nil == o then o = optionsCommon[name] end
109 if nil ~= o then
110 if nil ~= val then o.value = val; D(name .. ' = ' .. tostring(val)) end
111 if nil ~= o.func then o:func(options, a, args, i, name) end
112 end
113 return o
114 end
115
116 if nil ~= name then
117 for i,v in ipairs{'/etc/', '~/.', './.'} do
118 local p = v .. name .. '.conf.lua'
119 local h = io.open(p, 'r')
120 if nil ~= h then
121 D('Found configuration file '.. p)
122 h:close()
123 local ar = dofile(p)
124 for k, w in pairs(ar) do
125 if nil == doIt(k, w, k .. '=' .. tostring(w), args, i) then W('config variable not found ' .. k .. ' = ' .. tostring(w)) end
126 end
127 end
128 end
129 end
130
131 if 0 ~= #args then
132 for i,a in ipairs(args) do
133 D('Argument ' .. i .. ' = ' .. a)
134 local ds = 0
135 if ('-' == a:sub(1, 1)) and ('-' ~= a:sub(2, 2)) then ds = 1 end
136 if '--' == a:sub(1, 2) then ds = 2; a = a:sub(3, -1) end
137 local s, e = a:find('=', 1, true)
138 local k , v
139 if not s then
140 e = 0
141 v = nil
142 else
143 v = a:sub(e + 1, -1)
144 end
145 k = a:sub(1, e - 1)
146 if 1 == ds then
147 for j = 2, #k do
148 o = doIt('-' .. k:sub(j, j), v, a, args, i)
149 end
150 else
151 o = doIt(k, v, a, args, i)
152 end
153 end
154 end
155
156 if nil == o then
157 _.usage(args, options)
158 os.exit(0)
159 end
160end
161
162_.runnable = function(c)
163 return ( 0 == __('which ' .. c):Do().status )
164end
165
166_.running = function(c)
167 return ( 1 ~= tonumber(__('pgrep -u $USER -cf ' .. c):Do().lines[1]) )
168end
169
170_.exists = function(f)
171 local h = io.open(f, 'r')
172 if nil == h then return false else h:close(); return true end
173end
174
175
176_.killEmAll = function(all)
177 for i,l in ipairs(all) do
178 local c = 0
179 while 0 ~= tonumber(__('pgrep -u $USER -xc ' .. l):Do().lines[1]) do
180 local s = 'TERM'
181 if c > 1 then s = 'KILL'; __('sleep ' .. c):Do() end
182 __('pkill -' .. s .. ' -u $USER -x ' .. l):log():Do()
183 c = c + 1
184 end
185 end
186end
187
188
189_.readCmd = function(cmd)
190 local result = {}
191 local output = io.popen(cmd)
192 if nil ~= output then
193 for l in output:lines() do
194 table.insert(result, l)
195 end
196 end
197 -- While this does return the same things as os.execute(), it's just as useless.
198 output:close()
199 return result
200end
201
202
203_G.__ = function(c)
204 local exe = {status = 0, lines = {}, logging = false, showing = false, cmd = '', command = c, isScript = false, script = ''}
205 local n = 0
206
207 exe.cmd = '{ '
208 if 'table' == type(c) then
209 for i, l in ipairs(c) do
210 n = n + 1
211 exe.cmd = exe.cmd .. l .. ' ; '
212 end
213 elseif 'string' == type(c) then
214 exe.isScript = (n == 0) and ('#!' == c:sub(1,2))
215 for l in string.gmatch(c, '\n*([^\n]+)\n*') do
216 if '' ~= l then
217 if exe.isScript then
218 if '' == exe.script then
219 exe.scriptFile = os.tmpname()
220 D('Creating temporary script file at ' .. exe.scriptFile)
221 exe.cmd = exe.cmd .. l:sub(3) .. ' ' .. exe.scriptFile .. ' ; '
222 -- PHP wants this to be executable.
223 __('chmod u+x ' .. exe.scriptFile)
224 end
225 exe.script = exe.script .. l .. '\n'
226 else
227 n = n + 1
228 exe.cmd = exe.cmd .. l .. ' ; '
229 end
230 end
231 end
232 end
233 if exe.isScript then
234 local a, e = io.open(exe.scriptFile, 'w')
235 if nil == a then E('Could not open ' .. exe.scriptFile .. ' - ' .. e) else
236 a:write(exe.script)
237 a:close()
238 end
239 exe.cmd = exe.cmd .. 'rm ' .. exe.scriptFile .. ' ; '
240 end
241 exe.cmd = exe.cmd .. ' } '
242 if 1 == n then exe.cmd = c end
243
244
245 function exe:Nice(c)
246 if nil == c then
247 self.cmd = 'ionice -c3 nice -n 19 ' .. self.cmd
248 else
249 self.cmd = self.cmd .. ' ionice -c3 nice -n 19 ' .. c .. ' '
250 end
251 return self
252 end
253
254 function exe:timeout(c)
255 -- 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.
256 -- --kill-after means "send KILL after TERM fails".
257 if nil == c then
258 self.cmd = 'timeout --kill-after=10.0 --foreground 42.0s ' .. self.cmd
259 else
260 self.cmd = 'timeout --kill-after=10.0 --foreground ' .. c .. ' ' .. self.cmd
261 end
262 return self
263 end
264
265 function exe:log() self.logging = true return self end
266 function exe:show() self.showing = true return self end
267 -- Should be called "then" but that's a reserved word.
268 function exe:Then(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. '; ' .. c .. ' ' return self end
269 function exe:And(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' && ' .. c .. ' ' return self end
270 function exe:Or(c) if nil == c then c = '' else c = ' ' .. c end self.cmd = self.cmd .. ' || ' .. c .. ' ' return self end
271 function exe:noErr() self.cmd = self.cmd .. ' 2>/dev/null ' return self end
272 function exe:noOut() self.cmd = self.cmd .. ' 1>/dev/null ' return self end
273 function exe:wait(w) self.cmd = self.cmd .. ' && touch ' .. w .. ' ' return self end
274
275 function exe:Do()
276 --[[ "The condition expression of a control structure can return any
277 value. Both false and nil are considered false. All values different
278 from nil and false are considered true (in particular, the number 0
279 and the empty string are also true)."
280 says the docs, I beg to differ.]]
281 if true == self.logging then D(' executing - ' .. self.cmd) end
282 --[[ Damn os.execute()
283 Lua 5.1 says it returns "a status code, which is system-dependent"
284 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
285 I'm getting 7168 or 0. No idea what the fuck that is.
286 local ok, rslt, status = os.execute(s)
287 ]]
288 self.lines = _.readCmd(self.cmd .. '; echo "$?"', 'r')
289 -- The last line will be the command's returned status, fish that out and collect everything else in lines.
290 self.status = tonumber(self.lines[#self.lines])
291 self.lines[#self.lines] = nil
292 if true == self.showing then for i, l in ipairs(self.lines) do I(l) end end
293
294 if (nil == self.status) then D('STATUS |' .. 'NIL' .. '| ' .. self.command)
295 elseif (137 == self.status) or (124 == self.status) then T('timeout killed ' .. self.status .. ' ' .. self.command)
296 elseif (0 ~= self.status) then D('STATUS |' .. self.status .. '| ' .. self.command)
297 end
298
299 return self
300 end
301
302 function exe:fork(after, host)
303-- The host part is from apt-panopticon, likely needed there, but makes no sense here.
304-- 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
305 if nil == after then after = '' end
306 if '' ~= after then after = ' ; ' .. after end
307 self.cmd = '{ ' .. self.cmd .. after .. ' ; } & '
308 if true == self.logging then D(' forking - ' .. self.cmd) end
309 os.execute(self.cmd)
310 return self
311 end
312
313 function exe:forkOnce()
314 if _.running(self.command) then
315 D('Already running ' .. self.command)
316 else
317 self:fork()
318 end
319 end
320
321 return exe
322end
323
324
325
326_.who = __[[whoami]]:noErr():Do().lines[1]
327_.dir = __[[pwd]]:noErr():Do().lines[1]
328
329
330
331if (arg[0] == './PolygLua.lua') or (arg[0] == 'PolygLua.lua') then
332 local function goAway(txt)
333 local luas = __'ls -d1 /usr/share/lua/*':noErr():Do()
334 for i,l in ipairs(luas.lines) do
335 local lua = '/usr/local/share/lua/' .. l:sub(16) .. '/PolygLua.lua'
336 if _.exists(lua) then
337 if 'root' == _.who then
338 print(txt .. ' ' .. lua)
339 __('rm ' .. lua):Do()
340 end
341 end
342 end
343 end
344
345 local options =
346 {
347 install =
348 {
349 help = 'Command to install PolygLua.lua',
350 func = function(self, options, a, args, i)
351 if 'root' ~= _.who then
352 E'Need to be root user to install.'
353 else
354 print('INSTALLING PolygLua.lua!!!')
355
356 local luas = __'ls -d1 /usr/share/lua/*':noErr():Do()
357 for i,l in ipairs(luas.lines) do
358 local lua = '/usr/local/share/lua/' .. l:sub(16) .. '/PolygLua.lua'
359 if _.exists(lua) then
360 print(lua .. ' installed')
361 else
362 if 'root' == _.who then
363 print('Installing ' .. lua)
364 __('mkdir -p /usr/local/share/lua/' .. l:sub(16) .. ' ; ln -s ' .. _.dir .. '/PolygLua.lua ' .. lua):Do()
365 else
366 print(lua .. ' NOT installed')
367 end
368 end
369 end
370
371 end
372 end
373 },
374 uninstall =
375 {
376 help = 'Command to uninstall PolygLua.lua',
377 func = function(self, options, a, args, i)
378 if 'root' ~= _.who then
379 E'Need to be root user to uninstall.'
380 else
381 print('UNINSTALLING PolygLua.lua!!!')
382 goAway('Uninstalling')
383 end
384 end
385 },
386 purge =
387 {
388 help = 'Command to purge PolygLua.lua',
389 func = function(self, options, a, args, i)
390 if 'root' ~= _.who then
391 E'Need to be root user to purge.'
392 else
393 print('PURGING PolygLua.lua!!!')
394 goAway('Purging')
395 end
396 end
397 },
398 }
399
400 _.parse(arg, options)
401end
402
403
404
405return _
diff --git a/aataaj.lua b/aataaj.lua
index 86a9af0..e08373b 100755
--- a/aataaj.lua
+++ b/aataaj.lua
@@ -14,7 +14,7 @@
14### END INIT INFO 14### END INIT INFO
15]] 15]]
16 16
17local _ = require 'PolygLua' 17local _ = require 'polygLua'
18Version = '0.0 crap' 18Version = '0.0 crap'
19 19
20local function goAway() 20local function goAway()
@@ -76,39 +76,44 @@ local options =
76 E'Need to be root user to install.' 76 E'Need to be root user to install.'
77 else 77 else
78 print('INSTALLING!!!') 78 print('INSTALLING!!!')
79 __[[#!/bin/bash 79 -- espeak-ng has an entirely undocumented way of speciyfying the output device. aplay can't deal with it's output, so have to pipe it through sox.
80 __[=[#!/bin/bash
80 echo "Installing aataaj" 81 echo "Installing aataaj"
81 ./PolygLua.lua -vvvv install 82 ./PolygLua.lua -vvvv install
82 ln -s `pwd`/aataaj.lua /usr/local/bin/aataaj.lua 83 if [[ ! -h /usr/local/bin/aataaj.lua ]]; then
83 ln -s /usr/local/bin/aataaj.lua /etc/init.d/aataaj.lua 84 ln -s `pwd`/aataaj.lua /usr/local/bin/aataaj.lua
84 update-rc.d aataaj.lua defaults 85 fi
86 if [[ ! -h /etc/init.d/aataaj.lua ]]; then
87 ln -s /usr/local/bin/aataaj.lua /etc/init.d/aataaj.lua
88 fi
85 mkdir -p /usr/local/share/doc/aataaj 89 mkdir -p /usr/local/share/doc/aataaj
86 ln -s `pwd`/*.md /usr/local/share/doc/aataaj/
87 pushd /usr/local/share/doc/aataaj 90 pushd /usr/local/share/doc/aataaj
88 espeak-ng -w your.wav "Your " 91 espeak-ng --stdout "Your " | sox - your.wav channels 2
89 espeak-ng -w devices.wav " audio devices are - " 92 espeak-ng --stdout " audio devices are - " | sox - devices.wav channels 2
90 espeak-ng -w device.wav "Device number " 93 espeak-ng --stdout "Device number " | sox - device.wav channels 2
91 espeak-ng -w sub.wav ", sub device " 94 espeak-ng --stdout ", sub device " | sox - sub.wav channels 2
92 espeak-ng -w zero.wav "zero" 95 espeak-ng --stdout "zero" | sox - zero.wav channels 2
93 espeak-ng -w one.wav "one" 96 espeak-ng --stdout "one" | sox - one.wav channels 2
94 espeak-ng -w two.wav "two" 97 espeak-ng --stdout "two" | sox - two.wav channels 2
95 espeak-ng -w three.wav "three" 98 espeak-ng --stdout "three" | sox - three.wav channels 2
96 espeak-ng -w four.wav "four" 99 espeak-ng --stdout "four" | sox - four.wav channels 2
97 espeak-ng -w five.wav "five" 100 espeak-ng --stdout "five" | sox - five.wav channels 2
98 espeak-ng -w six.wav "six" 101 espeak-ng --stdout "six" | sox - six.wav channels 2
99 espeak-ng -w seven.wav "seven" 102 espeak-ng --stdout "seven" | sox - seven.wav channels 2
100 espeak-ng -w eight.wav "eight" 103 espeak-ng --stdout "eight" | sox - eight.wav channels 2
101 espeak-ng -w nine.wav "nine" 104 espeak-ng --stdout "nine" | sox - nine.wav channels 2
102 espeak-ng -w ten.wav "ten" 105 espeak-ng --stdout "ten" | sox - ten.wav channels 2
103 espeak-ng -w eleven.wav "eleven" 106 espeak-ng --stdout "eleven" | sox - eleven.wav channels 2
104 espeak-ng -w twelve.wav "twelve" 107 espeak-ng --stdout "twelve" | sox - twelve.wav channels 2
105 espeak-ng -w thirteen.wav "thirteen" 108 espeak-ng --stdout "thirteen" | sox - thirteen.wav channels 2
106 espeak-ng -w fourteen.wav "fourteen" 109 espeak-ng --stdout "fourteen" | sox - fourteen.wav channels 2
107 espeak-ng -w fifteen.wav "fifteen" 110 espeak-ng --stdout "fifteen" | sox - fifteen.wav channels 2
108 espeak-ng -w sixteen.wav "sixteen" 111 espeak-ng --stdout "sixteen" | sox - sixteen.wav channels 2
109 espeak-ng -w best.wav "Please type the device number you heard best - " 112 espeak-ng --stdout "Please type the device number you heard best - " | sox - best.wav channels 2
110 popd 113 popd
111 ]]:log():show():Do() 114 ln -s `pwd`/*.md /usr/local/share/doc/aataaj/
115 update-rc.d aataaj.lua defaults
116 ]=]:log():show():Do()
112 end 117 end
113 os.exit(0) 118 os.exit(0)
114 end 119 end
@@ -200,21 +205,21 @@ table.sort(Cards, function(a, b) return a.card < b.card end)
200print('') 205print('')
201io.flush() 206io.flush()
202 207
203
204local speak = function(card, subdevice, device, words, printIt, forkIt, ...) 208local speak = function(card, subdevice, device, words, printIt, forkIt, ...)
205 local files = {...} 209 local files = {...}
206 local s = '' 210 local s = ''
211 if nil == subdevice then subdevice = '' elseif '' ~= subdevice then subdevice = ',' .. subdevice end
207 if 0 == #files then 212 if 0 == #files then
208 local file = os.tmpname() .. '.wav' 213 local file = os.tmpname() .. '.wav'
209 D('Creating temporary script file at ' .. file) 214 D('Creating temporary script file at ' .. file)
210-- s = '#!/bin/bash\necho "' .. words .. '" | ALSA_CARD=' .. device .. ' ' .. speaker 215-- s = '#!/bin/bash\necho "' .. words .. '" | ALSA_CARD=' .. device .. ' ' .. speaker
211-- s = '#!/bin/bash\necho "' .. words .. '" | ' .. speaker .. ' -d hw:' .. device .. ',' .. subdevice 216-- s = '#!/bin/bash\necho "' .. words .. '" | ' .. speaker .. ' -d hw:' .. device .. subdevice
212 s = '#!/bin/bash\n' .. speaker .. ' -d hw:' .. device .. ',' .. subdevice .. ' "' .. words .. '"' 217 s = '#!/bin/bash\n' .. speaker .. ' -d hw:' .. device .. subdevice .. ' "' .. words .. '"'
213-- s = '#!/bin/bash\necho "' .. words .. '" | ' .. speaker .. ' -w ' .. file .. ' ; aplay --device=hw:' .. device .. ',' .. subdevice .. ' ' .. file 218-- s = '#!/bin/bash\necho "' .. words .. '" | ' .. speaker .. ' -w ' .. file .. ' ; aplay --device=hw:' .. device .. subdevice .. ' ' .. file
214-- s = '#!/bin/bash\n' .. speaker .. ' -w ' .. file .. ' "' .. words .. '" ; aplay --device=hw:' .. device .. ',' .. subdevice .. ' ' .. file 219-- s = '#!/bin/bash\n' .. speaker .. ' -w ' .. file .. ' "' .. words .. '" ; aplay --device=hw:' .. device .. subdevice .. ' ' .. file
215 else 220 else
216 s = 'aplay --device=hw:' .. device .. ',' .. subdevice 221 s = 'aplay -q --device=hw:' .. device .. subdevice
217 for i, v in ipairs(files) do s = s .. ' ' .. v .. '.wav' end 222 for i, v in ipairs(files) do s = s .. ' /usr/local/share/doc/aataaj/' .. v .. '.wav' end
218 end 223 end
219print(s) 224print(s)
220 if printIt then print(words) end 225 if printIt then print(words) end
@@ -226,11 +231,25 @@ print(s)
226-- io.flush() 231-- io.flush()
227end 232end
228 233
229-- TODO - Need to maximize the volume, and turn on IEC958 for the devices / sub devices. Coz seems they might default to "can't hear it" states. 234-- TODO - Start with the device, then go through the sub devices. Coz at boot time subs don't seem to work.
235-- Likely that'll lock things up at "all speak at once" time.
230if 'start' == cmd then 236if 'start' == cmd then
231 print('Your ' .. cnt .. ' audio devices are - ') 237 print('Your ' .. cnt .. ' audio devices are - ')
238
239 for k = 0, cnt do
240 -- Turn on IEC958 for everything, they seem to default to off, so can't hear them.
241 for l, m in ipairs(__("amixer -c " .. k .. " scontrols | grep 'IEC958' | cut -d ',' -f 2"):noErr():Do().lines) do
242 __("amixer -c " .. k .. " set IEC958," .. m .. " on"):Do()
243 end
244 -- Turn the volume to maximum for everything.
245 for l, m in ipairs(__("amixer -c " .. k .. " controls | grep ' Playback Volume' | cut -d ',' -f 1"):noErr():Do().lines) do
246 __("amixer -c " .. k .. " cset iface=MIXER,name='PCM Playback Volume'," .. m .. " 100% "):Do()
247 end
248 end
249
232 for k,C in pairs(Cards) do 250 for k,C in pairs(Cards) do
233 for j,c in ipairs(C['playbackDevs']) do 251 for j,c in ipairs(C['playbackDevs']) do
252 speak(C.name, nil, C.card - 1, 'Your ' .. cnt .. ' audio devices are - ', false, true, 'your', numbers[cnt], 'devices')
234 speak(C.name, C['playbackDevs'][j], C.card - 1, 'Your ' .. cnt .. ' audio devices are - ', false, true, 'your', numbers[cnt], 'devices') 253 speak(C.name, C['playbackDevs'][j], C.card - 1, 'Your ' .. cnt .. ' audio devices are - ', false, true, 'your', numbers[cnt], 'devices')
235 end 254 end
236 end 255 end
@@ -238,6 +257,7 @@ if 'start' == cmd then
238 __'sleep 6':Do() 257 __'sleep 6':Do()
239 for k,C in pairs(Cards) do 258 for k,C in pairs(Cards) do
240 for j,c in ipairs(C['playbackDevs']) do 259 for j,c in ipairs(C['playbackDevs']) do
260 speak(C.name, nil, C.card - 1, 'Device number ' .. C.card - 1 .. ', sub device ' .. C['playbackDevs'][j] .. ' : ' .. C.name, true, false, 'device', numbers[C.card - 1], 'sub', numbers[tonumber(C['playbackDevs'][j])])
241 speak(C.name, C['playbackDevs'][j], C.card - 1, 'Device number ' .. C.card - 1 .. ', sub device ' .. C['playbackDevs'][j] .. ' : ' .. C.name, true, false, 'device', numbers[C.card - 1], 'sub', numbers[tonumber(C['playbackDevs'][j])]) 261 speak(C.name, C['playbackDevs'][j], C.card - 1, 'Device number ' .. C.card - 1 .. ', sub device ' .. C['playbackDevs'][j] .. ' : ' .. C.name, true, false, 'device', numbers[C.card - 1], 'sub', numbers[tonumber(C['playbackDevs'][j])])
242 end 262 end
243 __'sleep 1':Do() 263 __'sleep 1':Do()
@@ -247,6 +267,7 @@ if 'start' == cmd then
247 print('Please type the device number you heard best - ') 267 print('Please type the device number you heard best - ')
248 for k,C in pairs(Cards) do 268 for k,C in pairs(Cards) do
249 for j,c in ipairs(C['playbackDevs']) do 269 for j,c in ipairs(C['playbackDevs']) do
270 speak(C.name, nil, C.card - 1, 'Please type the device number you heard best - ', false, true, 'best')
250 speak(C.name, C['playbackDevs'][j], C.card - 1, 'Please type the device number you heard best - ', false, true, 'best') 271 speak(C.name, C['playbackDevs'][j], C.card - 1, 'Please type the device number you heard best - ', false, true, 'best')
251 end 272 end
252 end 273 end
@@ -261,6 +282,11 @@ if 'start' == cmd then
261 end 282 end
262 end 283 end
263 284
285
286
287--os.exit(true)
288
289
264 __('mkdir -p ' .. options.asoundrcPath.value):Do() 290 __('mkdir -p ' .. options.asoundrcPath.value):Do()
265 local a, e = io.open(options.asoundrcPath.value .. '/jack-plumbing', 'w') 291 local a, e = io.open(options.asoundrcPath.value .. '/jack-plumbing', 'w')
266 if nil == a then print('Could not open ' .. options.asoundrcPath.value .. '/jack-plumbing - ' .. e) else 292 if nil == a then print('Could not open ' .. options.asoundrcPath.value .. '/jack-plumbing - ' .. e) else
@@ -475,9 +501,9 @@ elseif 'JACK' == cmd then
475 501
476 502
477 local AIN = 'alsa_in' 503 local AIN = 'alsa_in'
478 if _.runnable'zita-a2j' then AIN = 'zita-a2j' end 504-- if _.runnable'zita-a2j' then AIN = 'zita-a2j' end
479 local AOUT = 'alsa_out' 505 local AOUT = 'alsa_out'
480 if _.runnable'zita-j2a' then AOUT = 'zita-j2a' end 506-- if _.runnable'zita-j2a' then AOUT = 'zita-j2a' end
481 507
482 print('Basic ALSA sound devices converted to JACK.') 508 print('Basic ALSA sound devices converted to JACK.')
483 for k,C in pairs(options.aliases.value) do 509 for k,C in pairs(options.aliases.value) do
diff --git a/test_.lua b/test_.lua
deleted file mode 100755
index 9e1931a..0000000
--- a/test_.lua
+++ /dev/null
@@ -1,186 +0,0 @@
1#!/usr/bin/env luajit
2
3if type(jit) == 'table' then
4 print(arg[0] .. ' is being run by ' .. jit.version .. ' under ' .. jit.os .. ' on a ' .. jit.arch .. '. Lua version ' .. _VERSION)
5else
6 print(arg[0] .. ' is being run by Lua version ' .. _VERSION)
7end
8
9
10local _ = require 'PolygLua'
11
12
13I'Starting from the top.'
14
15Help = [[
16This is part of the blah blah blah...
17]]
18
19Version = '0.0 crap'
20
21local options =
22{
23 start = {help = 'Command to start the scanning process, for Sys V init.', value = 'blah'},
24-- restart = {start},
25-- ['force-reload'] = {start},
26 status = {help = 'Command to check the status of the scanning process, for Sys V init.',},
27 stop = {help = 'Command to stop the scanning process, for Sys V init.',},
28 JACK = {help = 'Command to start the JACK stuff, for users.',},
29 STOP = {help = 'Command to stop the JACK stuff, for users.',
30 func = function(self, options, a, args, i)
31--[=[
32 _.killEmAll{'qsynth'}
33 __[[
34 a2j_control --stop
35 sleep 2
36 a2j_control --exit
37 sleep 2
38 ]]:Do()
39 _.killEmAll{'alsa_in', 'alsa_out', 'zita-a2j', 'zita-j2a', 'aseqjoy', 'jack-plumbing'}
40 __[[
41 sleep 2
42 jack_control stop
43 sleep 2
44 jack_control exit
45 sleep 2
46 ]]:Do()
47 _.killEmAll{'jmcore', 'qjackctl'}
48 -- Catia is python, and no easy way to kill it.
49 -- Also it keeps jackdbus alive, no matter how hard you kill it.
50 __'pkill -TERM -u $USER -f catia':Do()
51 __'sleep 2':Do()
52 _.killEmAll{'jackdbus', 'a2jmidid'}
53]=]
54 end
55 },
56 install =
57 {
58 help = 'Command to install aataaj.lua',
59 func = function(self, options, a, args, i)
60 local w = __[[whoami]]:noErr():Do().lines[1]
61 local d = __[[pwd]]:noErr():Do().lines[1]
62 if 'root' ~= w then
63 E'Need to be root user to install.'
64 else
65 print('INSTALLING!!!')
66 __[[#!/bin/bash
67 echo "Installing PolygLua"
68 ./PolygLua.lua -vvvv
69 ]]:log():show():Do()
70 end
71 os.exit(0)
72 end
73 },
74}
75options['restart'] = options['start']
76options['force-reload'] = options['start']
77
78print('start = ' .. options.start.value)
79_.parse(arg, options, 'test_')
80print('start = ' .. options.start.value)
81print('stop = ' .. options.stop.value)
82
83
84
85__[[
86 echo -n "This'll print forking later. "
87 date
88 sleep 2
89]]:log():show():fork('echo -n "later is "; date')
90print('')
91
92
93local GUI = 'qjackctl'
94if _.runnable'catia' then GUI = 'catia' end
95local speaker = 'espeak'
96if _.runnable'espeak-ng' then speaker = 'espeak-ng' end
97print('' .. GUI .. ' ' .. speaker)
98print('')
99
100for i,l in ipairs(__'free -h':log():Do().lines) do
101 print(l)
102end
103print('')
104
105for i,l in ipairs(__'uname -a\nfree -h':log():Do().lines) do
106 print(l)
107end
108print('')
109
110__'uname -a':log():Then'free -h':show():Do()
111print('')
112
113__{'uname -a', 'free -h'}:log():show():Do()
114print('')
115
116
117print(__[[#!/bin/NoSuchCommand
118 echo "Should not print."
119]]:log():show():Do().status)
120print('')
121
122__[[#!/bin/bash
123 echo "G'day world from bash."
124]]:log():show():Do()
125print('')
126
127print(__[[#!/usr/bin/tcc -run
128 #include <tcclib.h>
129
130 int main()
131 {
132 printf("G'day world from C.\n");
133 return 1;
134 }
135]]:log():show():Do().status)
136print('')
137
138__[[#!/usr/bin/env luajit
139 print("G'day " .. "world " .. [=[from]=] .. ' Lua.')
140]]:log():show():Do()
141print('')
142
143__[[#!/usr/bin/perl
144 print "G'day world from perl.\n";
145]]:log():show():Do()
146print('')
147
148__[[#!/usr/bin/env php
149<?php
150 print("G'day world from php.\n");
151]]:log():show():Do()
152print('')
153
154-- Note no indent for Python, coz whitespace is significant.
155__[[#!/usr/bin/env python3
156print("G'day world from python.")
157]]:log():show():Do()
158print('')
159
160__[[#!/usr/bin/ruby
161 puts "G'day world from ruby."
162]]:log():show():Do()
163print('')
164
165
166print(__'true':log():show():Do().status)
167print(__'false':log():show():Do().status)
168print(__'exit 42':log():show():Do().status)
169print(__'return 42':log():show():Do().status)
170print(__'command NoSuchCommand':log():show():Do().status)
171
172
173--__'qpdfview':forkOnce()
174--__'qpdfview':forkOnce()
175
176print('')
177
178for i,a in ipairs(arg) do print('arg[' .. i .. '] = ' .. a) end
179print('')
180for k,a in pairs(arg) do print('arg[' .. k .. '] = ' .. a) end
181
182__'date':log():show():Do()
183-- Should get that "later" thing printed while the sleep is happening.
184__'date; sleep 5; date':log():show():Do()
185
186