find path of 'env' for chroot automatically
authorGui Chen <gui.chen@intel.com>
Tue, 10 Jul 2012 10:34:19 +0000 (18:34 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 10 Jul 2012 10:34:19 +0000 (18:34 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/utils/fs_related.py
plugins/imager/fs_plugin.py
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index 741e937f779b6997544ea25be9cdbd93d7ccbea1..d817d98a30121ab64ff87a95f7dc64db14637e59 100644 (file)
@@ -29,6 +29,19 @@ from errors import *
 from mic import msger
 import runner
 
+def find_binary_inchroot(binary, chroot):
+    paths = ["/usr/sbin",
+             "/usr/bin",
+             "/sbin",
+             "/bin"
+            ]
+
+    for path in paths:
+        bin_path = "%s/%s" % (path, binary)
+        if os.path.exists("%s/%s" % (chroot, bin_path)):
+            return bin_path
+    return None
+
 def find_binary_path(binary):
     if os.environ.has_key("PATH"):
         paths = os.environ["PATH"].split(":")
index 1425516f9811e9fb47fcb48544e9ec9f3a1a319f..ebfd7a2e3c99a02867a6656848c5b5c05e1dda78 100644 (file)
@@ -19,7 +19,7 @@ import os
 import sys
 
 from mic import chroot, msger, rt_util
-from mic.utils import cmdln, misc, errors
+from mic.utils import cmdln, misc, errors, fs_related
 from mic.imager import fs
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
@@ -128,7 +128,12 @@ class FsPlugin(ImagerPlugin):
     @classmethod
     def do_chroot(self, target):#chroot.py parse opts&args
             try:
-                chroot.chroot(target, None, "/bin/env HOME=/root /bin/bash")
+                envcmd = fs_related.find_binary_inchroot("env", target)
+                if envcmd:
+                    cmdline = "%s HOME=/root /bin/bash" % envcmd
+                else:
+                    cmdline = "/bin/bash"
+                chroot.chroot(target, None, cmdline)
             finally:
                 chroot.cleanup_after_chroot("dir", None, None, None)
                 return 1
index 762e133f342dff6e0ff9b2bdfbc8cc685824e30a..01d434941743055d43b8b76bf67fbb923bf2a9a6 100644 (file)
@@ -150,7 +150,12 @@ class LiveCDPlugin(ImagerPlugin):
             raise
 
         try:
-            chroot.chroot(extmnt, None,  "/bin/env HOME=/root /bin/bash")
+            envcmd = fs_related.find_binary_inchroot("env", extmnt)
+            if envcmd:
+                cmdline = "%s HOME=/root /bin/bash" % envcmd
+            else:
+                cmdline = "/bin/bash"
+            chroot.chroot(extmnt, None, cmdline)
         except:
             raise errors.CreatorError("Failed to chroot to %s." %target)
         finally:
index 000870fceca3eb8a25e0b152cf1e259d302d10ba..86d1e4414b9cee0ba99bb942a258047e1702f9ee 100644 (file)
@@ -151,7 +151,12 @@ class LiveUSBPlugin(ImagerPlugin):
             raise
 
         try:
-            chroot.chroot(extmnt, None,  "/bin/env HOME=/root /bin/bash")
+            envcmd = fs_related.find_binary_inchroot("env", extmnt)
+            if envcmd:
+                cmdline = "%s HOME=/root /bin/bash" % envcmd
+            else:
+                cmdline = "/bin/bash"
+            chroot.chroot(extmnt, None, cmdline) 
         except:
             raise errors.CreatorError("Failed to chroot to %s." %target)
         finally:
index 5814cb5cb8c159a20f362c3d7514a6715a044f37..34e45634f48d591477d5391df8913eed2d3bade4 100644 (file)
@@ -228,7 +228,12 @@ class LoopPlugin(ImagerPlugin):
             raise
 
         try:
-            chroot.chroot(extmnt, None,  "/usr/bin/env HOME=/root /bin/bash")
+            envcmd = fs_related.find_binary_inchroot("env", extmnt)
+            if envcmd:
+                cmdline = "%s HOME=/root /bin/bash" % envcmd
+            else:
+                cmdline = "/bin/bash"
+            chroot.chroot(extmnt, None, cmdline)
         except:
             raise errors.CreatorError("Failed to chroot to %s." % img)
         finally:
index 6f918120655da2ed727e0de69db77be1ee99e4e0..c8385a49517febcbacd3b97ef69f2685a2bdfaa3 100644 (file)
@@ -201,7 +201,12 @@ class RawPlugin(ImagerPlugin):
             raise
 
         try:
-            chroot.chroot(imgmnt, None,  "/bin/env HOME=/root /bin/bash")
+            envcmd = fs_related.find_binary_inchroot("env", imgmnt)
+            if envcmd:
+                cmdline = "%s HOME=/root /bin/bash" % envcmd
+            else:
+                cmdline = "/bin/bash"
+            chroot.chroot(imgmnt, None, cmdline) 
         except:
             raise errors.CreatorError("Failed to chroot to %s." %img)
         finally: