82 lines
2.2 KiB
Lua
Executable File
82 lines
2.2 KiB
Lua
Executable File
#!/usr/bin/env luajit
|
|
package.path = (arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)")) .. "lib" .. package.config:sub(1, 1) .. "?.lua;" .. package.path
|
|
local utility = require "utility"
|
|
|
|
local data = utility.load_data("info.json")
|
|
|
|
local copy_pack_mods = function(pack_name, destination_path)
|
|
os.execute("mkdir -p " .. destination_path:enquote())
|
|
|
|
local pack_mods = data.packs[pack_name].mods
|
|
|
|
for mod_name in pairs(pack_mods) do
|
|
local source = ("mods" .. utility.path_separator .. mod_name):enquote()
|
|
local target = (destination_path .. utility.path_separator .. mod_name):enquote()
|
|
|
|
os.execute("cp -r " .. source .. " " .. target)
|
|
end
|
|
end
|
|
|
|
local check_dependencies = function(pack_name)
|
|
local pack_mods = data.packs[pack_name].mods
|
|
|
|
local provided_mods = {}
|
|
|
|
for mod_name in pairs(pack_mods) do
|
|
local function loop()
|
|
local selected_mod = data.mods[mod_name]
|
|
if not selected_mod then
|
|
print("Error: " .. mod_name .. " is not defined!")
|
|
return
|
|
end
|
|
|
|
if selected_mod.provides then
|
|
for _, name_provided in ipairs(selected_mod.provides) do
|
|
provided_mods[name_provided] = mod_name
|
|
end
|
|
end
|
|
end
|
|
loop()
|
|
end
|
|
|
|
for mod_name in pairs(pack_mods) do
|
|
local function loop()
|
|
local selected_mod = data.mods[mod_name]
|
|
if not selected_mod then return end
|
|
|
|
if selected_mod.required then
|
|
for _, name_required in ipairs(selected_mod.required) do
|
|
if not (pack_mods[name_required] or provided_mods[name_required]) then
|
|
print("Missing: " .. mod_name .. " requires " .. name_required)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
loop()
|
|
end
|
|
end
|
|
|
|
local standardize_data = function()
|
|
for name, data in pairs(data.mods) do
|
|
local function loop()
|
|
if not (type(data) == "table") then
|
|
return
|
|
end
|
|
|
|
if data.optional then table.sort(data.optional) end
|
|
if data.provides then table.sort(data.provides) end
|
|
if data.required then table.sort(data.required) end
|
|
end
|
|
loop()
|
|
end
|
|
end
|
|
|
|
local techage = "Unnamed Luanti TechAge Pack"
|
|
local technic = "Unnamed Luanti Technic Pack"
|
|
|
|
check_dependencies(technic)
|
|
-- copy_pack_mods(techage, "../Luanti_Servers/mods")
|
|
|
|
standardize_data()
|
|
utility.save_data(data)
|