paulbsd-salt/states/haproxy/scripts/compile.lua

25 lines
819 B
Lua
Raw Normal View History

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 = {}
2024-08-22 04:16:46 +02:00
local lua_version = "5.4"
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)
2024-05-25 13:54:44 +02:00
local sourcepath = string.format("%s/%s.c", modpath, module)
local binpath = string.format("%s/%s.so", modpath, module)
2023-04-13 23:13:34 +02:00
local binexists = io.open(binpath)
if not binexists or (binexists and lfs.attributes(sourcepath).change > lfs.attributes(binpath).change ) then
2024-05-25 22:10:30 +02:00
io.popen(string.format("cc -I/usr/include/ -I/usr/include/lua%s/ -fPIC -shared -o %s %s %s", lua_version, binpath, sourcepath, table.concat(libs, " ")))
io.popen(string.format("chown %s:%s %s", user, group, binpath))
io.popen(string.format("chmod 600 %s", binpath))
2023-04-13 23:13:34 +02:00
end
end
return compile