diff options
-rw-r--r-- | mic/3rdparty/pykickstart/constants.py | 1 | ||||
-rw-r--r-- | mic/3rdparty/pykickstart/parser.py | 3 | ||||
-rw-r--r-- | mic/3rdparty/pykickstart/sections.py | 5 | ||||
-rwxr-xr-x | mic/imager/baseimager.py | 41 | ||||
-rwxr-xr-x | mic/imager/loop.py | 1 | ||||
-rwxr-xr-x | mic/kickstart/__init__.py | 7 | ||||
-rw-r--r--[-rwxr-xr-x] | tests/test_configmgr.py | 0 |
7 files changed, 56 insertions, 2 deletions
diff --git a/mic/3rdparty/pykickstart/constants.py b/mic/3rdparty/pykickstart/constants.py index 5e12fc8..92f8325 100644 --- a/mic/3rdparty/pykickstart/constants.py +++ b/mic/3rdparty/pykickstart/constants.py @@ -39,6 +39,7 @@ SELINUX_PERMISSIVE = 2 KS_SCRIPT_PRE = 0 KS_SCRIPT_POST = 1 KS_SCRIPT_TRACEBACK = 2 +KS_SCRIPT_RUN = 3 KS_WAIT = 0 KS_REBOOT = 1 diff --git a/mic/3rdparty/pykickstart/parser.py b/mic/3rdparty/pykickstart/parser.py index 840a448..cf4db4c 100644 --- a/mic/3rdparty/pykickstart/parser.py +++ b/mic/3rdparty/pykickstart/parser.py @@ -202,6 +202,8 @@ class Script(KickstartObject): retval += '\n%post' elif self.type == constants.KS_SCRIPT_TRACEBACK: retval += '\n%traceback' + elif self.type == constants.KS_SCRIPT_RUN: + retval += '\n%runscript' if self.interp != "/bin/sh" and self.interp != "": retval += " --interpreter=%s" % self.interp @@ -699,4 +701,5 @@ class KickstartParser: self.registerSection(PreScriptSection(self.handler, dataObj=Script)) self.registerSection(PostScriptSection(self.handler, dataObj=Script)) self.registerSection(TracebackScriptSection(self.handler, dataObj=Script)) + self.registerSection(RunScriptSection(self.handler, dataObj=Script)) self.registerSection(PackageSection(self.handler)) diff --git a/mic/3rdparty/pykickstart/sections.py b/mic/3rdparty/pykickstart/sections.py index 44df856..51cba3b 100644 --- a/mic/3rdparty/pykickstart/sections.py +++ b/mic/3rdparty/pykickstart/sections.py @@ -194,6 +194,11 @@ class TracebackScriptSection(ScriptSection): ScriptSection._resetScript(self) self._script["type"] = KS_SCRIPT_TRACEBACK +class RunScriptSection(ScriptSection): + sectionOpen = "%runscript" + def _resetScript(self): + ScriptSection._resetScript(self) + self._script["type"] = KS_SCRIPT_RUN class PackageSection(Section): sectionOpen = "%packages" diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index dd758b4..bdf059d 100755 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1154,13 +1154,50 @@ class BaseImageCreator(object): def postinstall(self): self.copy_attachment() + def run_sign_scripts(self): + if kickstart.get_sign_scripts(self.ks)==[]: + return + msger.info("Running sign scripts ...") + if os.path.exists(self._instroot + "/tmp"): + shutil.rmtree(self._instroot + "/tmp") + os.mkdir (self._instroot + "/tmp", 0755) + for s in kickstart.get_sign_scripts(self.ks): + (fd, path) = tempfile.mkstemp(prefix = "ks-runscript-", + dir = self._instroot + "/tmp") + s.script = s.script.replace("\r", "") + os.write(fd, s.script) + os.close(fd) + os.chmod(path, 0700) + for item in os.listdir(self._imgdir): + sub = os.path.splitext(item)[1] + if sub == ".img": + shutil.move(os.path.join(self._imgdir, item), + os.path.join(self._instroot + "/tmp", item)) + oldoutdir = os.getcwd() + os.chdir(self._instroot + "/tmp") + try: + try: + p = subprocess.Popen([s.interp, path], + stdout = subprocess.PIPE, + stderr = subprocess.STDOUT) + while p.poll() == None: + msger.info(p.stdout.readline().strip()) + except OSError, (err, msg): + raise CreatorError("Failed to execute %%sign script " + "with '%s' : %s" % (s.interp, msg)) + finally: + os.chdir(oldoutdir) + os.unlink(path) + for item in os.listdir(self._instroot + "/tmp"): + shutil.move(os.path.join(self._instroot + "/tmp", item), + os.path.join(self._imgdir, item)) def __run_post_scripts(self): - msger.info("Running scripts ...") + msger.info("Running post scripts ...") if os.path.exists(self._instroot + "/tmp"): shutil.rmtree(self._instroot + "/tmp") os.mkdir (self._instroot + "/tmp", 0755) for s in kickstart.get_post_scripts(self.ks): - (fd, path) = tempfile.mkstemp(prefix = "ks-script-", + (fd, path) = tempfile.mkstemp(prefix = "ks-postscript-", dir = self._instroot + "/tmp") s.script = s.script.replace("\r", "") diff --git a/mic/imager/loop.py b/mic/imager/loop.py index cca8080..eab83b2 100755 --- a/mic/imager/loop.py +++ b/mic/imager/loop.py @@ -464,6 +464,7 @@ class LoopImageCreator(BaseImageCreator): imgsize = os.path.getsize(imgfile) msger.info("filesystem size of %s : %s bytes" % (item, imgsize)) + self.run_sign_scripts() if not self.pack_to: for item in os.listdir(self._imgdir): shutil.move(os.path.join(self._imgdir, item), diff --git a/mic/kickstart/__init__.py b/mic/kickstart/__init__.py index 8ec653c..f568f99 100755 --- a/mic/kickstart/__init__.py +++ b/mic/kickstart/__init__.py @@ -813,6 +813,13 @@ def get_post_scripts(ks): scripts.append(s) return scripts +def get_sign_scripts(ks): + scripts = [] + for s in ks.handler.scripts: + if s.type != ksparser.KS_SCRIPT_RUN: + continue + scripts.append(s) + return scripts def add_repo(ks, repostr): args = repostr.split() repoobj = ks.handler.repo.parse(args[1:]) diff --git a/tests/test_configmgr.py b/tests/test_configmgr.py index 08c3744..08c3744 100755..100644 --- a/tests/test_configmgr.py +++ b/tests/test_configmgr.py |