26 lines
834 B
Lua
26 lines
834 B
Lua
local lfs = require("lfs")
|
|
|
|
local modpath = "/etc/haproxy/mods"
|
|
|
|
local compile = {}
|
|
local lua_version = "5.3"
|
|
local user = "haproxy"
|
|
local group = "haproxy"
|
|
local libs = {"-ljansson", "-lmaxminddb", "-lcurl"}
|
|
|
|
function compile.check(module)
|
|
local sourcepath = string.format("%s/%s.c", modpath, module)
|
|
local binpath = string.format("%s/%s.so", modpath, module)
|
|
|
|
local binexists = io.open(binpath)
|
|
|
|
if not binexists or (binexists and lfs.attributes(sourcepath).change > lfs.attributes(binpath).change ) then
|
|
local cmd = string.format("cc -I/usr/include/ -I/usr/include/lua%s/ -fPIC -shared -o %s %s %s", lua_version, binpath, sourcepath, table.concat(libs," "))
|
|
local res = io.popen(cmd)
|
|
io.popen("chown %s:%s %s", user, group, binpath)
|
|
io.popen(string.format("chmod 600 %s",binpath))
|
|
end
|
|
end
|
|
|
|
return compile
|