Add a simple imgcreate frontend which would be useful
both to people who just want a simple way of building
system images, but also as the simplest possible example
of using the imgcreate API.
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
---
API | 7 ++--
Makefile | 1 +
tools/image-creator | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 88 insertions(+), 3 deletions(-)
create mode 100755 tools/image-creator
diff --git a/API b/API
index 8b7ca8b..9783c74 100644
--- a/API
+++ b/API
@@ -5,9 +5,10 @@ functionality.
== Image Creation Frontends ==
-livecd-creator is one frontend for creating images. But really, it's
-straight-forward to build your own which deals with your own specific
-needs. To do so, you'll want to do the following:
+livecd-creator and image-creator are both frontends for creating
+images. But really, it's straight-forward to build your own which
+deals with your own specific needs. To do so, you'll want to do
+the following:
* Create a pykickstart handler object. All of the image creators are
driven by data stored in pykickstart handlers.
diff --git a/Makefile b/Makefile
index c3fc032..3d86b29 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ all:
install:
$(INSTALL_PROGRAM) -D creator/livecd-creator $(DESTDIR)/usr/bin/livecd-creator
+ $(INSTALL_PROGRAM) -D creator/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/mayflower $(DESTDIR)/usr/lib/livecd-creator/mayflower
$(INSTALL_DATA) -D AUTHORS $(DESTDIR)/usr/share/doc/livecd-tools-$(VERSION)/AUTHORS
diff --git a/tools/image-creator b/tools/image-creator
new file mode 100755
index 0000000..2603f9d
--- /dev/null
+++ b/tools/image-creator
@@ -0,0 +1,83 @@
+#!/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 imgcreate
+
+class ImageCreator(imgcreate.LoopImageCreator):
+ def _stage_final_image(self):
+ self._resparse()
+ shutil.move(self._image, self._outdir + "/" + self.name +
".img")
+
+def parse_options(args):
+ parser = optparse.OptionParser(usage = "%prog --config=<kickstart>
[options]")
+
+ def parse_kickstart(option, opt, kscfg, parser):
+ try:
+ ks = imgcreate.read_kickstart(kscfg)
+ except imgcreate.CreatorError, e:
+ raise optparse.OptionValueError(str(e))
+ setattr(parser.values, option.dest, (kscfg, ks))
+
+ parser.add_option("-c", "--config", type = "string",
dest = "ks",
+ action = "callback", callback = parse_kickstart,
+ help = "Path to kickstart config file")
+ parser.add_option("-n", "--name", type="string",
dest="name",
+ help="Image name and filesystem label")
+
+ (options, args) = parser.parse_args()
+
+ if options.ks is None or len(args) != 0:
+ parser.print_usage()
+ sys.exit(1)
+
+ return options
+
+def main():
+ options = parse_options(sys.argv[1:])
+
+ if os.geteuid () != 0:
+ print >> sys.stderr, "You must run image-creator as root"
+ return 1
+
+ (kscfg, ks) = (options.ks[0], options.ks[1])
+
+ if options.name:
+ name = options.name
+ else:
+ name = imgcreate.build_name(kscfg)
+
+ creator = ImageCreator(ks, name)
+
+ try:
+ creator.create()
+ except imgcreate.CreatorError, e:
+ print >> sys.stderr, "Error creating image : %s" % e
+ return 1
+ finally:
+ creator.cleanup()
+
+ return 0
+
+if __name__ == "__main__":
+ sys.exit(main())
--
1.5.3.3