1 -- Check MD5 sums of download files automagically (it expects them in
2 -- downloadedfile.txt).
4 ----------------------------------------------------------------------
6 ----------------------------------------------------------------------
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 = {
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
)
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"))
39 local tmp
= tmpname()..'.txt'
42 for i
,v
in results
do write(v
) end
44 table.insert(tmp_files
, tmp
)
45 return 'goto_url', tmp
49 -- Edit this to match your download directory.
50 return md5sum_check(home_dir
.. "/download")