PERFORCE change 122502 for review
Ivan Voras
ivoras at FreeBSD.org
Thu Jun 28 22:00:06 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=122502
Change 122502 by ivoras at ivoras_finstall on 2007/06/28 21:59:39
Remove config file generation from script code and move it to
external files.
Affected files ...
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/bundle-spec#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/dot.xinitrc#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/fstab#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/hosts#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/livecd#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/loader.conf#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/rc.conf#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/bundles/xorg.conf#1 add
.. //depot/projects/soc2007/ivoras_finstall/makeimage/makeimage.py#6 edit
.. //depot/projects/soc2007/ivoras_finstall/makeimage/util.py#4 edit
Differences ...
==== //depot/projects/soc2007/ivoras_finstall/makeimage/makeimage.py#6 (text+ko) ====
@@ -22,7 +22,7 @@
# finstall LiveCD image creator
-import os, os.path, sys
+import os, os.path, sys, stat
from time import strftime
from getopt import getopt, GetoptError
from util import nukedir, execute, printmsg, cmdout, readline, initutils, getpkgdeps, getpkgfullname
@@ -37,11 +37,11 @@
raise MakeImageException("This utility requires mkisofs(8) (install ports/sysutils/cdrtools)")
def usage(exit=True):
- print "usage: %s -d WORKDIR [-i ISOFILE] [-k KERNEL] [-p PKGLISTFILE] [-s SRCDIR] [-b] [-c] " % sys.argv[0]
+ print "usage: %s -d WORKDIR [-i ISOFILE] [-k KERNEL] [-p PKGLISTFILE] [-s SRCDIR] [-x BUNDLEDIR] [-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 " (requires ~1.5 GB 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)"
@@ -49,6 +49,8 @@
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 " -x BUNDLEDIR Directory containing bundle-spec file and appropriate"
+ print " files to bundle (default: bundles)"
print " -b Do buildworld / buildkernel before proceeding"
print " -c Assume installworld / installkernel phase has been"
print " done in WORKDIR/livecd and proceed with configuration"
@@ -65,6 +67,8 @@
DoBuild = False
DoMakeRoot = True # Create / install livecd tree
LABEL = "FreeBSD7" # ISO9660 Volume label
+BUNDLEDIR = "bundles"
+BUNDLEFILE = "bundle-spec"
PKGLISTFILE = None
ISO = None
@@ -90,6 +94,8 @@
DoMakeRoot = False
elif o == "-i":
ISO = a
+ elif o == "-x":
+ BUNDLEDIR = a
elif o == "-h":
usage()
@@ -100,6 +106,8 @@
raise MakeImageException("Source directory not found: '%s'")
if not os.path.exists(WORKDIR):
os.makedirs(WORKDIR)
+if not os.path.exists(BUNDLEDIR) or not os.path.exists("%s/%s" % (BUNDLEDIR, BUNDLEFILE)):
+ BUNDLEDIR = None
DESTDIR = "%s/livecd" % WORKDIR
@@ -128,39 +136,52 @@
execute("make installworld DESTDIR=%s" % DESTDIR)
execute("make distribution DESTDIR=%s" % DESTDIR)
execute("make installkernel KERNCONF=%s DESTDIR=%s" % (KERNEL, DESTDIR))
+ execute("rm %s/boot/kernel/*.symbols" % DESTDIR)
else:
if not os.path.exists(DESTDIR) or not os.path.exists("%s/COPYRIGHT" % DESTDIR):
print "%s doesn't look like existing livecd root" % DESTDIR
sys.exit(1)
-str_time = strftime("%Y-%m-%d %H:%M")
-printmsg("Creating config files")
+str_time = strftime("%H:%M")
+str_date = strftime("%Y-%m-%d")
-# Edit loader.conf
-lc = file("%s/boot/loader.conf" % DESTDIR, "w+")
-lc.write("# /boot/loader.conf generated by finstall makeimage.py on %s\n" % str_time)
-lc.write('rootdev="iso9660/%s"\n' % LABEL)
-lc.write('boot_cdrom="1"\n')
-lc.close()
+if os.path.exists("%s/%s" % (BUNDLEDIR, BUNDLEFILE)):
+ printmsg("Bundling config files")
+ f = file("%s/%s" % (BUNDLEDIR, BUNDLEFILE), "r")
+ for line in f.readlines():
+ line = line.strip()
+ if len(line) == 0:
+ continue
+ if line[0] == "#":
+ continue
+ if line.find("=") == -1:
+ raise MakeImageException("Invalid %s line: %s", (BUNDLEFILE, line))
+ if line.find(";") != -1:
+ files, flags = line.split(";", 1)
+ flags = flags.split(";")
+ dest_file, src_file = files.split("=", 1)
+ else:
+ flags = []
+ dest_file, src_file = line.split("=", 1)
+ file_contents = file("%s/%s" % (BUNDLEDIR, src_file), "r").read()
+ if "kw" in flags:
+ file_contents = file_contents.replace("$label$", LABEL)
+ file_contents = file_contents.replace("$time$", str_time)
+ file_contents = file_contents.replace("$date$", str_date)
+ file_contents = file_contents.replace("$dest_file$", dest_file)
+ file_contents = file_contents.replace("$src_file$", src_file)
+ if "a" in flags:
+ df = file("%s%s" % (DESTDIR, dest_file), "a")
+ else:
+ df = file("%s%s" % (DESTDIR, dest_file), "w")
+ df.write(file_contents)
+ df.close()
+ if "x" in flags:
+ os.chmod("%s%s" % (DESTDIR, dest_file), stat.S_IRUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
+ f.close()
-# Edit fstab
-f = file("%s/etc/fstab" % DESTDIR, "w+")
-f.write("# /etc/fstab generated by finstall makeimage.py on %s\n" % str_time)
-f.write("/dev/iso9660/%s / cd9660 ro 0 0\n" % LABEL)
-#f.write("md /tmp mfs rw,-S,-s32m 0 0\n")
-#f.write("/tmp /etc unionfs rw,copymode=transparent 0 0\n")
-f.close()
-
-# Edit rc.conf
-f = file("%s/etc/rc.conf" % DESTDIR, "w+")
-f.write("# /etc/rc.conf generated by finstall makeimage.py on %s\n" % str_time)
-f.write('rc_debug="NO"\n')
-f.write('hostname="finstall"\n')
-f.write('background_fsck="NO"\n')
-f.write('syslogd_flags="-C"\n')
-f.close()
-
if PKGLISTFILE != None:
+ printmsg("Bundling packages")
# Install packages into the liveCD tree, using chroot
master_pkglist = []
f = file(PKGLISTFILE, "r")
@@ -178,8 +199,8 @@
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))
+ pkg_file = "%s.tgz" % pkg
+ execute("pkg_create -v -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")
@@ -192,19 +213,6 @@
os.unlink(dest_pkgs[pkg])
os.unlink("pkginst.sh")
-f = file("%s/etc/rc.d/livecd" % DESTDIR, "w")
-f.write("# /etc/rc.d/livecd generated by finstall makeimage.py on %s\n" % str_time)
-f.write("# BEFORE: hostid\n")
-f.write("# REQUIRE: root\n")
-f.write("# KEYWORD: nojail\n\n")
-f.write("/sbin/mount_mfs -s 32m -S md /tmp\n")
-f.write("/bin/mkdir /tmp/etc /tmp/log /tmp/run /tmp/tmp\n")
-f.write("/sbin/mount_unionfs -o copymode=transparent /tmp/etc /etc\n")
-f.write("/sbin/mount_unionfs -o copymode=transparent /tmp/log /var/log\n")
-f.write("/sbin/mount_unionfs -o copymode=transparent /tmp/run /var/run\n")
-f.write("/sbin/mount_unionfs -o copymode=transparent /tmp/tmp /var/tmp\n")
-f.close()
-execute("chmod a+x %s/etc/rc.d/livecd" % DESTDIR)
os.chdir(WORKDIR)
if ISO == None:
==== //depot/projects/soc2007/ivoras_finstall/makeimage/util.py#4 (text+ko) ====
More information about the p4-projects
mailing list