From owner-p4-projects@FreeBSD.ORG Sun Jun 24 01:29:54 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 0630316A46B; Sun, 24 Jun 2007 01:29:54 +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 AA1F116A400 for ; Sun, 24 Jun 2007 01:29:53 +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 9CCC913C465 for ; Sun, 24 Jun 2007 01:29:53 +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 l5O1TrLG001348 for ; Sun, 24 Jun 2007 01:29:53 GMT (envelope-from ivoras@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l5O1TrCQ001345 for perforce@freebsd.org; Sun, 24 Jun 2007 01:29:53 GMT (envelope-from ivoras@FreeBSD.org) Date: Sun, 24 Jun 2007 01:29:53 GMT Message-Id: <200706240129.l5O1TrCQ001345@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 122213 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: Sun, 24 Jun 2007 01:29:54 -0000 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 +# 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))