diff --git a/examples/specs/5-x86-g-remaster-add-games.spec b/examples/specs/5-x86-g-remaster-add-games.spec index e035544..04c9089 100644 --- a/examples/specs/5-x86-g-remaster-add-games.spec +++ b/examples/specs/5-x86-g-remaster-add-games.spec @@ -23,6 +23,10 @@ source_iso: /sabayon/iso_images/Sabayon_5.0_G.iso # - kmerge.sh - setup kernel bins # inner_chroot_script: /sabayon/scripts/inner_chroot_script.sh +# Inner chroot script command, to be executed inside destination chroot after +# packages installation and removal +# inner_chroot_script_after: /sabayon/scripts/inner_chroot_script_after.sh + # Outer chroot script command, to be executed outside destination chroot before # before entering it (and AFTER inner_chroot_script) # outer_chroot_script_after: /path/to/script/to/be/executed/outside/after diff --git a/molecule/specs/plugins/builtin.py b/molecule/specs/plugins/builtin.py index fbbcf56..167522a 100644 --- a/molecule/specs/plugins/builtin.py +++ b/molecule/specs/plugins/builtin.py @@ -240,6 +240,35 @@ class ChrootHandler(GenericExecutionStep): ) return 0 + def _exec_inner_script(self, exec_script): + + while 1: + tmp_dir = os.path.join(self.dest_dir, + str(molecule.utils.get_random_number())) + if not os.path.lexists(tmp_dir): + break + + os.makedirs(tmp_dir) + tmp_exec = os.path.join(tmp_dir, "inner_exec") + shutil.copy2(exec_script, tmp_exec) + os.chmod(tmp_exec, 0755) + dest_exec = tmp_exec[len(self.dest_dir):] + if not dest_exec.startswith("/"): + dest_exec = "/%s" % (dest_exec,) + + rc = molecule.utils.exec_chroot_cmd([dest_exec], self.dest_dir, + self.metadata.get('prechroot',[])) + os.remove(tmp_exec) + os.rmdir(tmp_dir) + + if rc != 0: + self.Output.updateProgress("[%s|%s] %s: %s" % ( + blue("ChrootHandler"),darkred(self.spec_name), + _("inner chroot hook failed"),rc, + ) + ) + return rc + def run(self): self.Output.updateProgress("[%s|%s] %s" % ( @@ -251,35 +280,12 @@ class ChrootHandler(GenericExecutionStep): # run inner chroot script exec_script = self.metadata.get('inner_chroot_script') if exec_script: - if os.path.isfile(exec_script) and os.access(exec_script,os.R_OK): - - while 1: - tmp_dir = os.path.join(self.dest_dir, - str(molecule.utils.get_random_number())) - if not os.path.lexists(tmp_dir): - break - - os.makedirs(tmp_dir) - tmp_exec = os.path.join(tmp_dir,"inner_exec") - shutil.copy2(exec_script,tmp_exec) - os.chmod(tmp_exec,0755) - dest_exec = tmp_exec[len(self.dest_dir):] - if not dest_exec.startswith("/"): - dest_exec = "/%s" % (dest_exec,) - - rc = molecule.utils.exec_chroot_cmd([dest_exec], self.dest_dir, - self.metadata.get('prechroot',[])) - os.remove(tmp_exec) - os.rmdir(tmp_dir) - + if os.path.isfile(exec_script) and os.access(exec_script, os.R_OK): + rc = self._exec_inner_script(exec_script) if rc != 0: - self.Output.updateProgress("[%s|%s] %s: %s" % ( - blue("ChrootHandler"),darkred(self.spec_name), - _("inner chroot hook failed"),rc, - ) - ) return rc + self.Output.updateProgress("[%s|%s] %s" % ( blue("ChrootHandler"),darkred(self.spec_name), _("hooks completed succesfully"), diff --git a/molecule/specs/plugins/remaster.py b/molecule/specs/plugins/remaster.py index ad6c7ef..165616b 100644 --- a/molecule/specs/plugins/remaster.py +++ b/molecule/specs/plugins/remaster.py @@ -251,6 +251,14 @@ class ChrootHandler(BuiltinChrootHandler): if rc != 0: return rc + # run inner chroot script after pkgs handling + exec_script = self.metadata.get('inner_chroot_script_after') + if exec_script: + if os.path.isfile(exec_script) and os.access(exec_script, os.R_OK): + rc = self._exec_inner_script(exec_script) + if rc != 0: + return rc + return 0 @@ -324,6 +332,10 @@ class RemasterSpec(GenericSpec): 'cb': self.valid_path_string, 've': self.ve_string_stripper, }, + 'inner_chroot_script_after': { + 'cb': self.valid_path_string, + 've': self.ve_string_stripper, + }, 'outer_chroot_script_after': { 'cb': self.valid_path_string, 've': self.ve_string_stripper,