From owner-p4-projects@FreeBSD.ORG Mon Jun 25 16:39:47 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9699D16A534; Mon, 25 Jun 2007 16:39:46 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5A36A16A4E6 for ; Mon, 25 Jun 2007 16:39:46 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 48A6A13C4E9 for ; Mon, 25 Jun 2007 16:39:46 +0000 (UTC) (envelope-from ivoras@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l5PGdkrU066827 for ; Mon, 25 Jun 2007 16:39:46 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l5PGdjE6066823 for perforce@freebsd.org; Mon, 25 Jun 2007 16:39:45 GMT (envelope-from ivoras@FreeBSD.org) Date: Mon, 25 Jun 2007 16:39:45 GMT Message-Id: <200706251639.l5PGdjE6066823@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ivoras@FreeBSD.org using -f From: Ivan Voras To: Perforce Change Reviews Cc: Subject: PERFORCE change 122287 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jun 2007 16:39:47 -0000 http://perforce.freebsd.org/chv.cgi?CH=122287 Change 122287 by ivoras@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 +