image-creator was duplicating a lot of code, while still failing to stay
in sync with livecd-creator (not providing useful options, such as
tmpdir or cachedir). Make it a link to livecd-creator and determine the
image packaging by argv[0].
---
Makefile | 2 +-
tools/image-creator | 75 --------------------------------------------------
tools/livecd-creator | 48 ++++++++++++++++++++++++++------
3 files changed, 40 insertions(+), 85 deletions(-)
delete mode 100755 tools/image-creator
diff --git a/Makefile b/Makefile
index 83880ef..be14e32 100644
--- a/Makefile
+++ b/Makefile
@@ -22,8 +22,8 @@ man:
install: man
$(INSTALL_PROGRAM) -D tools/livecd-creator $(DESTDIR)/usr/bin/livecd-creator
+ ln $(DESTDIR)/usr/bin/livecd-creator $(DESTDIR)/usr/bin/image-creator
$(INSTALL_PROGRAM) -D tools/liveimage-mount $(DESTDIR)/usr/bin/liveimage-mount
- $(INSTALL_PROGRAM) -D tools/image-creator $(DESTDIR)/usr/bin/image-creator
$(INSTALL_PROGRAM) -D tools/livecd-iso-to-disk.sh $(DESTDIR)/usr/bin/livecd-iso-to-disk
$(INSTALL_PROGRAM) -D tools/livecd-iso-to-pxeboot.sh $(DESTDIR)/usr/bin/livecd-iso-to-pxeboot
$(INSTALL_PROGRAM) -D tools/mkbiarch.py $(DESTDIR)/usr/bin/mkbiarch
diff --git a/tools/image-creator b/tools/image-creator
deleted file mode 100755
index 6f2604c..0000000
--- a/tools/image-creator
+++ /dev/null
@@ -1,75 +0,0 @@
-#!/usr/bin/python -tt
-#
-# image-creator: Create an ext3 system image
-#
-# Copyright 2007, Red Hat Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Library General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-import os
-import sys
-import shutil
-import optparse
-import logging
-
-import imgcreate
-
-def parse_options(args):
- parser = optparse.OptionParser(usage = "%prog [--name=<name>] <kickstart>")
-
- parser.add_option("-n", "--name", type="string", dest="name",
- help="Image name and filesystem label")
-
- imgcreate.setup_logging(parser)
-
- (options, args) = parser.parse_args()
-
- if len(args) != 1:
- parser.print_usage()
- sys.exit(1)
-
- return (args[0], options)
-
-def main():
- (kscfg, options) = parse_options(sys.argv[1:])
-
- if os.geteuid () != 0:
- print >> sys.stderr, "You must run image-creator as root"
- return 1
-
- try:
- ks = imgcreate.read_kickstart(kscfg)
- except imgcreate.CreatorError, e:
- logging.error("Unable to load kickstart file '%s' : %s" % (kscfg, e))
- return 1
-
- if options.name:
- name = options.name
- else:
- name = imgcreate.build_name(kscfg)
-
- creator = imgcreate.LoopImageCreator(ks, name)
-
- try:
- creator.create()
- except imgcreate.CreatorError, e:
- logging.error("Unable to create image : %s" % e)
- return 1
- finally:
- creator.cleanup()
-
- return 0
-
-if __name__ == "__main__":
- sys.exit(main())
diff --git a/tools/livecd-creator b/tools/livecd-creator
index d352d74..8559372 100755
--- a/tools/livecd-creator
+++ b/tools/livecd-creator
@@ -41,6 +41,11 @@ def parse_options(args):
help="Add packages to an existing live CD iso9660 image.")
imgopt.add_option("-f", "--fslabel", type="string", dest="fs_label",
help="File system label (default based on config name)")
+ # Provided for img-create compatibility
+ imgopt.add_option("-n", "--name", type="string", dest="fs_label",
+ help=optparse.SUPPRESS_HELP)
+ imgopt.add_option("", "--image-type", type="string", dest="image_type",
+ help=optparse.SUPPRESS_HELP)
imgopt.add_option("", "--compression-type", type="string", dest="compress_type",
help="Compression type recognized by mksquashfs (default gzip, lzma needs custom kernel, lzo needs a 2.6.36+ kernel)",
default="gzip")
@@ -70,14 +75,31 @@ def parse_options(args):
help=optparse.SUPPRESS_HELP)
(options, args) = parser.parse_args()
+
+ # Pretend to be a image-creator if called with that name
+ if not options.image_type:
+ if sys.argv[0].endswith('image-creator'):
+ options.image_type = 'image'
+ else:
+ options.image_type = 'livecd'
+ if options.image_type not in ('livecd', 'image'):
+ raise Usage("'%s' is a recognized image type" % options.image_type)
+
+ # image-create compatibility: Last argument is kickstart file
+ if len(args) == 1:
+ options.kscfg = args.pop()
+ if len(args):
+ raise Usage("Extra arguments given")
+
if not options.kscfg:
raise Usage("Kickstart file must be provided")
if options.base_on and not os.path.isfile(options.base_on):
- raise Usage("Live CD ISO '%s' does not exist" %(options.base_on,))
- if options.fs_label and len(options.fs_label) > imgcreate.FSLABEL_MAXLEN:
- raise Usage("CD labels are limited to 32 characters")
- if options.fs_label and options.fs_label.find(" ") != -1:
- raise Usage("CD labels cannot contain spaces.")
+ raise Usage("Image file '%s' does not exist" %(options.base_on,))
+ if options.image_type == 'live':
+ if options.fs_label and len(options.fs_label) > imgcreate.FSLABEL_MAXLEN:
+ raise Usage("CD labels are limited to 32 characters")
+ if options.fs_label and options.fs_label.find(" ") != -1:
+ raise Usage("CD labels cannot contain spaces.")
return options
@@ -96,17 +118,17 @@ def main():
return ret
if os.geteuid () != 0:
- print >> sys.stderr, "You must run livecd-creator as root"
+ print >> sys.stderr, "You must run %s as root" % sys.argv[0]
return 1
if options.fs_label:
fs_label = options.fs_label
name = fs_label
else:
- name = imgcreate.build_name(options.kscfg, "livecd-")
+ name = imgcreate.build_name(options.kscfg, options.image_type + "-")
fs_label = imgcreate.build_name(options.kscfg,
- "livecd-",
+ options.image_type + "-",
maxlen = imgcreate.FSLABEL_MAXLEN,
suffix = "%s-%s" %(os.uname()[4], time.strftime("%Y%m%d%H%M")))
@@ -114,7 +136,15 @@ def main():
ks = imgcreate.read_kickstart(options.kscfg)
- creator = imgcreate.LiveImageCreator(ks, name, fs_label)
+ if options.image_type == 'livecd':
+ creator = imgcreate.LiveImageCreator(ks, name, fs_label)
+ elif options.image_type == 'image':
+ creator = imgcreate.LoopImageCreator(ks, name, fs_label)
+ else:
+ # Cannot happen, we validate this when parsing options.
+ logging.error(u"'%s' is not a valid image type" % options.image_type)
+ return 1
+
creator.tmpdir = os.path.abspath(options.tmpdir)
creator.compress_type = options.compress_type
creator.skip_compression = options.skip_compression
--
1.7.3.2