From 71034d171fe80d305d766e15ba894de78062cc11 Mon Sep 17 00:00:00 2001 From: Pavel Egorov Date: Wed, 29 Jul 2026 03:30:49 +0300 Subject: [yay] add hooks --- .config/yay/hooks/install_log.lua | 30 +++++++++++++ .config/yay/hooks/maintainer_change.lua | 75 +++++++++++++++++++++++++++++++++ .config/yay/hooks/recently_modified.lua | 18 ++++++++ 3 files changed, 123 insertions(+) create mode 100644 .config/yay/hooks/install_log.lua create mode 100644 .config/yay/hooks/maintainer_change.lua create mode 100644 .config/yay/hooks/recently_modified.lua (limited to '.config/yay/hooks') diff --git a/.config/yay/hooks/install_log.lua b/.config/yay/hooks/install_log.lua new file mode 100644 index 0000000..e07183e --- /dev/null +++ b/.config/yay/hooks/install_log.lua @@ -0,0 +1,30 @@ +-- Copypasted from https://github.com/Jguer/yay/blob/next/doc/examples/install_log.lua + + +local log_path = (os.getenv("XDG_STATE_HOME") or (os.getenv("HOME") .. "/.local/state")) .. "/yay/install.log" +local log_dir = log_path:match("^(.+)/[^/]+$") + +yay.create_autocmd("PostInstall", { + desc = "append every installed/upgraded package to a persistent log", + callback = function(event) + yay.log.info("install_log: writing to ", log_path) + os.execute("mkdir -p " .. log_dir) + local f, err = io.open(log_path, "a") + if not f then + yay.log.warn("install_log: cannot open log file: ", err) + return + end + + local ts = os.date("%Y-%m-%dT%H:%M:%S") + + for _, pkg in ipairs(event.data.packages) do + local upgrade = pkg.local_version ~= "" + local action = upgrade and "upgrade" or "install" + local version_change = upgrade and (pkg.local_version .. " -> " .. pkg.version) or pkg.version + f:write(string.format("%s %-9s %-7s %-14s %-12s %s\n", + ts, action, pkg.source, pkg.reason, pkg.name, version_change)) + end + + f:close() + end, +}) diff --git a/.config/yay/hooks/maintainer_change.lua b/.config/yay/hooks/maintainer_change.lua new file mode 100644 index 0000000..9f8be2d --- /dev/null +++ b/.config/yay/hooks/maintainer_change.lua @@ -0,0 +1,75 @@ +-- Copypasted from https://github.com/Jguer/yay/blob/next/doc/examples/maintainer_change.lua +-- +-- Warn when an AUR package's maintainer changes between upgrades. +-- +-- The known maintainer for each package is stored in a plain text cache file +-- inside the yay cache directory (build_dir). On the first upgrade for a +-- package the current maintainer is recorded without any warning. On +-- subsequent upgrades: +-- * same maintainer → debug "match correct" +-- * different maintainer → error "new maintainer, double check build files" +-- +-- The cache is updated whenever a new or changed maintainer is seen. +-- +-- Cache file location: /maintainer_cache +-- Format: one "pkgname=maintainer" entry per line. + +-- missing reliable cfg getter +local cache_dir = (os.getenv("XDG_CACHE_HOME") or (os.getenv("HOME") .. "/.cache")) .. "/yay" +local cache_file = cache_dir .. "/maintainer_cache" + +local function load_cache() + local cache = {} + local f = io.open(cache_file, "r") + if not f then return cache end + for line in f:lines() do + local name, maintainer = line:match("^([^=]+)=(.*)$") + if name then + cache[name] = maintainer + end + end + f:close() + return cache +end + +local function save_cache(cache) + local f = assert(io.open(cache_file, "w")) + for name, maintainer in pairs(cache) do + f:write(name .. "=" .. maintainer .. "\n") + end + f:close() +end + +yay.create_autocmd("UpgradeSelect", { + desc = "warn on AUR maintainer changes", + callback = function(event) + yay.log.info("checking for AUR maintainer changes") + local cache = load_cache() + local dirty = false + + for _, pkg in ipairs(event.data.upgrades) do + if pkg.repository == "aur" and pkg.maintainer ~= "" then + local cached = cache[pkg.name] + if cached == nil then + -- First time seeing this package: seed the cache silently. + cache[pkg.name] = pkg.maintainer + dirty = true + elseif cached == pkg.maintainer then + yay.log.debug("match correct: " .. pkg.name .. " " .. pkg.maintainer) + else + yay.log.error("new maintainer, double check build files: ", pkg.name, + "(was: " .. cached .. ", now: " .. pkg.maintainer .. ")") + cache[pkg.name] = pkg.maintainer + dirty = true + end + end + end + + if dirty then + yay.log.info("saving maintainer cache:", cache_file) + save_cache(cache) + end + + return { exclude = {}, skip_menu = false } + end, +}) diff --git a/.config/yay/hooks/recently_modified.lua b/.config/yay/hooks/recently_modified.lua new file mode 100644 index 0000000..561d87e --- /dev/null +++ b/.config/yay/hooks/recently_modified.lua @@ -0,0 +1,18 @@ +-- Copypasted from https://github.com/Jguer/yay/blob/next/doc/examples/recently_modified.lua + +yay.create_autocmd("UpgradeSelect", { + desc = "skip recently modified AUR upgrades", + callback = function(event) + yay.log.info("pre-excluding AUR packages modified in the last 3 days") + local exclude = {} + local recent_cutoff = os.time() - (3 * 24 * 60 * 60) + for _, pkg in ipairs(event.data.upgrades) do + if pkg.repository == "aur" and pkg.last_modified >= recent_cutoff then + yay.log.warn("pre-excluding recently modified AUR package: ", pkg.name) + table.insert(exclude, pkg.name) + end + end + + return { exclude = exclude, skip_menu = false } + end, +}) -- cgit v1.3