#!/usr/bin/lua -- aur-repo-check -- Pierre Chapuis -- Released under the MIT license. local http = require("socket.http") local json = require("json") local alpm = require("lualpm") -- FUNCTIONS local process_args = function(args) local mode = 0 local aR, aO = "archlinuxfr", nil for _,arg in ipairs(args) do if arg:find("-") == 1 then mode = arg:sub(2) elseif mode == "r" then aR = arg elseif mode == "o" then aO = arg end end if aO == nil then aO = os.getenv("PWD") .. "/" .. aR .. ".xhtml" end return aR, aO end local char_encode = function(s) return(s:gsub("+", "%%2B")) end local json_infos = function(pkg) local request, code = http.request("http://aur.archlinux.org/rpc.php?type=info&arg=" .. char_encode(pkg)) if code == 200 then local results = json.decode(request).results if results.ID then return results.ID, results.Version else return "Not in AUR" end else return("AUR RPC error") end end local line = function(pkg, repo_v, aur_id, aur_v) if aur_id == "AUR RPC error" then return("" .. pkg .. "AUR RPC error\n") elseif aur_id == "Not in AUR" then return("" .. pkg .. "Not in AUR\n") else local color if repo_v == aur_v then color = "green" else color = "orange" end return("" .. pkg .. "" .. repo_v .. "" .. aur_v .. "\n") end end ---- MAIN local aR, aO = process_args(arg) local head = [[ ]] .. aR .. [[ repository state

]] .. aR .. [[ repository state

]] local tail = [[
packagerepository versionAUR version

]] -- build repo-ver so that repo_ver[pkgname] = pkgver local repo_ver = {} alpm.initialize() alpm.option_set_dbpath("/var/lib/pacman/") local alpm_db = alpm.db_register_sync(aR) if (alpm_db == nil) then print("alpm error: " .. alpm.strerrorlast()) end for _, pkg in ipairs(alpm_db:db_get_pkgcache()) do repo_ver[pkg:pkg_get_name()] = pkg:pkg_get_version() end -- sort the keys of repo_ver local sorted_pkg = {} for i in pairs(repo_ver) do table.insert(sorted_pkg, i) end table.sort(sorted_pkg) -- compare versions to AUR and write to file local of = io.open(aO, "w+") of:write(head) print("Processing " .. aR .. " repository...") for _,pkg in ipairs(sorted_pkg) do print(pkg) of:write(line(pkg, repo_ver[pkg], json_infos(pkg))) end print("Done.") of:write(tail) of:close()