2015-11-10 16:49:29 +01:00
|
|
|
# coding=utf-8
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# 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 <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
from __future__ import absolute_import
|
2017-09-24 12:20:12 +02:00
|
|
|
from distutils.version import LooseVersion
|
2015-11-10 16:49:29 +01:00
|
|
|
import logging
|
|
|
|
import dnf
|
2017-09-24 12:20:12 +02:00
|
|
|
import dnf.const
|
2015-11-10 16:49:29 +01:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
PLUGIN_CONF = 'qubes-hooks'
|
|
|
|
|
2021-05-05 11:19:21 +02:00
|
|
|
def is_active(service):
|
|
|
|
status = subprocess.call(["systemctl", "is-active", "--quiet", service])
|
|
|
|
return status == 0
|
|
|
|
|
2015-11-10 16:49:29 +01:00
|
|
|
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')
|
|
|
|
|
2019-08-03 03:39:10 +02:00
|
|
|
def resolved(self):
|
2021-05-05 11:19:21 +02:00
|
|
|
if not is_active("qubes-qrexec-agent"):
|
|
|
|
return
|
2019-08-03 03:39:10 +02:00
|
|
|
# in case of no action to do, transaction() hook won't be called;
|
|
|
|
# report updates availability here - especially when everything is up
|
|
|
|
# to date - to clear updates-available flag
|
|
|
|
if not self.base.transaction:
|
|
|
|
query = self.base.sack.query()
|
|
|
|
query = query.upgrades()
|
|
|
|
updates = set(query.run())
|
|
|
|
subprocess.call([
|
|
|
|
'/usr/lib/qubes/qrexec-client-vm',
|
|
|
|
'dom0',
|
|
|
|
'qubes.NotifyUpdates',
|
|
|
|
'/bin/echo',
|
|
|
|
str(len(updates))
|
|
|
|
])
|
|
|
|
|
2015-11-10 16:49:29 +01:00
|
|
|
def transaction(self):
|
2021-05-05 11:19:21 +02:00
|
|
|
if not is_active("qubes-qrexec-agent"):
|
|
|
|
return
|
2017-09-24 12:20:12 +02:00
|
|
|
if LooseVersion(dnf.const.VERSION) < '2.0.0':
|
|
|
|
config = self.read_config(self.base.conf, PLUGIN_CONF)
|
|
|
|
else:
|
|
|
|
config = self.read_config(self.base.conf)
|
2015-11-10 16:49:29 +01:00
|
|
|
|
|
|
|
if config.getboolean('main', 'notify-updates'):
|
2020-06-27 05:35:19 +02:00
|
|
|
# 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:
|
2020-06-27 05:37:55 +02:00
|
|
|
updates.discard(item.pkg)
|
2015-11-10 16:49:29 +01:00
|
|
|
subprocess.call([
|
|
|
|
'/usr/lib/qubes/qrexec-client-vm',
|
|
|
|
'dom0',
|
|
|
|
'qubes.NotifyUpdates',
|
|
|
|
'/bin/echo',
|
|
|
|
str(len(updates))
|
|
|
|
])
|
|
|
|
|
2018-02-13 17:05:42 +01:00
|
|
|
self.log.info("Notifying dom0 about installed applications")
|
|
|
|
subprocess.call(['/etc/qubes-rpc/qubes.PostInstall'])
|