27 lines
1012 B
Plaintext
27 lines
1012 B
Plaintext
#!/usr/bin/env nomsu -V2.5.5.4
|
|
#
|
|
This file defines some actions for hashing files and looking up files by hash.
|
|
|
|
action [file with hash %hash]:
|
|
lua> ".."
|
|
local Hash = require("openssl.digest")
|
|
for filename in io.popen('find -L . -not -path "*/\\\\.*" -type f -name "*.nom"'):lines() do
|
|
local file = io.open(filename)
|
|
local contents = file:read("*a")
|
|
file:close()
|
|
local hash = Hash.new("sha1"):final(contents)
|
|
local hex = hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)
|
|
if hex == \%hash then
|
|
return filename
|
|
end
|
|
end
|
|
|
|
action [hash %, sha1 %]:
|
|
%hashlib = (=lua "require('openssl.digest')")
|
|
%hash = (=lua "\%hashlib.new('sha1'):final(\%)")
|
|
return (..)
|
|
=lua ".."
|
|
\%hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)
|
|
|
|
parse [hash of file %filename] as (sha1 (=lua "io.open(\%filename):read('*a')"))
|