paulbsd-salt/states/haproxy/scripts/compile.lua
Paul Lecuq 14800c11d1
All checks were successful
continuous-integration/drone/push Build is passing
updated haproxy state
2023-04-13 23:13:34 +02:00

26 lines
766 B
Lua

lfs = require("lfs")
modpath = "/etc/haproxy/mods"
local compile = {}
local user = "haproxy"
local group = "haproxy"
local libs = {"-lcurl", "-ljansson", "-lmaxminddb"}
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
local cmd = "cc -I/usr/include/ -I/usr/include/lua5.3/ -fPIC -shared -o " .. binpath .. " " .. sourcepath .. " " ..table.concat(libs," ")
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