]> git.proxmox.com Git - mirror_lxc.git/blob - config/yum/lxc-patch.py
Merge pull request #4023 from diederikdehaas/fix-SC2006
[mirror_lxc.git] / config / yum / lxc-patch.py
1 # Yum plugin to re-patch container rootfs after a yum update is done
2 #
3 # Copyright (C) 2012 Oracle
4 #
5 # Authors:
6 # Dwight Engen <dwight.engen@oracle.com>
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 # USA
22 #
23
24 import os
25 from fnmatch import fnmatch
26 from yum.plugins import TYPE_INTERACTIVE
27
28 requires_api_version = '2.0'
29 plugin_type = (TYPE_INTERACTIVE,)
30
31 def posttrans_hook(conduit):
32 pkgs = []
33 patch_required = False
34
35 # If we aren't root, we can't have updated anything
36 if os.geteuid():
37 return
38
39 # See what packages have files that were patched
40 confpkgs = conduit.confString('main', 'packages')
41 if not confpkgs:
42 return
43
44 tmp = confpkgs.split(",")
45 for confpkg in tmp:
46 pkgs.append(confpkg.strip())
47
48 conduit.info(2, "lxc-patch: checking if updated pkgs need patching...")
49 ts = conduit.getTsInfo()
50 for tsmem in ts.getMembers():
51 for pkg in pkgs:
52 if fnmatch(pkg, tsmem.po.name):
53 patch_required = True
54 if patch_required:
55 conduit.info(2, "lxc-patch: patching container...")
56 os.spawnlp(os.P_WAIT, "lxc-patch", "lxc-patch", "--patch", "/")