From 583fa7c9a90696d8c198eccfb1a0b6d5a874b09d Mon Sep 17 00:00:00 2001 From: shadowfax-chc Date: Sat, 5 Jan 2013 02:56:13 -0500 Subject: [PATCH] Updated layman.add and layman.delete to adjust make.conf When the first overlay is added, the make.conf needs to source layman's make.conf so that emerge sees the packages in the overlay. Likewise, when the last overlay is deleted, the make.conf needs to no longer source layman's make.conf as it will cause emerge to break. --- salt/modules/layman.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/salt/modules/layman.py b/salt/modules/layman.py index 17baab762c..64ed460d30 100644 --- a/salt/modules/layman.py +++ b/salt/modules/layman.py @@ -13,6 +13,18 @@ def __virtual__(): return 'layman' return False +def _get_makeconf(): + ''' + Find the correct make.conf. Gentoo recently moved the make.conf + but still supports the old location, using the old location first + ''' + old_conf = '/etc/make.conf' + new_conf = '/etc/portage/make.conf' + if __salt__['file.file_exists'](old_conf): + return old_conf + elif __salt__['file.file_exists'](new_conf): + return new_conf + def add(overlay): ''' Add the given overlay from the caced remote list to your locally @@ -31,6 +43,15 @@ def add(overlay): __salt__['cmd.retcode'](cmd) new_overlays = list_local() + # If we did not have any overlays before and we sucessfully added + # a new one. We need to ensure the make.conf is sourcing layman's + # make.conf so emerge can see the overlays + if len(old_overlays == 0) and len(new_overlays > 0): + srcline = 'source /var/lib/layman/make.conf' + makeconf = _get_makeconf() + if not __salt__['file.contains'](makeconf, layman): + __salt__['file.append'](makeconf, srcline) + ret = [overlay for overlay in new_overlays if overlay not in old_overlays] return ret @@ -52,6 +73,14 @@ def delete(overlay): __salt__['cmd.retcode'](cmd) new_overlays = list_local() + # If we now have no overlays added, We need to ensure that the make.conf + # does not source layman's make.conf, as it will break emerge + if len(new_overlays == 0): + srcline = 'source /var/lib/layman/make.conf' + makeconf = _get_makeconf() + if __salt__['file.contains'](makeconf, layman): + __salt__['file.sed'](makeconf, srcline, '') + ret = [overlay for overlay in old_overlays if overlay not in new_overlays] return ret