2023-06-06 09:23:53 +02:00
|
|
|
local lfs = require("lfs")
|
2023-04-13 23:13:34 +02:00
|
|
|
|
2023-06-06 09:23:53 +02:00
|
|
|
local modpath = "/etc/haproxy/mods"
|
2023-04-13 23:13:34 +02:00
|
|
|
|
|
|
|
local compile = {}
|
2023-06-06 09:23:53 +02:00
|
|
|
local lua_version = "5.3"
|
2023-04-13 23:13:34 +02:00
|
|
|
local user = "haproxy"
|
|
|
|
local group = "haproxy"
|
2024-01-27 10:41:30 +01:00
|
|
|
local libs = {"-ljansson", "-lmaxminddb", "-lcurl"}
|
2023-04-13 23:13:34 +02:00
|
|
|
|
|
|
|
function compile.check(module)
|
|
|
|
local sourcepath = modpath.."/"..module..".c"
|
|
|
|
local binpath = modpath.."/"..module..".so"
|
|
|
|
|
|
|
|
local binexists = io.open(binpath)
|
|
|
|
|
|
|
|
if not binexists or (binexists and lfs.attributes(sourcepath).change > lfs.attributes(binpath).change ) then
|
2023-06-06 09:23:53 +02:00
|
|
|
local cmd = "cc -I/usr/include/ -I/usr/include/lua" .. lua_version .. "/ -fPIC -shared -o " .. binpath .. " " .. sourcepath .. " " ..table.concat(libs," ")
|
2023-04-13 23:13:34 +02:00
|
|
|
local res = io.popen(cmd)
|
|
|
|
local aa = res:read("a*")
|
|
|
|
io.popen("chown "..user..":"..group.." "..binpath)
|
|
|
|
io.popen("chmod 600 "..binpath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return compile
|