# Yum plugin to re-patch container rootfs after a yum update is done
#
# Copyright (C) 2012 Oracle
#
# Authors:
# Dwight Engen <dwight.engen@oracle.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 Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

import os
from fnmatch import fnmatch
from yum.plugins import TYPE_INTERACTIVE
from yum.plugins import PluginYumExit

requires_api_version = '2.0'
plugin_type = (TYPE_INTERACTIVE,)

def posttrans_hook(conduit):
    pkgs = []
    patch_required = False

    # If we aren't root, we can't have updated anything
    if os.geteuid():
        return

    # See what packages have files that were patched
    confpkgs = conduit.confString('main', 'packages')
    if not confpkgs:
        return

    tmp = confpkgs.split(",")
    for confpkg in tmp:
        pkgs.append(confpkg.strip())

    conduit.info(2, "lxc-patch: checking if updated pkgs need patching...")
    ts = conduit.getTsInfo()
    for tsmem in ts.getMembers():
        for pkg in pkgs:
            if fnmatch(pkg, tsmem.po.name):
                patch_required = True
    if patch_required:
        conduit.info(2, "lxc-patch: patching container...")
        os.spawnlp(os.P_WAIT, "lxc-patch", "lxc-patch", "--patch", "/")

@@ -151,31 +151,31 @@
 m%3E%0A#%0A# This 
-program
+library
  is free sof
@@ -215,17 +215,17 @@
 d/or
+%0A#
  modify
-%0A#
  it 
@@ -243,32 +243,39 @@
 erms of the GNU 
+Lesser 
 General Public L
@@ -264,32 +264,34 @@
 r General Public
+%0A#
  License as publ
@@ -298,18 +298,16 @@
 ished by
-%0A#
  the Fre
@@ -335,16 +335,18 @@
 ; either
+%0A#
  version
@@ -347,16 +347,18 @@
 ersion 2
+.1
  of the 
@@ -368,18 +368,16 @@
 ense, or
-%0A#
  (at you
@@ -414,23 +414,23 @@
 %0A# This 
-program
+library
  is dist
@@ -605,22 +605,21 @@
  the
-%0A#
  GNU
- Library
+%0A# Lesser
  Gen
@@ -703,16 +703,23 @@
 the GNU 
+Lesser 
 General 
@@ -724,24 +724,26 @@
 l Public
+%0A#
  License
 %0A# along
@@ -734,18 +734,16 @@
  License
-%0A#
  along w
@@ -755,15 +755,15 @@
 his 
-program
+library
 ; if
@@ -820,34 +820,38 @@
 ., 5
-9 Temple Place - Suite 330
+1 Franklin Street, Fifth Floor
 , Bo
@@ -863,24 +863,25 @@
  MA 
+ 
 0211
-1
+0
 -130
-7,
+1%0A#
  USA
-.
 %0A#%0A%0A

correct license on file to LGPL vs. GPL and fix address