PERFORCE change 122287 for review

Ivan Voras ivoras at FreeBSD.org
Mon Jun 25 16:39:47 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=122287

Change 122287 by ivoras at ivoras_finstall on 2007/06/25 16:39:37

	MakeImage can now embed 3rd party packages / ports in the LiveCD,
	chosen from those installed on the build machine.
	Among the minor changes, curses interface is now much improved and
	consistend across the script.

Affected files ...

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

Differences ...

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

@@ -25,7 +25,7 @@
 import os, os.path, sys
 from time import strftime
 from getopt import getopt, GetoptError
-from util import nukedir, execute, printmsg, cmdout, initutils
+from util import nukedir, execute, printmsg, cmdout, readline, initutils, getpkgdeps, getpkgfullname
 
 class MakeImageException(Exception):
 	pass
@@ -36,9 +36,27 @@
 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 WORKDIR [-s SRCDIR] [-k KERNEL] [-b] [-c] [-i ISOFILE]" % sys.argv[0]
-	sys.exit(1)
+def usage(exit=True):
+	print "usage: %s -d WORKDIR [-i ISOFILE] [-k KERNEL] [-p PKGLISTFILE] [-s SRCDIR] [-b] [-c] " % sys.argv[0]
+	print
+	print "Description:"
+	print "	-d WORKDIR	Base work directory to hold intermediate and final files"
+	print "			(requires ~800MB free). This is the only required"
+	print "			argument."
+	print "	-k KERNEL	FreeBSD kernel to package (default: GENERIC)"
+	print "	-i ISOFILE	ISO image to generate (default: WORKDIR/image.iso)"
+	print "	-p PKGLISTFILE	File containing list of packages to bundle with the"
+	print "			LiveCD system. All packages from the list must be"
+	print "			installed on the system doing the build."
+	print "	-s SRCDIR	Directory with FreeBSD source tree (default: /usr/src)"
+	print "	-b		Do buildworld / buildkernel before proceeding"
+	print "	-c		Assume installworld / installkernel phase has been"
+	print "			done in WORKDIR/livecd and proceed with configuration"
+	print "			and ISO image build"
+	if exit:
+		sys.exit(1)
+	else:
+		print
 
 WORKDIR = None		# Working directory. Will create DESTDIR inside it.
 DESTDIR = None		# The directory that will contain the root drive hierarchy
@@ -46,10 +64,11 @@
 KERNEL = "GENERIC"
 DoBuild = False
 DoMakeRoot = True	# Create / install livecd tree
-LABEL = "FreeBSD7"
+LABEL = "FreeBSD7"	# ISO9660 Volume label
+PKGLISTFILE = None
 ISO = None
 
-opts, args = getopt(sys.argv[1:], "d:s:i:bch")
+opts, args = getopt(sys.argv[1:], "d:s:i:p:bch")
 for o,a in opts:
 	if o == "-d":
 		WORKDIR = a
@@ -63,6 +82,8 @@
 			raise MakeImageException("Source directory not found: '%s'" % SRCDIR)
 	elif o == "-k":
 		KERNEL = a
+	elif o == "-p":
+		PKGLISTFILE = a
 	elif o == "-b":
 		DoBuild = True
 	elif o == "-c":
@@ -73,6 +94,7 @@
 		usage()
 
 if WORKDIR == None:
+	usage(False)
 	raise MakeImageException("Directory not specified (use '-d WORKDIR' argument)")
 if not os.path.exists(SRCDIR):
 	raise MakeImageException("Source directory not found: '%s'")
@@ -81,22 +103,21 @@
 
 DESTDIR = "%s/livecd" % WORKDIR
 
+initutils()
 if DoMakeRoot:
 	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()
+			printmsg("%s doesn't look like a FreeBSD root" % DESTDIR)
+			resp = readline("Delete it anyway? (y/N)").upper()
 			if resp != "Y":
-				print "Canceling"
+				printmsg("Canceling")
 				sys.exit(1)
 			else:
-				print "Wiping out %s" % DESTDIR
+				printmsg("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)
@@ -139,6 +160,38 @@
 f.write('syslogd_flags="-C"\n')
 f.close()
 
+if PKGLISTFILE != None:
+	# Install packages into the liveCD tree, using chroot
+	master_pkglist = []
+	f = file(PKGLISTFILE, "r")
+	for line in f.readlines():
+		line = line.strip()
+		if len(line) == 0:
+			continue
+		if line[0] == "#":
+			continue
+		master_pkglist.append(getpkgfullname(line))
+	dest_pkgs = {}
+	for pkg in master_pkglist:
+		dest_pkgs[pkg] = True
+		for p2 in getpkgdeps(pkg):
+			dest_pkgs[p2] = True
+	os.chdir("%s/tmp" % DESTDIR)
+	for pkg in dest_pkgs:
+		pkg_file = "%s.tbz" % pkg
+		execute("pkg_create -v -j -b %s %s" % (pkg, pkg_file))
+		dest_pkgs[pkg] = pkg_file
+	f = file("pkginst.sh", "w")
+	f.write("#!/bin/sh\ncd /tmp\npkg_delete -av\n")
+	for pkg in master_pkglist:
+		f.write("/usr/sbin/pkg_add -v %s\n" % dest_pkgs[pkg])
+	f.close()
+	execute("chroot %s /bin/sh /tmp/pkginst.sh" % DESTDIR)
+	for pkg in dest_pkgs:
+		os.unlink(dest_pkgs[pkg])
+	os.unlink("pkginst.sh")
+
+
 os.chdir(WORKDIR)
 if ISO == None:
 	ISO = "%s/image.iso" % WORKDIR

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

@@ -54,12 +54,21 @@
 def printmsg(str):
 	global msgwin, cmdwin
 	if msgwin != None:
-		msgwin.addstr(" ### %s\n" % str)
+		msgwin.addstr("\n ### %s" % str)
 		msgwin.refresh()
 	else:
 		print " ### %s" % str
 
 
+def readline(prompt):
+	global msgwin
+	if msgwin != None:
+		msgwin.addstr("\n >>> %s : " % prompt)
+		return msgwin.getstr()
+	else:
+		return raw_input(" >>> %s : " % prompt)
+
+
 def execute(cmd):
 	global msgwin, cmdwin
 	printmsg("Executing: \"%s\"" % cmd)
@@ -88,3 +97,28 @@
 def cmdout(cmd):
 	return os.popen(cmd, "r").read()
 
+
+def getpkgdeps(pkg):
+	f = os.popen("pkg_info -r %s" % pkg, "r")
+	deps = []
+	for line in f.readlines():
+		line = line.strip()
+		if line.startswith("Dependency: "):
+			d, dep = line.split(": ", 1)
+			deps.append(dep)
+	f.close()
+	return deps
+
+
+def getpkgfullname(pkg):
+	"""Not a very intelligent implementation of "base package name" to
+	"fully qualified package name" translator. E.g. returns "python24-2.4.4"
+	when given "python24"
+	"""
+	f = os.popen("pkg_info", "r")
+	for line in f.readlines():
+		if line.startswith(pkg):
+			fullname, etc = line.split(" ", 1)
+			return fullname.strip()
+	return None
+


More information about the p4-projects mailing list