summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mic/imager/baseimager.py17
-rw-r--r--mic/imager/livecd.py70
-rw-r--r--mic/imager/liveusb.py60
-rw-r--r--mic/utils/misc.py180
-rw-r--r--plugins/imager/livecd_plugin.py95
-rw-r--r--plugins/imager/liveusb_plugin.py103
-rwxr-xr-xtools/mic4
7 files changed, 112 insertions, 417 deletions
diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py
index 5200d28..2b6c7d2 100644
--- a/mic/imager/baseimager.py
+++ b/mic/imager/baseimager.py
@@ -84,7 +84,7 @@ class BaseImageCreator(object):
self.tmpdir = "/var/tmp"
self.cachedir = "/var/cache"
self.destdir = "."
-
+
self.__builddir = None
self.__bindmounts = []
@@ -404,6 +404,18 @@ class BaseImageCreator(object):
RPM's n-v-r in the case of e.g. xen)
"""
+ def get_kernel_versions(self, instroot):
+ ret = {}
+ versions = set()
+ files = glob.glob(instroot + "/boot/vmlinuz-*")
+ for file in files:
+ version = os.path.basename(file)[8:]
+ if version is None:
+ continue
+ versions.add(version)
+ ret["kernel"] = list(versions)
+ return ret
+
def get_version(header):
version = None
for f in header['filenames']:
@@ -411,6 +423,9 @@ class BaseImageCreator(object):
version = f[14:]
return version
+ if self.ks is None:
+ return get_kernel_versions(self._instroot)
+
ts = rpm.TransactionSet(self._instroot)
ret = {}
diff --git a/mic/imager/livecd.py b/mic/imager/livecd.py
index bf846cf..59239ae 100644
--- a/mic/imager/livecd.py
+++ b/mic/imager/livecd.py
@@ -115,9 +115,9 @@ class LiveImageCreatorBase(LoopImageCreator):
"""
if self.ks is None:
r = "ro liveimg quiet"
- if os.path.exists(instroot + "/usr/bin/rhgb"):
+ if os.path.exists(self._instroot + "/usr/bin/rhgb"):
r += " rhgb"
- if os.path.exists(instroot + "/usr/bin/plymouth"):
+ if os.path.exists(self._instroot + "/usr/bin/plymouth"):
r += " rhgb"
return r
r = kickstart.get_kernel_args(self.ks)
@@ -152,72 +152,6 @@ class LiveImageCreatorBase(LoopImageCreator):
return False
- def _uncompress_squashfs(self, squashfsimg, outdir):
- """Uncompress file system from squshfs image"""
- unsquashfs = fs_related.find_binary_path("unsquashfs")
- args = [unsquashfs, "-d", outdir, squashfsimg ]
- rc = subprocess.call(args)
- if (rc != 0):
- raise CreatorError("Failed to uncompress %s." % squashfsimg)
- #
- # Actual implementation
- #
- def _base_on(self, base_on):
- """Support Image Convertor"""
- if self.actasconvertor:
- if os.path.exists(base_on) and not os.path.isfile(base_on):
- ddcmd = fs_related.find_binary_path("dd")
- args = [ ddcmd, "if=%s" % base_on, "of=%s" % self._image ]
- print "dd %s -> %s" % (base_on, self._image)
- rc = subprocess.call(args)
- if rc != 0:
- raise CreatorError("Failed to dd from %s to %s" % (base_on, self._image))
- self._set_image_size(misc.get_file_size(self._image) * 1024L * 1024L)
- if os.path.isfile(base_on):
- print "Copying file system..."
- shutil.copyfile(base_on, self._image)
- self._set_image_size(get_file_size(self._image) * 1024L * 1024L)
- return
-
- #helper function to extract ext3 file system from a live CD ISO
- isoloop = fs_related.DiskMount(fs_related.LoopbackDisk(base_on, 0), self._mkdtemp())
-
- try:
- isoloop.mount()
- except MountError, e:
- raise CreatorError("Failed to loopback mount '%s' : %s" %
- (base_on, e))
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(isoloop.mountdir + "/squashfs.img"):
- squashimg = isoloop.mountdir + "/squashfs.img"
- else:
- squashimg = isoloop.mountdir + "/LiveOS/squashfs.img"
-
- tmpoutdir = self._mkdtemp()
- # unsquashfs requires outdir mustn't exist
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- self._uncompress_squashfs(squashimg, tmpoutdir)
-
- try:
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(tmpoutdir + "/os.img"):
- os_image = tmpoutdir + "/os.img"
- else:
- os_image = tmpoutdir + "/LiveOS/ext3fs.img"
-
- if not os.path.exists(os_image):
- raise CreatorError("'%s' is not a valid live CD ISO : neither "
- "LiveOS/ext3fs.img nor os.img exist" %
- base_on)
-
- print "Copying file system..."
- shutil.copyfile(os_image, self._image)
- self._set_image_size(get_file_size(self._image) * 1024L * 1024L)
- finally:
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- isoloop.cleanup()
-
def _mount_instroot(self, base_on = None):
LoopImageCreator._mount_instroot(self, base_on)
self.__write_initrd_conf(self._instroot + "/etc/sysconfig/mkinitrd")
diff --git a/mic/imager/liveusb.py b/mic/imager/liveusb.py
index eadc4dd..b16f969 100644
--- a/mic/imager/liveusb.py
+++ b/mic/imager/liveusb.py
@@ -263,63 +263,3 @@ class LiveUSBImageCreator(LiveCDImageCreator):
shutil.rmtree(isodir, ignore_errors = True)
self._set_isodir(None)
- def _base_on(self, base_on):
- """Support Image Convertor"""
- if self.actasconvertor:
- if os.path.exists(base_on) and not os.path.isfile(base_on):
- ddcmd = fs_related.find_binary_path("dd")
- args = [ ddcmd, "if=%s" % base_on, "of=%s" % self._image ]
- print "dd %s -> %s" % (base_on, self._image)
- rc = subprocess.call(args)
- if rc != 0:
- raise CreatorError("Failed to dd from %s to %s" % (base_on, self._image))
- self._set_image_size(misc.get_file_size(self._image) * 1024L * 1024L)
- if os.path.isfile(base_on):
- print "Copying file system..."
- shutil.copyfile(base_on, self._image)
- self._set_image_size(misc.get_file_size(self._image) * 1024L * 1024L)
- return
-
- #helper function to extract ext3 file system from a live usb image
- usbimgsize = misc.get_file_size(base_on) * 1024L * 1024L
- disk = fs_related.SparseLoopbackDisk(base_on, usbimgsize)
- usbimgmnt = self._mkdtemp("usbimgmnt-")
- usbloop = PartitionedMount({'/dev/sdb':disk}, usbimgmnt, skipformat = True)
- usbimg_fstype = "vfat"
- usbloop.add_partition(usbimgsize/1024/1024, "/dev/sdb", "/", usbimg_fstype, boot=False)
- try:
- usbloop.mount()
- except MountError, e:
- usbloop.cleanup()
- raise CreatorError("Failed to loopback mount '%s' : %s" %
- (base_on, e))
-
- #legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(usbimgmnt + "/squashfs.img"):
- squashimg = usbimgmnt + "/squashfs.img"
- else:
- squashimg = usbimgmnt + "/LiveOS/squashfs.img"
-
- tmpoutdir = self._mkdtemp()
- #unsquashfs requires outdir mustn't exist
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- self._uncompress_squashfs(squashimg, tmpoutdir)
-
- try:
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(tmpoutdir + "/os.img"):
- os_image = tmpoutdir + "/os.img"
- else:
- os_image = tmpoutdir + "/LiveOS/ext3fs.img"
-
- if not os.path.exists(os_image):
- raise CreatorError("'%s' is not a valid live CD ISO : neither "
- "LiveOS/ext3fs.img nor os.img exist" %
- base_on)
-
- print "Copying file system..."
- shutil.copyfile(os_image, self._image)
- self._set_image_size(misc.get_file_size(self._image) * 1024L * 1024L)
- finally:
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- usbloop.cleanup()
diff --git a/mic/utils/misc.py b/mic/utils/misc.py
index fdff0b6..77905ac 100644
--- a/mic/utils/misc.py
+++ b/mic/utils/misc.py
@@ -1138,183 +1138,3 @@ def SrcpkgsDownload(pkgs, repometadata, instroot, cachedir):
print "%d source packages gotten from cache" %cached_count
return src_pkgs
-
-def add_optparser(arg):
- def decorate(f):
- if not hasattr(f, "optparser"):
- f.optparser = arg
- return f
- return decorate
-
-def setup_chrootenv(chrootdir, bindmounts = None):##move to mic/utils/misc
- global chroot_lockfd, chroot_lock
- def get_bind_mounts(chrootdir, bindmounts):
- chrootmounts = []
- if bindmounts in ("", None):
- bindmounts = ""
- mounts = bindmounts.split(";")
- for mount in mounts:
- if mount == "":
- continue
- srcdst = mount.split(":")
- srcdst[0] = os.path.abspath(os.path.expanduser(srcdst[0]))
- if len(srcdst) == 1:
- srcdst.append("none")
- if not os.path.isdir(srcdst[0]):
- continue
- if srcdst[0] in ("/proc", "/proc/sys/fs/binfmt_misc", "/", "/sys", "/dev", "/dev/pts", "/dev/shm", "/var/lib/dbus", "/var/run/dbus", "/var/lock"):
- pwarning("%s will be mounted by default." % srcdst[0])
- continue
- if srcdst[1] == "" or srcdst[1] == "none":
- srcdst[1] = None
- else:
- srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[1]))
- if os.path.isdir(chrootdir + "/" + srcdst[1]):
- pwarning("%s has existed in %s , skip it." % (srcdst[1], chrootdir))
- continue
- chrootmounts.append(fs_related.BindChrootMount(srcdst[0], chrootdir, srcdst[1]))
-
- """Default bind mounts"""
- chrootmounts.append(fs_related.BindChrootMount("/proc", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/proc/sys/fs/binfmt_misc", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/sys", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/dev", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/dev/pts", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/dev/shm", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/var/lib/dbus", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/var/run/dbus", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/var/lock", chrootdir, None))
- chrootmounts.append(fs_related.BindChrootMount("/", chrootdir, "/parentroot", "ro"))
- for kernel in os.listdir("/lib/modules"):
- chrootmounts.append(fs_related.BindChrootMount("/lib/modules/" + kernel, chrootdir, None, "ro"))
-
- return chrootmounts
-
- def bind_mount(chrootmounts):
- for b in chrootmounts:
- print "bind_mount: %s -> %s" % (b.src, b.dest)
- b.mount()
-
- def setup_resolv(chrootdir):
- shutil.copyfile("/etc/resolv.conf", chrootdir + "/etc/resolv.conf")
-
- globalmounts = get_bind_mounts(chrootdir, bindmounts)
- bind_mount(globalmounts)
- setup_resolv(chrootdir)
- mtab = "/etc/mtab"
- dstmtab = chrootdir + mtab
- if not os.path.islink(dstmtab):
- shutil.copyfile(mtab, dstmtab)
- chroot_lock = os.path.join(chrootdir, ".chroot.lock")
- chroot_lockfd = open(chroot_lock, "w")
- return globalmounts
-
-def cleanup_chrootenv(chrootdir, bindmounts = None, globalmounts = []):
- global chroot_lockfd, chroot_lock
- def bind_unmount(chrootmounts):
- chrootmounts.reverse()
- for b in chrootmounts:
- print "bind_unmount: %s -> %s" % (b.src, b.dest)
- b.unmount()
-
- def cleanup_resolv(chrootdir):
- fd = open(chrootdir + "/etc/resolv.conf", "w")
- fd.truncate(0)
- fd.close()
-
- def kill_processes(chrootdir):
- for file in glob.glob("/proc/*/root"):
- try:
- if os.readlink(file) == chrootdir:
- pid = int(file.split("/")[2])
- os.kill(pid, 9)
- except:
- pass
-
- def cleanup_mountdir(chrootdir, bindmounts):
- if bindmounts == "" or bindmounts == None:
- return
- chrootmounts = []
- mounts = bindmounts.split(";")
- for mount in mounts:
- if mount == "":
- continue
- srcdst = mount.split(":")
- if len(srcdst) == 1:
- srcdst.append("none")
- if srcdst[1] == "" or srcdst[1] == "none":
- srcdst[1] = srcdst[0]
- srcdst[1] = os.path.abspath(os.path.expanduser(srcdst[1]))
- tmpdir = chrootdir + "/" + srcdst[1]
- if os.path.isdir(tmpdir):
- if len(os.listdir(tmpdir)) == 0:
- shutil.rmtree(tmpdir, ignore_errors = True)
- else:
- print "Warning: dir %s isn't empty." % tmpdir
-
- chroot_lockfd.close()
- bind_unmount(globalmounts)
- if not fs_releate.my_fuser(chroot_lock):
- tmpdir = chrootdir + "/parentroot"
- if len(os.listdir(tmpdir)) == 0:
- shutil.rmtree(tmpdir, ignore_errors = True)
- cleanup_resolv(chrootdir)
- if os.path.exists(chrootdir + "/etc/mtab"):
- os.unlink(chrootdir + "/etc/mtab")
- kill_processes(chrootdir)
- cleanup_mountdir(chrootdir, bindmounts)
-
-def chroot(chrootdir, bindmounts = None, execute = "/bin/bash"):
- def mychroot():
- os.chroot(chrootdir)
- os.chdir("/")
-
- dev_null = os.open("/dev/null", os.O_WRONLY)
- files_to_check = ["/bin/bash", "/sbin/init"]
-
- architecture_found = False
-
- """ Register statically-linked qemu-arm if it is an ARM fs """
- qemu_emulator = None
-
- for ftc in files_to_check:
- ftc = "%s/%s" % (chrootdir,ftc)
-
- # Return code of 'file' is "almost always" 0 based on some man pages
- # so we need to check the file existance first.
- if not os.path.exists(ftc):
- continue
-
- filecmd = find_binary_path("file")
- initp1 = subprocess.Popen([filecmd, ftc], stdout=subprocess.PIPE, stderr=dev_null)
- fileOutput = initp1.communicate()[0].strip().split("\n")
-
- for i in range(len(fileOutput)):
- if fileOutput[i].find("ARM") > 0:
- qemu_emulator = setup_qemu_emulator(chrootdir, "arm")
- architecture_found = True
- break
- if fileOutput[i].find("Intel") > 0:
- architecture_found = True
- break
-
- if architecture_found:
- break
-
- os.close(dev_null)
- if not architecture_found:
- raise errors.CreatorError("Failed to get architecture from any of the following files %s from chroot." % files_to_check)
-
- try:
- print "Launching shell. Exit to continue."
- print "----------------------------------"
- globalmounts = setup_chrootenv(chrootdir, bindmounts)
- args = shlex.split(execute)
- subprocess.call(args, preexec_fn = mychroot)
- except OSError, (err, msg):
- raise errors.CreatorError("Failed to chroot: %s" % msg)
- finally:
- cleanup_chrootenv(chrootdir, bindmounts, globalmounts)
- if qemu_emulator:
- os.unlink(chrootdir + qemu_emulator)
-
diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py
index 3a63c4d..d621e08 100644
--- a/plugins/imager/livecd_plugin.py
+++ b/plugins/imager/livecd_plugin.py
@@ -66,39 +66,8 @@ class LiveCDPlugin(ImagerPlugin):
@classmethod
def do_chroot(cls, target):
- img = target
- imgmnt = misc.mkdtemp()
- imgloop = fs_related.DiskMount(fs_related.LoopbackDisk(img, 0), imgmnt)
- try:
- imgloop.mount()
- except MountError, e:
- imgloop.cleanup()
- raise CreatorError("Failed to loopback mount '%s' : %s" %(img, e))
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(imgmnt + "/squashfs.img"):
- squashimg = imgmnt + "/squashfs.img"
- else:
- squashimg = imgmnt + "/LiveOS/squashfs.img"
-
- tmpoutdir = misc.mkdtemp()
- # unsquashfs requires outdir mustn't exist
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- misc.uncompress_squashfs(squashimg, tmpoutdir)
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(tmpoutdir + "/os.img"):
- os_image = tmpoutdir + "/os.img"
- else:
- os_image = tmpoutdir + "/LiveOS/ext3fs.img"
-
- if not os.path.exists(os_image):
- imgloop.cleanup()
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- shutil.rmtree(imgmnt, ignore_errors = True)
- raise CreatorError("'%s' is not a valid live CD ISO : neither "
- "LiveOS/ext3fs.img nor os.img exist" %img)
-
+ os_image = cls.do_unpack(target)
+ os_image_dir = os.path.dirname(os_image)
#unpack image to target dir
imgsize = misc.get_file_size(os_image) * 1024L * 1024L
extmnt = misc.mkdtemp()
@@ -112,26 +81,22 @@ class LiveCDPlugin(ImagerPlugin):
extloop = MyDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
extmnt,
tfstype,
- 4096,
+ 4096,
tlabel)
try:
extloop.mount()
except MountError, e:
extloop.cleanup()
shutil.rmtree(extmnt, ignore_errors = True)
- imgloop.cleanup()
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- shutil.rmtree(imgmnt, ignore_errors = True)
+ shutil.rmtree(os_image_dir, ignore_errors = True)
raise CreatorError("Failed to loopback mount '%s' : %s" %(os_image, e))
try:
chroot.chroot(extmnt, None, "/bin/env HOME=/root /bin/bash")
except:
raise CreatorError("Failed to chroot to %s." %img)
finally:
- imgloop.cleanup()
- shutil.rmtree(imgmnt, ignore_errors = True)
- chroot.cleanup_after_chroot("img",extloop,tmpoutdir,extmnt)
-
+ chroot.cleanup_after_chroot("img", extloop, os_image_dir, extmnt)
+
@classmethod
def do_pack(cls, base_on):
def __mkinitrd(instance):
@@ -166,14 +131,44 @@ class LiveCDPlugin(ImagerPlugin):
@classmethod
def do_unpack(cls, srcimg):
- convertor = livecd.LiveCDImageCreator()
- srcimgsize = (misc.get_file_size(srcimg)) * 1024L * 1024L
- convertor._srcfmt = 'livecd'
- convertor._set_fstype("ext3")
- convertor._set_image_size(srcimgsize)
- convertor.mount(srcimg, None)
- image = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "meego.img")
- shutil.copyfile(convertor._image, image)
- return image
+ img = srcimg
+ imgmnt = misc.mkdtemp()
+ imgloop = fs_related.DiskMount(fs_related.LoopbackDisk(img, 0), imgmnt)
+ try:
+ imgloop.mount()
+ except MountError, e:
+ imgloop.cleanup()
+ raise CreatorError("Failed to loopback mount '%s' : %s" %(img, e))
+
+ # legacy LiveOS filesystem layout support, remove for F9 or F10
+ if os.path.exists(imgmnt + "/squashfs.img"):
+ squashimg = imgmnt + "/squashfs.img"
+ else:
+ squashimg = imgmnt + "/LiveOS/squashfs.img"
+
+ tmpoutdir = misc.mkdtemp()
+ # unsquashfs requires outdir mustn't exist
+ shutil.rmtree(tmpoutdir, ignore_errors = True)
+ misc.uncompress_squashfs(squashimg, tmpoutdir)
+
+ try:
+ # legacy LiveOS filesystem layout support, remove for F9 or F10
+ if os.path.exists(tmpoutdir + "/os.img"):
+ os_image = tmpoutdir + "/os.img"
+ else:
+ os_image = tmpoutdir + "/LiveOS/ext3fs.img"
+
+ if not os.path.exists(os_image):
+ raise CreatorError("'%s' is not a valid live CD ISO : neither "
+ "LiveOS/ext3fs.img nor os.img exist" %img)
+
+ rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "meego.img")
+ shutil.copyfile(os_image, rtimage)
+ finally:
+ imgloop.cleanup()
+ shutil.rmtree(tmpoutdir, ignore_errors = True)
+ shutil.rmtree(imgmnt, ignore_errors = True)
+
+ return rtimage
mic_plugin = ["livecd", LiveCDPlugin]
diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py
index 2162202..4308f86 100644
--- a/plugins/imager/liveusb_plugin.py
+++ b/plugins/imager/liveusb_plugin.py
@@ -43,7 +43,7 @@ class LiveUSBPlugin(ImagerPlugin):
for (key, pcls) in plgmgr.getBackendPlugins():
if key == creatoropts['pkgmgr']:
pkgmgr = pcls
-
+
creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr)
try:
creator.check_depend_tools()
@@ -63,44 +63,10 @@ class LiveUSBPlugin(ImagerPlugin):
print "Finished."
return 0
- @classmethod
+ @classmethod
def do_chroot(cls, target):
- img = target
- imgsize = misc.get_file_size(img) * 1024L * 1024L
- imgmnt = misc.mkdtemp()
- disk = fs_related.SparseLoopbackDisk(img, imgsize)
- imgloop = PartitionedMount({'/dev/sdb':disk}, imgmnt, skipformat = True)
- imgloop.add_partition(imgsize/1024/1024, "/dev/sdb", "/", "vfat", boot=False)
- try:
- imgloop.mount()
- except MountError, e:
- imgloop.cleanup()
- raise CreatorError("Failed to loopback mount '%s' : %s" %(img, e))
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(imgmnt + "/squashfs.img"):
- squashimg = imgmnt + "/squashfs.img"
- else:
- squashimg = imgmnt + "/LiveOS/squashfs.img"
-
- tmpoutdir = misc.mkdtemp()
- # unsquashfs requires outdir mustn't exist
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- misc.uncompress_squashfs(squashimg, tmpoutdir)
-
- # legacy LiveOS filesystem layout support, remove for F9 or F10
- if os.path.exists(tmpoutdir + "/os.img"):
- os_image = tmpoutdir + "/os.img"
- else:
- os_image = tmpoutdir + "/LiveOS/ext3fs.img"
-
- if not os.path.exists(os_image):
- imgloop.cleanup()
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- shutil.rmtree(imgmnt, ignore_errors = True)
- raise CreatorError("'%s' is not a valid live CD ISO : neither "
- "LiveOS/ext3fs.img nor os.img exist" %img)
-
+ os_image = cls.do_unpack(target)
+ os_image_dir = os.path.dirname(os_image)
#unpack image to target dir
imgsize = misc.get_file_size(os_image) * 1024L * 1024L
extmnt = misc.mkdtemp()
@@ -114,26 +80,21 @@ class LiveUSBPlugin(ImagerPlugin):
extloop = MyDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize),
extmnt,
tfstype,
- 4096,
+ 4096,
tlabel)
try:
extloop.mount()
except MountError, e:
extloop.cleanup()
shutil.rmtree(extmnt, ignore_errors = True)
- imgloop.cleanup()
- shutil.rmtree(tmpoutdir, ignore_errors = True)
- shutil.rmtree(imgmnt, ignore_errors = True)
raise CreatorError("Failed to loopback mount '%s' : %s" %(os_image, e))
try:
chroot.chroot(extmnt, None, "/bin/env HOME=/root /bin/bash")
except:
raise CreatorError("Failed to chroot to %s." %img)
finally:
- imgloop.cleanup()
- shutil.rmtree(imgmnt, ignore_errors = True)
- chroot.cleanup_after_chroot("img", extloop, tmpoutdir, extmnt)
-
+ chroot.cleanup_after_chroot("img", extloop, os_image_dir, extmnt)
+
@classmethod
def do_pack(cls, base_on):
def __mkinitrd(instance):
@@ -169,16 +130,46 @@ class LiveUSBPlugin(ImagerPlugin):
@classmethod
def do_unpack(cls, srcimg):
- convertor = liveusb.LiveUSBImageCreator()
- srcimgsize = (misc.get_file_size(srcimg)) * 1024L * 1024L
- convertor._srcfmt = 'livecd'
- convertor._set_fstype("ext3")
- convertor._set_image_size(srcimgsize)
- convertor.mount(srcimg, None)
+ img = srcimg
+ imgsize = misc.get_file_size(img) * 1024L * 1024L
+ imgmnt = misc.mkdtemp()
+ disk = fs_related.SparseLoopbackDisk(img, imgsize)
+ imgloop = PartitionedMount({'/dev/sdb':disk}, imgmnt, skipformat = True)
+ imgloop.add_partition(imgsize/1024/1024, "/dev/sdb", "/", "vfat", boot=False)
+ try:
+ imgloop.mount()
+ except MountError, e:
+ imgloop.cleanup()
+ raise CreatorError("Failed to loopback mount '%s' : %s" %(img, e))
- image = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "meego.img")
- shutil.copyfile(convertor._image, image)
- return image
+ # legacy LiveOS filesystem layout support, remove for F9 or F10
+ if os.path.exists(imgmnt + "/squashfs.img"):
+ squashimg = imgmnt + "/squashfs.img"
+ else:
+ squashimg = imgmnt + "/LiveOS/squashfs.img"
-mic_plugin = ["liveusb", LiveUSBPlugin]
+ tmpoutdir = misc.mkdtemp()
+ # unsquashfs requires outdir mustn't exist
+ shutil.rmtree(tmpoutdir, ignore_errors = True)
+ misc.uncompress_squashfs(squashimg, tmpoutdir)
+ try:
+ # legacy LiveOS filesystem layout support, remove for F9 or F10
+ if os.path.exists(tmpoutdir + "/os.img"):
+ os_image = tmpoutdir + "/os.img"
+ else:
+ os_image = tmpoutdir + "/LiveOS/ext3fs.img"
+
+ if not os.path.exists(os_image):
+ raise CreatorError("'%s' is not a valid live CD ISO : neither "
+ "LiveOS/ext3fs.img nor os.img exist" %img)
+ rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), "meego.img")
+ shutil.copyfile(os_image, rtimage)
+ finally:
+ imgloop.cleanup()
+ shutil.rmtree(tmpoutdir, ignore_errors = True)
+ shutil.rmtree(imgmnt, ignore_errors = True)
+
+ return rtimage
+
+mic_plugin = ["liveusb", LiveUSBPlugin]
diff --git a/tools/mic b/tools/mic
index 06ea75a..827f3c1 100755
--- a/tools/mic
+++ b/tools/mic
@@ -91,7 +91,7 @@ class Mic(cmdln.Cmdln):
destimager = icls
if (srcimager and destimager) is None:
- raise CreatorError("Can't convert from %s to %s" %(srcformat, destformat))
+ raise errors.CreatorError("Can't convert from %s to %s" %(srcformat, destformat))
else:
base_on = srcimager.do_unpack(srcimg)
destimager.do_pack(base_on)
@@ -141,7 +141,7 @@ class Mic(cmdln.Cmdln):
break
if not chrootclass:
- raise CreatorError("Don't support image type: %s" % imagetype)
+ raise errors.CreatorError("Don't support image type: %s" % imagetype)
chrootclass.do_chroot(targetimage)