pl.po: update
[elinks.git] / contrib / lua / md5check.lua
blob1823c704d1628a3d29c35b989425187ca057ea73
1 -- Check MD5 sums of download files automagically (it expects them in
2 -- downloadedfile.txt).
4 ----------------------------------------------------------------------
5 -- Installation
6 ----------------------------------------------------------------------
7 --
8 -- 1. Put this into your hooks.lua. Alternatively you can put
9 -- this in a separate file and `dofile' it.
11 -- 2. Edit your `console_hook_functions' table in hooks.lua. e.g.
13 -- console_hook_functions = {
14 -- ...
15 -- md5 = md5,
16 -- ...
17 -- }
19 -- 3. Edit the second last line of this file to point to your
20 -- download directory. Sorry, but ELinks can't get this
21 -- information automatically (yet?).
23 function md5sum_check(download_dir)
24 local results = {}
25 string.gsub(current_document(), "([a-z%d]+) ([^\n]+)\n",
26 function (sum, filename)
27 -- lua regexps don't seem to be able to do this
28 if string.len(sum) ~= 32 then return end
30 local fn = download_dir.."/"..filename
31 if file_exists(fn) then
32 local localsum = string.gsub(pipe_read("md5sum "..fn),
33 "^([a-z%d]+).*$", "%1")
34 table.insert(results, filename.. " -- "..
35 ((sum == localsum) and "ok\n" or "MISMATCH!\n"))
36 end
37 end)
39 local tmp = tmpname()..'.txt'
40 writeto(tmp)
41 results.n = nil
42 for i,v in results do write(v) end
43 writeto()
44 table.insert(tmp_files, tmp)
45 return 'goto_url', tmp
46 end
48 function md5()
49 -- Edit this to match your download directory.
50 return md5sum_check(home_dir .. "/download")
51 end