[Midnightbsd-cvs] mports: make_chroot_tarball.pl: Update to make /etc and /usr/share from

ctriv at midnightbsd.org ctriv at midnightbsd.org
Thu Nov 6 15:11:23 EST 2008


Log Message:
-----------
Update to make /etc and /usr/share from src.  We also inject a resolv.conf
into /etc, as the one from source isn't empty/non-existant.  

Right now the only way to change resolv.conf is to edit this script, a way
to configure this at run time is still needed.

Modified Files:
--------------
    mports/Tools/magus:
        make_chroot_tarball.pl (r1.5 -> r1.6)

-------------- next part --------------
Index: make_chroot_tarball.pl
===================================================================
RCS file: /home/cvs/mports/Tools/magus/make_chroot_tarball.pl,v
retrieving revision 1.5
retrieving revision 1.6
diff -L Tools/magus/make_chroot_tarball.pl -L Tools/magus/make_chroot_tarball.pl -u -r1.5 -r1.6
--- Tools/magus/make_chroot_tarball.pl
+++ Tools/magus/make_chroot_tarball.pl
@@ -34,9 +34,12 @@
 #
 use strict;
 use warnings;
+use File::Temp qw(tempdir);
 
 my $ballname = shift || die "Usage: $0 <tarball name>\n";
 
+my $tmpdir = tempdir('/tmp/magusXXXXXXXX', CLEANUP => 1);
+
 # list of files and dirs that are passed to tar normally.
 my @files = qw(
   /.cshrc
@@ -64,11 +67,8 @@
   /boot/screen.4th
   /boot/support.4th
   /COPYRIGHT
-  /etc
   /lib
   /libexec
-  /mnt
-  /proc
   /rescue
   /root/.cshrc
   /root/.k5login
@@ -82,7 +82,6 @@
   /usr/libdata
   /usr/libexec
   /usr/sbin
-  /usr/share
   /var/account
   /var/at
   /var/at/jobs
@@ -103,11 +102,32 @@
   /var/yp/Makefile.dist
 );
 
+# directories to get out of the tempdir
+my @tempdirs = qw(mnt proc usr/share etc var/named);
+
+run(qq(/usr/bin/tar -cpf $ballname --exclude '*perl*' @files));
+
+
+run("mtree -p $tmpdir -f /usr/src/etc/mtree/BSD.root.dist -dU");
+run("mtree -p $tmpdir/usr -f /usr/src/etc/mtree/BSD.usr.dist -dU");
+run("mtree -p $tmpdir/var -f /usr/src/etc/mtree/BSD.var.dist -dU");
+run("mtree -p $tmpdir/var/named -f /usr/src/etc/mtree/BIND.chroot.dist -dU");
+
+run("cd /usr/src/share && make DESTDIR=$tmpdir install");
+run("cd /usr/src/etc && make DESTDIR=$tmpdir distribution");
+
+inject_etc_files($tmpdir);
+
+run(qq(tar -C $tmpdir -rpf $ballname @tempdirs));
+run(qq(bzip2 $ballname));
+run(qq(/bin/ls -hl $ballname.bz2));
+
+# clean this up so the tmpdir can get deleted
+run(qq(chflags 0 $tmpdir/var/empty));
 
 sub run {
   my ($command) = @_;
 
-  print "Warning: Be sure to have /mnt and other file systems unmounted\n";
   print "$command\n";
   system($command);
   
@@ -119,9 +139,28 @@
     die "Couldn't execute: $!\n";
   }
   
-  die "Command returned non-zero ($?)\n";
+  die "Command \"$command\" returned non-zero ($?)\n";
 }
 
-run(qq(/usr/bin/tar -cpyf $ballname @files));
-run(qq(/bin/ls -hl $ballname));
+sub inject_etc_files {
+  my ($tempdir) = @_;
+  
+  my @files = (
+    {
+      name     => 'resolve.conf',
+      contents => <<END,
+search emich.edu
+nameserver 164.76.2.251
+nameserver 164.76.2.54
+nameserver 164.76.102.66
+END
+    }
+  );
+  
+  foreach my $file (@files) {
+    open(my $fh, '>', "$tempdir/etc/$file->{name}") || die "Couldn't open $tempdir/etc/$file->{name}: $!\n";
+    print $fh $file->{contents};
+    close($fh) || die "Couldn't close $tempdir/etc/$file->{name}: $!\n";
+  }
+}
 


More information about the Midnightbsd-cvs mailing list