Setup environment to perform signing script
[tools/mic.git] / mic / imager / baseimager.py
index c02e74d..843fdd5 100755 (executable)
@@ -90,6 +90,7 @@ class BaseImageCreator(object):
         self.pack_to = None
         self.repourl = {}
         self.multiple_partitions = False
+        self._imgdir = None
 
         # If the kernel is save to the destdir when copy_kernel cmd is called.
         self._need_copy_kernel = False
@@ -1154,6 +1155,35 @@ class BaseImageCreator(object):
     def postinstall(self):
         self.copy_attachment()
 
+    def _get_sign_scripts_env(self):
+        """Return an environment dict for %post-umount scripts.
+
+        This is the hook where subclasses may specify some environment
+        variables for %post-umount scripts by return a dict containing the
+        desired environment.
+        """
+
+        env = {}
+
+        # Directory path of images
+        if self._imgdir:
+            env['IMG_DIR_PATH'] = str(self._imgdir)
+
+        imgfiles = []
+        imgpaths = []
+        for item in self._instloops:
+            imgfiles.append(item['name'])
+            if self._imgdir:
+                imgpaths.append(os.path.join(self._imgdir, item['name']))
+
+        # Images file name
+        env['IMG_FILES'] = ' '.join(imgfiles)
+
+        # Absolute path of images
+        env['IMG_PATHS'] = ' '.join(imgpaths)
+
+        return env
+
     def run_sign_scripts(self):
         if kickstart.get_sign_scripts(self.ks)==[]:
             return
@@ -1171,6 +1201,7 @@ class BaseImageCreator(object):
                 os.write(fd, 'exit 0\n')
             os.close(fd)
             os.chmod(path, 0700)
+
             for item in os.listdir(self._imgdir):
                 sub = os.path.splitext(item)[1]
                 if sub == ".img":
@@ -1178,9 +1209,14 @@ class BaseImageCreator(object):
                                 os.path.join(self._instroot + "/tmp", item))
             oldoutdir = os.getcwd()
             os.chdir(self._instroot + "/tmp")
+
+            env = self._get_sign_scripts_env()
+            #*.img files are moved to self._instroot + "/tmp" directory in running runscripts
+            env['IMG_PATHS'] = env['IMG_PATHS'].replace(self._imgdir,self._instroot + "/tmp")
             try:
                 try:
                     p = subprocess.Popen([s.interp, path],
+                                       env = env,
                                        stdout = subprocess.PIPE,
                                        stderr = subprocess.STDOUT)
                     while p.poll() == None:
@@ -1197,6 +1233,7 @@ class BaseImageCreator(object):
                 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 post scripts ...")
         if os.path.exists(self._instroot + "/tmp"):