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 = 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/lua" .. lua_version .. "/ -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