require ("luamods/command")
require("config/software_conf")

pkgnamestbl = {}
pkgvstbl = {}
pkgdesctbl = {}
rtr = ""

rtr = command.ex(software_conf.opkg_all_pack)

if (rtr == nil) then rtr = "" end
packages = {}
for line in rtr:gmatch("(.-\n)") do
    name,version,desc = line:match("([^%s]+) %- ([^%s]+)%s*%-?%s*([^\n]*)\n")
    if (name ~= nil) and (version ~= nil) then
        package = {}
        package.name = name
        package.version = version
        package.desc = desc or ""
        table.insert(packages, package)
    end
end

print("Content-type: application/octet-stream")
print("Content-Disposition: attachment; filename=\"all_pkgs.csv\"")
print("")

for num,package in pairs(packages) do
    print(package.name..","..package.version..","..package.desc)
end
