summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoonKyu Park <sk7.park@samsung.com>2017-11-08 15:58:24 +0900
committeryuhuan.yang <yuhuan.yang@samsung.com>2018-01-30 10:48:45 +0800
commit486cea5abfb762d02f8c06c0311ecc7dacd24756 (patch)
treec41bbf856664da63f099d9c61cf401508a942752
parent925cece6ba20bcf90724b53815953725b6cae2a2 (diff)
downloadmic-486cea5abfb762d02f8c06c0311ecc7dacd24756.tar.gz
mic-486cea5abfb762d02f8c06c0311ecc7dacd24756.tar.bz2
mic-486cea5abfb762d02f8c06c0311ecc7dacd24756.zip
Setup environment to perform signing script
Change-Id: I8b7a5916a6db8863a03b24d297a479e0d990adad
-rw-r--r--mic/bootstrap.py34
-rwxr-xr-xmic/imager/baseimager.py37
2 files changed, 71 insertions, 0 deletions
diff --git a/mic/bootstrap.py b/mic/bootstrap.py
index f911414..b51b79a 100644
--- a/mic/bootstrap.py
+++ b/mic/bootstrap.py
@@ -264,6 +264,34 @@ class Bootstrap(object):
except:
pass
+ def sync_hostfile(rootdir):
+ try:
+ # sync host info to bootstrap
+ if os.path.exists(rootdir + "/etc/hosts"):
+ os.unlink(rootdir + "/etc/hosts")
+ shutil.copyfile("/etc/hosts", rootdir + "/etc/hosts")
+ except:
+ pass
+
+ def sync_signfile(rootdir,homedir):
+ if os.path.exists(homedir + "/.sign"):
+ signfile = rootdir + homedir + "/.sign"
+ try:
+ # sync sign info to bootstrap
+ if os.path.exists(signfile):
+ if os.path.isdir(signfile):
+ shutil.rmtree(signfile)
+ else:
+ os.unlink(signfile)
+ try:
+ shutil.copytree(homedir + "/.sign", signfile)
+ except OSError as exc:
+ if exc.errno == errno.ENOTDIR:
+ shutil.copy(homedir + "/.sign", signfile)
+ else: raise
+ except:
+ pass
+
if not rootdir:
rootdir = self.rootdir
@@ -282,6 +310,12 @@ class Bootstrap(object):
gloablmounts = setup_chrootenv(rootdir, bindmounts)
sync_timesetting(rootdir)
sync_passwdfile(rootdir)
+ sync_hostfile(rootdir)
+ env['SUDO_USER'] = 'root'
+ if 'SUDO_USER' in env:
+ sync_signfile(rootdir, os.path.expanduser('~' + env['SUDO_USER']))
+ else:
+ sync_signfile(rootdir, os.path.expanduser('~'))
retcode = subprocess.call(cmd, preexec_fn=mychroot, env=env, shell=shell)
except (OSError, IOError):
# add additional information to original exception
diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py
index d9bc2cf..c1bb418 100755
--- a/mic/imager/baseimager.py
+++ b/mic/imager/baseimager.py
@@ -89,6 +89,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
@@ -1198,6 +1199,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
@@ -1215,6 +1245,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":
@@ -1222,9 +1253,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:
@@ -1241,6 +1277,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"):