diff options
author | yanqingx.li <yanqingx.li@intel.com> | 2012-09-26 14:47:55 +0800 |
---|---|---|
committer | Gui Chen <gui.chen@intel.com> | 2012-09-26 15:08:22 +0800 |
commit | fee503b47d468cbc7c539910796269b65cbff750 (patch) | |
tree | ae593364b7fe4f4e064e3d526009ace86f60accf /plugins | |
parent | ab277036676eb8cc77d21ce1b9366da5ee8c67d2 (diff) | |
download | mic-fee503b47d468cbc7c539910796269b65cbff750.tar.gz mic-fee503b47d468cbc7c539910796269b65cbff750.tar.bz2 mic-fee503b47d468cbc7c539910796269b65cbff750.zip |
support running specified command for mic chroot
usage: mic chroot CHROOT [COMMAND [ARGS]]
this feature enables running command with non-interactive
Change-Id: Ic7e74a00c83e3cef5684c2ee94a755389ba4276d
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/imager/fs_plugin.py | 10 | ||||
-rw-r--r-- | plugins/imager/livecd_plugin.py | 10 | ||||
-rw-r--r-- | plugins/imager/liveusb_plugin.py | 10 | ||||
-rw-r--r-- | plugins/imager/loop_plugin.py | 20 | ||||
-rw-r--r-- | plugins/imager/raw_plugin.py | 10 |
5 files changed, 37 insertions, 23 deletions
diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index e2ee82b..70985b7 100644 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -126,13 +126,15 @@ class FsPlugin(ImagerPlugin): return 0 @classmethod - def do_chroot(self, target):#chroot.py parse opts&args + def do_chroot(self, target, cmd):#chroot.py parse opts&args try: - envcmd = fs_related.find_binary_inchroot("env", target) - if envcmd: - cmdline = "%s HOME=/root /bin/bash" % envcmd + if len(cmd) != 0: + cmdline = ' '.join(cmd) else: cmdline = "/bin/bash" + envcmd = fs_related.find_binary_inchroot("env", target) + if envcmd: + cmdline = "%s HOME=/root %s" % (envcmd, cmdline) chroot.chroot(target, None, cmdline) finally: chroot.cleanup_after_chroot("dir", None, None, None) diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index 275f5c1..98b6dbb 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -118,7 +118,7 @@ class LiveCDPlugin(ImagerPlugin): return 0 @classmethod - def do_chroot(cls, target): + def do_chroot(cls, target, cmd): os_image = cls.do_unpack(target) os_image_dir = os.path.dirname(os_image) @@ -150,11 +150,13 @@ class LiveCDPlugin(ImagerPlugin): raise try: - envcmd = fs_related.find_binary_inchroot("env", extmnt) - if envcmd: - cmdline = "%s HOME=/root /bin/bash" % envcmd + if len(cmd) != 0: + cmdline = ' '.join(cmd) else: cmdline = "/bin/bash" + envcmd = fs_related.find_binary_inchroot("env", extmnt) + if envcmd: + cmdline = "%s HOME=/root %s" % (envcmd, cmdline) chroot.chroot(extmnt, None, cmdline) except: raise errors.CreatorError("Failed to chroot to %s." %target) diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index 02cfb45..e0f079a 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -119,7 +119,7 @@ class LiveUSBPlugin(ImagerPlugin): return 0 @classmethod - def do_chroot(cls, target): + def do_chroot(cls, target, cmd): os_image = cls.do_unpack(target) os_image_dir = os.path.dirname(os_image) @@ -151,11 +151,13 @@ class LiveUSBPlugin(ImagerPlugin): raise try: - envcmd = fs_related.find_binary_inchroot("env", extmnt) - if envcmd: - cmdline = "%s HOME=/root /bin/bash" % envcmd + if len(cmd) != 0: + cmdline = ' '.join(cmd) else: cmdline = "/bin/bash" + envcmd = fs_related.find_binary_inchroot("env", extmnt) + if envcmd: + cmdline = "%s HOME=/root %s" % (envcmd, cmdline) chroot.chroot(extmnt, None, cmdline) except: raise errors.CreatorError("Failed to chroot to %s." %target) diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index c1bccba..78cde65 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -131,7 +131,7 @@ class LoopPlugin(ImagerPlugin): return 0 @classmethod - def _do_chroot_tar(cls, target): + def _do_chroot_tar(cls, target, cmd): mountfp_xml = os.path.splitext(target)[0] + '.xml' if not os.path.exists(mountfp_xml): raise errors.CreatorError("No mount point file found for this tar " @@ -178,7 +178,11 @@ class LoopPlugin(ImagerPlugin): loops.append(loop) try: - chroot.chroot(mntdir, None, "/usr/bin/env HOME=/root /bin/bash") + if len(cmd) != 0: + cmdline = "/usr/bin/env HOME=/root " + ' '.join(cmd) + else: + cmdline = "/usr/bin/env HOME=/root /bin/bash" + chroot.chroot(mntdir, None, cmdline) except: raise errors.CreatorError("Failed to chroot to %s." % target) finally: @@ -188,11 +192,11 @@ class LoopPlugin(ImagerPlugin): shutil.rmtree(tmpdir, ignore_errors=True) @classmethod - def do_chroot(cls, target): + def do_chroot(cls, target, cmd): if target.endswith('.tar'): import tarfile if tarfile.is_tarfile(target): - LoopPlugin._do_chroot_tar(target) + LoopPlugin._do_chroot_tar(target, cmd) return else: raise errors.CreatorError("damaged tarball for loop images") @@ -225,11 +229,13 @@ class LoopPlugin(ImagerPlugin): raise try: - envcmd = fs_related.find_binary_inchroot("env", extmnt) - if envcmd: - cmdline = "%s HOME=/root /bin/bash" % envcmd + if len(cmd) != 0: + cmdline = ' '.join(cmd) else: cmdline = "/bin/bash" + envcmd = fs_related.find_binary_inchroot("env", extmnt) + if envcmd: + cmdline = "%s HOME=/root %s" % (envcmd, cmdline) chroot.chroot(extmnt, None, cmdline) except: raise errors.CreatorError("Failed to chroot to %s." % img) diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 3cb15ed..9b76d6f 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -125,7 +125,7 @@ class RawPlugin(ImagerPlugin): return 0 @classmethod - def do_chroot(cls, target): + def do_chroot(cls, target, cmd): img = target imgsize = misc.get_file_size(img) * 1024L * 1024L partedcmd = fs_related.find_binary_path("parted") @@ -221,11 +221,13 @@ class RawPlugin(ImagerPlugin): raise try: - envcmd = fs_related.find_binary_inchroot("env", imgmnt) - if envcmd: - cmdline = "%s HOME=/root /bin/bash" % envcmd + if len(cmd) != 0: + cmdline = ' '.join(cmd) else: cmdline = "/bin/bash" + envcmd = fs_related.find_binary_inchroot("env", imgmnt) + if envcmd: + cmdline = "%s HOME=/root %s" % (envcmd, cmdline) chroot.chroot(imgmnt, None, cmdline) except: raise errors.CreatorError("Failed to chroot to %s." %img) |