aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xapt-panopticon.lua61
1 files changed, 37 insertions, 24 deletions
diff --git a/apt-panopticon.lua b/apt-panopticon.lua
index a03e89b..def0197 100755
--- a/apt-panopticon.lua
+++ b/apt-panopticon.lua
@@ -202,7 +202,26 @@ end
202 202
203local execute = function (s) 203local execute = function (s)
204 D(" executing " .. s) 204 D(" executing " .. s)
205 return os.execute(s) 205 --[[ Damn os.execute()
206 Lua 5.1 says it returns "a status code, which is system-dependent"
207 Lua 5.2 says it returns true/nil, "exit"/"signal", the status code.
208 I'm getting 7168 or 0. No idea what the fuck that is.
209 local ok, rslt, status = os.execute(s)
210 ]]
211 local f = io.popen(s .. ' ; echo "$?"', 'r')
212 local status = ""
213 local result = ""
214 -- The last line will be the command's returned status, collect everything else in result.
215 for l in f:lines() do
216 result = result .. status .. "\n"
217 status = l
218 end
219 return 0 + status, result
220end
221
222local fork = function(s)
223 D(" executing " .. s)
224 os.execute(s .. " &")
206end 225end
207 226
208local checkExes = function (exe) 227local checkExes = function (exe)
@@ -311,23 +330,17 @@ checkHEAD = function (host, URL, r, retry)
311 end 330 end
312 local cmd = 'curl -I --retry 0 -s --path-as-is --connect-timeout 15 --max-redirs 0 ' .. IP .. ' ' .. '-o /dev/null -D results/"HEADERS_' .. fname .. '" ' .. 331 local cmd = 'curl -I --retry 0 -s --path-as-is --connect-timeout 15 --max-redirs 0 ' .. IP .. ' ' .. '-o /dev/null -D results/"HEADERS_' .. fname .. '" ' ..
313 hdr .. ' -w "#%{http_code} %{ssl_verify_result} %{url_effective}\\n" ' .. PU.scheme .. '://' .. host .. PU.path .. ' >>results/"STATUS_' .. fname .. '"' 332 hdr .. ' -w "#%{http_code} %{ssl_verify_result} %{url_effective}\\n" ' .. PU.scheme .. '://' .. host .. PU.path .. ' >>results/"STATUS_' .. fname .. '"'
314 local rslt, status = execute(cmd) 333 local status, result = execute(cmd)
315 os.execute("sleep 2")
316 os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm results/"HEADERS_' .. fname .. '" 2>/dev/null') 334 os.execute('cat results/"HEADERS_' .. fname .. '" >>results/"STATUS_' .. fname .. '" 2>/dev/null; rm results/"HEADERS_' .. fname .. '" 2>/dev/null')
317 if "exit" == rslt then 335 if 28 == status then
318 if 28 == status then 336 E(" TIMEOUT " .. timeouts + 1 .. ", retry " .. retry + 1, PU.scheme, "", host)
319 E(" TIMEOUT!", PU.scheme, "", host) 337 timeouts = timeouts + 1
320 timeouts = timeouts + 1 338 checkHEAD(host, URL, r, retry + 1, timeouts)
321 checkHEAD(host, URL, r, retry + 1, timeouts) 339 return
322 return 340 elseif 0 ~= status then
323 elseif 0 ~= status then 341 E(" The curl command return an error code of " .. status .. ", consult the curl manual for what this means.", PU.scheme, "", host)
324 E(" The curl command return an error code of " .. status .. ", consult the curl manual for what this means.", PU.scheme, "", host) 342 checkHEAD(host, URL, r, retry + 1, timeouts)
325 checkHEAD(host, URL, r, retry + 1, timeouts) 343 return
326 return
327 end
328 elseif "signal" == rslt then
329 E(" The curl command was interupted by signal " .. status)
330 return
331 end 344 end
332 local rfile, e = io.open("results/STATUS_" .. fname, "r") 345 local rfile, e = io.open("results/STATUS_" .. fname, "r")
333 local code = "000" 346 local code = "000"
@@ -434,7 +447,7 @@ checkHost = function (orig, host, path, ip, file)
434 else 447 else
435 if orig == host then 448 if orig == host then
436 D("checkHost " .. orig .. "" .. file) 449 D("checkHost " .. orig .. "" .. file)
437 if testing("IPv4") then execute("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " -o " .. orig .. path .. " " .. file .." &") end 450 if testing("IPv4") then fork("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " -o " .. orig .. path .. " " .. file) end
438 else D("checkHost " .. orig .. " -> " .. host) end 451 else D("checkHost " .. orig .. " -> " .. host) end
439 local h = mirrors[ph.host] 452 local h = mirrors[ph.host]
440 if nil == h then return end 453 if nil == h then return end
@@ -442,16 +455,16 @@ checkHost = function (orig, host, path, ip, file)
442 if "table" == type(v) then 455 if "table" == type(v) then
443 for k1, v1 in pairs(v) do 456 for k1, v1 in pairs(v) do
444 if v1 == "A" then 457 if v1 == "A" then
445 if testing("IPv4") then execute("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " " .. k1 .. " " .. file .." &") end 458 if testing("IPv4") then fork("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " " .. k1 .. " " .. file) end
446 elseif v1 == "AAAA" then 459 elseif v1 == "AAAA" then
447 if testing("IPv6") then execute("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k1 .. "] " .. file .. " &") end 460 if testing("IPv6") then fork("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k1 .. "] " .. file) end
448 end 461 end
449 end 462 end
450 else 463 else
451 if v == "A" then 464 if v == "A" then
452 if testing("IPv4") then execute("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " " .. k .. " " .. file .." &") end 465 if testing("IPv4") then fork("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " " .. k .. " " .. file) end
453 elseif v == "AAAA" then 466 elseif v == "AAAA" then
454 if testing("IPv6") then execute("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] " .. file .. " &") end 467 if testing("IPv6") then fork("ionice -c3 ./apt-panopticon.lua " .. sendArgs .. " " .. orig .. path .. " [" .. k .. "] " .. file) end
455 end 468 end
456 end 469 end
457 end 470 end
@@ -472,7 +485,7 @@ local downloads = function (cut, host, URL)
472 cm = cm .. " https://" .. host .. URL .. "/" .. s 485 cm = cm .. " https://" .. host .. URL .. "/" .. s
473 end 486 end
474 for i, s in pairs(releases) do 487 for i, s in pairs(releases) do
475 execute(cm .. " &") 488 fork(cm)
476 cm = "ionice -c3 " .. downloadLock .. lock:format(s) .. download .. log:format(s, s) .. cd 489 cm = "ionice -c3 " .. downloadLock .. lock:format(s) .. download .. log:format(s, s) .. cd
477 if repoExists(s .. k) then 490 if repoExists(s .. k) then
478 for j, k in pairs(releaseFiles) do 491 for j, k in pairs(releaseFiles) do
@@ -480,7 +493,7 @@ local downloads = function (cut, host, URL)
480 end 493 end
481 end 494 end
482 end 495 end
483 execute(cm .. " &") 496 fork(cm)
484end 497end
485 498
486local getMirrors = function () 499local getMirrors = function ()