From b6cfcdcc6f10673d75d8c84009a14c4f41788fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Tue, 10 Nov 2015 16:49:29 +0100 Subject: [PATCH] Implement dnf hooks for post-update actions Similar to previous yum hooks: - notify dom0 about installed updates (possibly clear "updates pending" marker) - trigger appmenus synchronization QubesOS/qubes-issues#1282 --- Makefile | 9 ++++++ misc/dnf-qubes-hooks.conf | 4 +++ misc/dnf-qubes-hooks.py | 62 +++++++++++++++++++++++++++++++++++++++ rpm_spec/core-vm.spec | 2 ++ 4 files changed, 77 insertions(+) create mode 100644 misc/dnf-qubes-hooks.conf create mode 100644 misc/dnf-qubes-hooks.py diff --git a/Makefile b/Makefile index 1bd148d..5cbffdb 100644 --- a/Makefile +++ b/Makefile @@ -131,6 +131,15 @@ install-rh: install-systemd install-systemd-dropins install-sysvinit install -D -m 0644 misc/dracut-qubes.conf \ $(DESTDIR)/usr/lib/dracut/dracut.conf.d/30-qubes.conf + install -D -m 0644 misc/dnf-qubes-hooks.py \ + $(DESTDIR)/usr/lib/python2.7/site-packages/dnf-plugins/qubes-hooks.py + install -D -m 0644 misc/dnf-qubes-hooks.pyc \ + $(DESTDIR)/usr/lib/python2.7/site-packages/dnf-plugins/qubes-hooks.pyc + install -D -m 0644 misc/dnf-qubes-hooks.pyo \ + $(DESTDIR)/usr/lib/python2.7/site-packages/dnf-plugins/qubes-hooks.pyo + install -D -m 0644 misc/dnf-qubes-hooks.conf $(DESTDIR)/etc/dnf/plugins/qubes-hooks.conf + + install-common: $(MAKE) -C autostart-dropins install install -m 0644 -D misc/fstab $(DESTDIR)/etc/fstab diff --git a/misc/dnf-qubes-hooks.conf b/misc/dnf-qubes-hooks.conf new file mode 100644 index 0000000..618c0c5 --- /dev/null +++ b/misc/dnf-qubes-hooks.conf @@ -0,0 +1,4 @@ +[main] +enabled = 1 +notify-updates = 1 +sync-appmenus = 1 diff --git a/misc/dnf-qubes-hooks.py b/misc/dnf-qubes-hooks.py new file mode 100644 index 0000000..8e72289 --- /dev/null +++ b/misc/dnf-qubes-hooks.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# coding=utf-8 +# +# The Qubes OS Project, http://www.qubes-os.org +# +# Copyright (C) 2015 Marek Marczykowski-Górecki +# +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +from __future__ import absolute_import +import logging +import dnf +import subprocess + +PLUGIN_CONF = 'qubes-hooks' + +class QubesHooks(dnf.Plugin): + name = 'qubes-hooks' + + def __init__(self, base, cli): + super(QubesHooks, self).__init__(base, cli) + self.base = base + self.log = logging.getLogger('dnf') + + def transaction(self): + config = self.read_config(self.base.conf, PLUGIN_CONF) + + if config.getboolean('main', 'notify-updates'): + # Get all updates available _before_ this transaction + query = self.base.sack.query() + query = query.upgrades() + updates = set(query.run()) + # Get packages installed in this transaction... + just_installed = self.base.transaction + # ...and filter them out of available updates + for item in just_installed: + for pkg in item.installs(): + updates.discard(pkg) + subprocess.call([ + '/usr/lib/qubes/qrexec-client-vm', + 'dom0', + 'qubes.NotifyUpdates', + '/bin/echo', + str(len(updates)) + ]) + + if config.getboolean('main', 'sync-appmenus'): + self.log.info("Sending application list and icons to dom0") + subprocess.call(['/usr/lib/qubes/qubes-trigger-sync-appmenus.sh']) diff --git a/rpm_spec/core-vm.spec b/rpm_spec/core-vm.spec index f0a0c07..8aeb89b 100644 --- a/rpm_spec/core-vm.spec +++ b/rpm_spec/core-vm.spec @@ -332,6 +332,7 @@ rm -f %{name}-%{version} %config(noreplace) /etc/yum.conf.d/qubes-proxy.conf %config(noreplace) /etc/yum.repos.d/qubes-r3.repo /etc/yum/pluginconf.d/yum-qubes-hooks.conf +%config(noreplace) /etc/dnf/plugins/qubes-hooks.conf /etc/yum/post-actions/qubes-trigger-sync-appmenus.action /usr/lib/systemd/system/user@.service.d/90-session-stop-timeout.conf /usr/sbin/qubes-serial-login @@ -377,6 +378,7 @@ rm -f %{name}-%{version} /usr/lib/qubes/xdg-icon /usr/lib/qubes/update-proxy-configs /usr/lib/yum-plugins/yum-qubes-hooks.py* +/usr/lib/python2.7/site-packages/dnf-plugins/qubes-hooks.py* /usr/lib/dracut/dracut.conf.d/30-qubes.conf /usr/lib64/python2.7/site-packages/qubes/xdg.py* /usr/sbin/qubes-firewall