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(":")
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
@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
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:
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:
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:
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: