Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Jun 2007 01:29:53 GMT
From:      Ivan Voras <ivoras@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 122213 for review
Message-ID:  <200706240129.l5O1TrCQ001345@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=122213

Change 122213 by ivoras@ivoras_finstall on 2007/06/24 01:29:30

	Implement basic functionality, with a nice little curses
	trick for better legibility.

Affected files ...

.. //depot/projects/soc2007/ivoras_finstall/makeimage/makeimage.py#2 edit
.. //depot/projects/soc2007/ivoras_finstall/makeimage/util.py#1 add

Differences ...

==== //depot/projects/soc2007/ivoras_finstall/makeimage/makeimage.py#2 (text+ko) ====

@@ -1,5 +1,31 @@
+#!/usr/local/bin/python
+# Copyright (c) 2007. Ivan Voras <ivoras@freebsd.org>
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions are met:
+#
+#   1. Redistributions of source code must retain the above copyright notice, 
+#      this list of conditions and the following disclaimer.
+#   2. Redistributions in binary form must reproduce the above copyright notice,
+#      this list of conditions and the following disclaimer in the 
+#      documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
+# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY 
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# finstall LiveCD image creator
+
 import os, os.path, sys
+from time import strftime
 from getopt import getopt, GetoptError
+from util import nukedir, execute, printmsg, cmdout, initutils
 
 class MakeImageException(Exception):
 	pass
@@ -7,25 +33,80 @@
 if os.getuid() != 0:
 	raise MakeImageException("This utility needs to be executed as root user (for the installworld phase)")
 
+if cmdout("which mkisofs").find("not found") != -1:
+	raise MakeImageException("This utility requires mkisofs(8) (install ports/sysutils/cdrtools)")
+
 def usage():
-	print "usage: %s <-d DESTDIR>" % sys.argv[0]
+	print "usage: %s -d WORKDIR [-s SRCDIR] [-k KERNEL]" % sys.argv[0]
 	sys.exit(1)
 
-DESTDIR = None 
+WORKDIR = None		# Working directory. Will create DESTDIR inside it.
+DESTDIR = None		# The directory that will contain the root drive hierarchy
+SRCDIR = "/usr/src"
+KERNEL = "GENERIC"
+DoBuild = False
+LABEL = "FreeBSD7"
 
-opts, args = getopt(sys.argv[1:], "d:h")
+opts, args = getopt(sys.argv[1:], "d:s:bh")
 for o,a in opts:
 	if o == "-d":
-		DESTDIR = a
-		if DESTDIR[-1] == "/":
-			DESTDIR = DESTDIR[:-1]
-		if not os.path.exists(DESTDIR):
-			raise MakeImageException("Directory not found: %s" % DESTDIR)
+		WORKDIR = a
+		if WORKDIR[-1] == "/":
+			WORKDIR = WORKDIR[:-1]
+	elif o == "-s":
+		SRCDIR = a
+		if SRCDIR[-1] == "/":
+			SRCDIR = SRCDIR[:-1]
+		if not os.path.exists(SRCDIR):
+			raise MakeImageException("Source directory not found: '%s'" % SRCDIR)
+	elif o == "-k":
+		KERNEL = a
+	elif o == "-b":
+		DoBuild = True
 	elif o == "-h":
 		usage()
 
-if DESTDIR == None:
-	raise MakeImageException("Directory not specified (use '-d DESTDIR' argument)")
+if WORKDIR == None:
+	raise MakeImageException("Directory not specified (use '-d WORKDIR' argument)")
+if not os.path.exists(SRCDIR):
+	raise MakeImageException("Source directory not found: '%s'")
+if not os.path.exists(WORKDIR):
+	os.makedirs(WORKDIR)
+
+DESTDIR = "%s/livecd" % WORKDIR
+if os.path.exists(DESTDIR):
+	if not os.path.exists("%s/COPYRIGHT" % DESTDIR):
+		print "--> %s doesn't look like a FreeBSD root" % DESTDIR
+		resp = raw_input("Delete it anyway? (y/N) ").upper()
+		if resp != "Y":
+			print "Canceling"
+			sys.exit(1)
+		else:
+			print "Wiping out %s" % DESTDIR
+	nukedir(DESTDIR)
+
+os.makedirs(DESTDIR)
+
+initutils()
+
+printmsg("Using '%s' as source directory" % SRCDIR)
+printmsg("Using '%s' as working directory (root on '%s')" % (WORKDIR, DESTDIR))
+printmsg("Using '%s' kernel" % KERNEL)
+printmsg("Random message to test scrolling")
+
+os.chdir(SRCDIR)
+if DoBuild:
+	execute("make buildworld")
+execute("make installworld DESTDIR=%s" % DESTDIR)
+execute("make distribution DESTDIR=%s" % DESTDIR)
+execute("make installkernel KERNCONF=%s DESTDIR=%s" % (KERNEL, DESTDIR))
+
+lc = file("%s/boot/loader.conf" % DESTDIR, "w+")
+lc.write("# /boot/loader.conf generated by finstall makeimage.py on %s\n" % strftime("%Y-%m-%d %H:%M"))
+lc.write('rootdev="iso9660/%s"\n' % LABEL)
+lc.write('boot_cdrom="1"\n')
+lc.close()
 
-print "Using '%s' as build directory" % DESTDIR
+os.chdir(WORKDIR)
+execute("mkisofs -l -nobak -V %s -T -J -r -ldots -b boot/cdboot -no-emul-boot -o %s/image.iso %s" % (LABEL, WORKDIR, DESTDIR))
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706240129.l5O1TrCQ001345>