7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen# Yum plugin to re-patch container rootfs after a yum update is done
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen#
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen# Copyright (C) 2012 Oracle
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen#
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen# Authors:
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen# Dwight Engen <dwight.engen@oracle.com>
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen#
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# This library is free software; you can redistribute it and/or
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# modify it under the terms of the GNU Lesser General Public
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# License as published by the Free Software Foundation; either
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# version 2.1 of the License, or (at your option) any later version.
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen#
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# This library is distributed in the hope that it will be useful,
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen# but WITHOUT ANY WARRANTY; without even the implied warranty of
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# Lesser General Public License for more details.
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen#
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# You should have received a copy of the GNU Lesser General Public
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# License along with this library; if not, write to the Free Software
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
391260dcb2ae8060134b635bc268ccdecf59003dDwight Engen# USA
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen#
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engenimport os
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engenfrom fnmatch import fnmatch
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engenfrom yum.plugins import TYPE_INTERACTIVE
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engenfrom yum.plugins import PluginYumExit
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engenrequires_api_version = '2.0'
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engenplugin_type = (TYPE_INTERACTIVE,)
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engendef posttrans_hook(conduit):
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen pkgs = []
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen patch_required = False
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen # If we aren't root, we can't have updated anything
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen if os.geteuid():
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen return
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen # See what packages have files that were patched
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen confpkgs = conduit.confString('main', 'packages')
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen if not confpkgs:
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen return
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen tmp = confpkgs.split(",")
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen for confpkg in tmp:
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen pkgs.append(confpkg.strip())
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen conduit.info(2, "lxc-patch: checking if updated pkgs need patching...")
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen ts = conduit.getTsInfo()
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen for tsmem in ts.getMembers():
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen for pkg in pkgs:
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen if fnmatch(pkg, tsmem.po.name):
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen patch_required = True
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen if patch_required:
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen conduit.info(2, "lxc-patch: patching container...")
7ceebfd12a0503bee5eaab8d4c062a4389939a61Dwight Engen os.spawnlp(os.P_WAIT, "lxc-patch", "lxc-patch", "--patch", "/")