From 3209008573b2f58fb271fac35ae086ab75189616 Mon Sep 17 00:00:00 2001 From: Jeremy Katz Date: Nov 07 2005 17:58:01 +0000 Subject: - enable plugins by default - add installyonlyn plugin so that we only keep two kernels around by default --- diff --git a/installonlyn.py b/installonlyn.py new file mode 100644 index 0000000..fb63325 --- /dev/null +++ b/installonlyn.py @@ -0,0 +1,70 @@ +# A plugin for yum which only leaves n 'kernel' packages installed instead +# of infinitely doing installonly +# +# Copyright 2005 Red Hat, Inc. +# Jeremy Katz +# +# 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. +# +# version 0.01 + +import os +from rpmUtils import miscutils +from yum.constants import * +from yum.plugins import TYPE_CORE, TYPE_INTERFACE, PluginYumExit +from yum.packages import YumInstalledPackage + +requires_api_version = '2.1' +plugin_type = (TYPE_CORE,) + +def sortPackages(pkg1,pkg2): + """sort pkgtuples by evr""" + return miscutils.compareEVR((pkg1[2:]),(pkg2[2:])) + +def get_running_kernel_version_release(): + """This takes the output of uname and figures out the (version, release) + tuple for the running kernel.""" + ver = os.uname()[2] + for s in ("bigmem", "enterprise", "smp", "hugemem", "guest", "hypervisor"): + if ver.endswith(s): + ver = ver.replace(s, "") + (v, r) = ver.split("-", 1) + return (v, r) + +def config_hook(conduit): + global num_tokeep + num_tokeep = conduit.confInt('main', 'tokeep', default=2) + +def postresolve_hook(conduit): + ts = conduit.getTsInfo() + rpmdb = conduit.getRpmDB() + conf = conduit.getConf() + mems = ts.getMembers() + toremove = [] + for instpkg in conf.installonlypkgs: + for m in mems: + if m.name == instpkg: + installed = rpmdb.returnTupleByKeyword(name=instpkg) + if len(installed) >= num_tokeep - 1: # since we're adding one + numleft = len(installed) - num_tokeep + 1 + (curv, curr) = get_running_kernel_version_release() + + installed.sort(sortPackages) + installed.reverse() + for (n, a, e, v, r) in installed: + if (v, r) == (curv, curr): # don't remove running + continue + toremove.append(YumInstalledPackage(rpmdb.returnHeaderByTuple((n,a,e,v,r))[0])) + numleft -= 1 + if numleft == 0: + break + + map(lambda x: ts.addErase(x), toremove) diff --git a/plugin.conf b/plugin.conf new file mode 100644 index 0000000..8e4d76c --- /dev/null +++ b/plugin.conf @@ -0,0 +1,2 @@ +[main] +enabled=1 diff --git a/yum.conf.fedora b/yum.conf.fedora index 5d7b6d2..9e877ea 100644 --- a/yum.conf.fedora +++ b/yum.conf.fedora @@ -6,9 +6,9 @@ pkgpolicy=newest distroverpkg=redhat-release tolerant=1 exactarch=1 -retries=20 obsoletes=1 gpgcheck=1 +plugins=1 # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d diff --git a/yum.spec b/yum.spec index b743633..8f77e01 100644 --- a/yum.spec +++ b/yum.spec @@ -3,7 +3,7 @@ Summary: RPM installer/updater Name: yum Version: 2.4.0 -Release: 8 +Release: 9 License: GPL Group: System Environment/Base Source0: http://linux.duke.edu/projects/yum/download/2.4/yum-%{version}.tar.gz @@ -14,6 +14,10 @@ Patch3: yum-2.4-returnbyname-list.patch Patch4: yum-2.4-tsconsts.patch Patch5: yum-2.4-ppc64.patch Patch6: yum-2.4-more-list-fixes.patch + +Source99: plugin.conf +# default plugins here +Source100: installonlyn.py URL: http://linux.duke.edu/yum/ BuildArchitectures: noarch BuildRequires: python @@ -51,6 +55,9 @@ install -m 644 %{SOURCE1} $RPM_BUILD_ROOT/etc/yum.conf chmod +x $RPM_BUILD_ROOT/%{_sysconfdir}/cron.daily/yum.cron mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/yum/pluginconf.d $RPM_BUILD_ROOT/usr/lib/yum-plugins +install -m 644 %{SOURCE100} $RPM_BUILD_ROOT/usr/lib/yum-plugins/installonlyn.py +install -m 644 %{SOURCE99} $RPM_BUILD_ROOT/%{_sysconfdir}/yum/pluginconf.d/installonlyn.conf + %clean rm -rf $RPM_BUILD_ROOT @@ -88,9 +95,15 @@ exit 0 %{_mandir}/man*/* # plugin stuff %dir %{_sysconfdir}/yum/pluginconf.d +%config %{_sysconfdir}/yum/pluginconf.d/* %dir /usr/lib/yum-plugins +/usr/lib/yum-plugins/* %changelog +* Mon Nov 7 2005 Jeremy Katz - 2.4.0-9 +- enable plugins by default +- add installyonlyn plugin so that we only keep two kernels around by default + * Mon Oct 24 2005 Jeremy Katz - 2.4.0-8 - drop macro patch - more fixes for returnByName* stuff -- need to leave best arch selection