diff options
author | onefang | 2019-12-23 13:13:27 +1000 |
---|---|---|
committer | onefang | 2019-12-23 13:13:27 +1000 |
commit | 1ba723ffeb3f987b8ed8fd7a14c9cd7fc60caef5 (patch) | |
tree | 3ae069ee4b6e8bbcf39ff97080eabaa431941fc0 | |
parent | Attempt to sanitize the .lua table output. (diff) | |
download | apt-panopticon-1ba723ffeb3f987b8ed8fd7a14c9cd7fc60caef5.zip apt-panopticon-1ba723ffeb3f987b8ed8fd7a14c9cd7fc60caef5.tar.gz apt-panopticon-1ba723ffeb3f987b8ed8fd7a14c9cd7fc60caef5.tar.bz2 apt-panopticon-1ba723ffeb3f987b8ed8fd7a14c9cd7fc60caef5.tar.xz |
Update script now updates everything, and sends progress reports.
Also locks out the normal checks while it's updating.
-rwxr-xr-x | apt-panopticon-update-data.lua | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/apt-panopticon-update-data.lua b/apt-panopticon-update-data.lua index 8adad4d..82a6ba5 100755 --- a/apt-panopticon-update-data.lua +++ b/apt-panopticon-update-data.lua | |||
@@ -9,15 +9,64 @@ local E = APT.E | |||
9 | local C = APT.C | 9 | local C = APT.C |
10 | local arg, sendArgs = APT.parseArgs({...}) | 10 | local arg, sendArgs = APT.parseArgs({...}) |
11 | 11 | ||
12 | local oldest = 0 | ||
12 | 13 | ||
14 | local lock = 'apt-panopticon.lock' | ||
15 | while APT.checkFile(lock) do os.execute('sleep 10') end | ||
16 | os.execute('touch ' .. lock) | ||
13 | 17 | ||
18 | |||
19 | if -1 < APT.verbosity then print('\nUpacking tarballs and cleaning them.') end | ||
14 | local files = io.popen('ls -1 results_*.tar.xz') | 20 | local files = io.popen('ls -1 results_*.tar.xz') |
15 | for l in files:lines() do | 21 | for l in files:lines() do |
16 | print('tar -xf ' .. l) | 22 | if 0 == oldest then |
23 | local status, whn = APT.execute('TZ="GMT" ls -d1 --time-style="+%s" ' .. l .. ' | cut -d " " -f 6-6') | ||
24 | whn = whn:sub(2, -2) | ||
25 | local status, new = APT.execute('TZ="GMT" date -d "' .. whn:sub(9, 18) .. ' ' .. whn:sub(20, 21) .. ':' .. whn:sub(23, 24) .. '" "+%s"') | ||
26 | oldest = tonumber("0" .. new:sub(2, -2)) - (60 * 60) | ||
27 | if -1 < APT.verbosity then print('\nOldest time is ' .. oldest) end | ||
28 | end | ||
29 | if -1 < APT.verbosity then io.stdout:write('\r' .. 'tar -xf ' .. l); io.stdout:flush() end | ||
17 | os.execute('tar -xf ' .. l) | 30 | os.execute('tar -xf ' .. l) |
31 | os.execute('rm -f ' .. l:sub(1, -8) .. '/*.curl') | ||
32 | os.execute('rm -f ' .. l:sub(1, -8) .. '/STATUS_*') | ||
33 | if APT.checkFile(l:sub(1, -8) .. '/mirrors.lua') then | ||
34 | APT.mirrors = loadfile(l:sub(1, -8) .. "/mirrors.lua")() | ||
35 | for k, v in pairs(APT.mirrors) do | ||
36 | if APT.options.referenceSite.value ~= k then | ||
37 | if APT.checkFile(l:sub(1, -8) .. '/' .. k) then | ||
38 | os.execute('rm -fr ' .. l:sub(1, -8) .. '/' .. k) | ||
39 | end | ||
40 | else | ||
41 | for i, n in pairs(APT.releases) do | ||
42 | os.execute( 'rm -f ' .. l:sub(1, -8) .. '/' .. k .. '/merged/dists/' .. n .. '/Release;' .. | ||
43 | 'rm -f ' .. l:sub(1, -8) .. '/' .. k .. '/merged/dists/' .. n .. '/Release.gpg;' .. | ||
44 | 'rm -fr ' .. l:sub(1, -8) .. '/' .. k .. '/merged/dists/' .. n .. '/contrib 2>/dev/null;' .. | ||
45 | 'rm -fr ' .. l:sub(1, -8) .. '/' .. k .. '/merged/dists/' .. n .. '/main 2>/dev/null;' .. | ||
46 | 'rm -fr ' .. l:sub(1, -8) .. '/' .. k .. '/merged/dists/' .. n .. '/non-free 2>/dev/null') | ||
47 | end | ||
48 | os.execute('rm -fr ' .. l:sub(1, -8) .. '/' .. k .. '/merged/pool') | ||
49 | end | ||
50 | local results = {} | ||
51 | local f = l:sub(1, -8) .. "/" .. k .. ".lua" | ||
52 | if APT.checkFile(f) then | ||
53 | results = loadfile(f)() | ||
54 | results = APT.padResults(results) | ||
55 | results['IPs'] = v.IPs | ||
56 | local rfile, e = io.open(f, "w+") | ||
57 | if nil == rfile then C("opening results file - " .. e) else | ||
58 | rfile:write(APT.dumpTable(results, "", "results") .. "\nreturn results\n") | ||
59 | rfile:close() | ||
60 | end | ||
61 | end | ||
62 | end | ||
63 | end | ||
18 | end | 64 | end |
19 | 65 | ||
66 | |||
67 | if -1 < APT.verbosity then print('\nDeleting old RRD data.') end | ||
20 | os.execute('rm -fr rrd') | 68 | os.execute('rm -fr rrd') |
69 | if -1 < APT.verbosity then print('\nRecreating RRD data.') end | ||
21 | local files = io.popen('ls -d1 results_*') | 70 | local files = io.popen('ls -d1 results_*') |
22 | for l in files:lines() do | 71 | for l in files:lines() do |
23 | if ('results_old' ~= l) and ('.tar.xz' ~= l:sub(25, -1)) then | 72 | if ('results_old' ~= l) and ('.tar.xz' ~= l:sub(25, -1)) then |
@@ -27,22 +76,34 @@ for l in files:lines() do | |||
27 | local status, new = APT.execute('TZ="GMT" date -d "' .. whn:sub(9, 18) .. ' ' .. whn:sub(20, 21) .. ':' .. whn:sub(23, 24) .. '" "+%s"') | 76 | local status, new = APT.execute('TZ="GMT" date -d "' .. whn:sub(9, 18) .. ' ' .. whn:sub(20, 21) .. ':' .. whn:sub(23, 24) .. '" "+%s"') |
28 | APT.now = tonumber("0" .. new:sub(2, -2)) | 77 | APT.now = tonumber("0" .. new:sub(2, -2)) |
29 | if 0 ~= APT.now then | 78 | if 0 ~= APT.now then |
30 | print(l .. ' -> ' .. APT.now) | 79 | if APT.checkFile(l .. '/mirrors.lua') then |
31 | APT.mirrors = loadfile(l .. "/mirrors.lua")() | 80 | if -1 < APT.verbosity then io.stdout:write('\r' .. l .. ' -> ' .. APT.now); io.stdout:flush() end |
32 | for k, v in pairs(APT.mirrors) do | 81 | APT.mirrors = loadfile(l .. "/mirrors.lua")() |
33 | APT.doRRD(l, k, v) | 82 | for k, v in pairs(APT.mirrors) do |
83 | APT.doRRD(l, k, v, oldest) | ||
84 | end | ||
85 | else | ||
86 | if -1 < APT.verbosity then io.stdout:write('\r' .. l); io.stdout:flush() end | ||
34 | end | 87 | end |
35 | else | 88 | else |
36 | print(l) | 89 | if -1 < APT.verbosity then io.stdout:write('\r' .. l); io.stdout:flush() end |
37 | end | 90 | end |
38 | else | 91 | else |
39 | print(l) | 92 | if -1 < APT.verbosity then io.stdout:write('\r' .. l); io.stdout:flush() end |
40 | end | 93 | end |
41 | end | 94 | end |
42 | end | 95 | end |
43 | 96 | ||
97 | |||
98 | os.execute('rm ' .. lock) | ||
99 | |||
100 | |||
101 | if -1 < APT.verbosity then print('\nRecreating tarballs.') end | ||
44 | local files = io.popen('ls -1 results_*.tar.xz') | 102 | local files = io.popen('ls -1 results_*.tar.xz') |
45 | for l in files:lines() do | 103 | for l in files:lines() do |
46 | print('tar -c --xz ' .. l:sub(1, 24) .. ' -f ' .. l .. '; rm -fr ' .. l:sub(1, 24)) | 104 | if -1 < APT.verbosity then io.stdout:write('\r' .. 'tar -c --xz ' .. l:sub(1, 24) .. ' -f ' .. l .. '; rm -fr ' .. l:sub(1, 24)); io.stdout:flush() end |
47 | os.execute('tar -c --xz ' .. l:sub(1, 24) .. ' -f ' .. l .. '; rm -fr ' .. l:sub(1, 24)) | 105 | os.execute('tar -c --xz ' .. l:sub(1, 24) .. ' -f ' .. l .. '; rm -fr ' .. l:sub(1, 24)) |
48 | end | 106 | end |
107 | |||
108 | |||
109 | if -1 < APT.verbosity then print('\nFinished updating data.') end | ||