Skip to content

Commit

Permalink
Merge pull request #8 from marusak/install
Browse files Browse the repository at this point in the history
kpatch: Add subcommand to only install patches
  • Loading branch information
sm00th authored Aug 24, 2021
2 parents d3ac9de + a5d30ac commit 95f1422
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
37 changes: 32 additions & 5 deletions kpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ def __init__(self, cli):

@staticmethod
def set_argparser(parser):
parser.add_argument('action', metavar="auto|manual|status")
parser.add_argument('action', metavar="auto|manual|install|status")


def configure(self):
demands = self.cli.demands

demands.root_user = True
if self.opts.action == "auto":
if self.opts.action in ["auto", "install", "status"]:
demands.resolving = True
demands.sack_activation = True
demands.available_repos = True
Expand All @@ -93,6 +93,26 @@ def configure(self):
demands.available_repos = False


def _list_missing_kpp_pkgs(self):
kpps = []

installed_kernels = self.base.sack.query().installed().filter(name=KERNEL_PKG_NAME)

for kernel_pkg in installed_kernels:
kpp_pkg_name = _kpp_name_from_kernel_pkg(kernel_pkg)
installed = self.base.sack.query().installed().filter(name=kpp_pkg_name).run()
if installed:
sub_q = self.base.sack.query().filter(name=kpp_pkg_name, release=installed[0].release, version=installed[0].version)
kpp_pkgs_query = self.base.sack.query().filter(name=kpp_pkg_name, arch=kernel_pkg.arch).latest().difference(sub_q)
else:
kpp_pkgs_query = self.base.sack.query().filter(name=kpp_pkg_name, arch=kernel_pkg.arch).latest()

for pkg in kpp_pkgs_query:
kpps.append(str(pkg))

return kpps


def _install_missing_kpp_pkgs(self):
installed_kernels = self.base.sack.query().installed().filter(name=KERNEL_PKG_NAME)

Expand Down Expand Up @@ -147,7 +167,14 @@ def run(self):
conf.has_option('main', KPATCH_UPDATE_OPT) and
conf.getboolean('main', KPATCH_UPDATE_OPT)):
kp_status = "auto"
logger.info(_("kpatch update setting: {}").format(kp_status))
logger.info(_("Kpatch update setting: {}").format(kp_status))

kpps = self._list_missing_kpp_pkgs()
if kpps:
logger.info(_("Available patches: {}").format(", ".join(kpps)))

elif action == "install":
self._install_missing_kpp_pkgs()
else:
raise dnf.exceptions.Error(_("Invalid argument: {}").format(action))

Expand Down Expand Up @@ -192,8 +219,8 @@ def resolved(self):
explicit_kpp_install = []
for tr_item in self.base.transaction:
# It might not be safe to check tr_item.pkg.name as there might be
# some dnf internal transaction items not linked to any pacakge.
# Check first whether the action is a pacakge related action
# some dnf internal transaction items not linked to any package.
# Check first whether the action is a package related action
if tr_item.action in dnf.transaction.FORWARD_ACTIONS:
if tr_item.pkg.name == KERNEL_PKG_NAME:
need_kpp_for.append(tr_item.pkg)
Expand Down
3 changes: 3 additions & 0 deletions man/dnf.kpatch.8
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ automatic kpatch\-patch installation for future kernel installations.
.B manual
Disables automatic installation of kpatch-patch packages.
.TP
.B install
Installs missing kpatch\-patch packages for installed kernels.
.TP
.B status
Queries the current installation setting of \fBdnf\-kpatch\fR.
.RE
Expand Down

0 comments on commit 95f1422

Please sign in to comment.