tests-update-20080121
authorMike Meffie <mmeffie@sinenomine.net>
Mon, 21 Jan 2008 21:04:35 +0000 (21:04 +0000)
committerDerrick Brashear <shadow@dementia.org>
Mon, 21 Jan 2008 21:04:35 +0000 (21:04 +0000)
LICENSE IPL10

update test scripting

17 files changed:
Makefile.in
configure.in
src/afsd/afs.rc.linux
src/tests/Makefile.in
src/tests/OpenAFS/ConfigUtils.pm
src/tests/OpenAFS/config.pm
src/tests/afs-newcell.pl
src/tests/baduniq.pl
src/tests/bosexec.pl
src/tests/bosinstall.pl
src/tests/extcopyin
src/tests/extcopyout
src/tests/hardlink5
src/tests/reauth.pl
src/tests/run-tests.in
src/tests/vosdump.pl
src/tests/vosrestore.pl

index 8d0c719..b94a3de 100644 (file)
@@ -771,7 +771,6 @@ distclean: clean
        src/tbutc/Makefile \
        src/tests/Makefile \
        src/tests/run-tests \
-       src/tests/OpenAFS/Dirpath.pm \
        src/tsalvaged/Makefile \
        src/tsm41/Makefile \
        src/tviced/Makefile \
index eafeb01..1be45f2 100644 (file)
@@ -109,7 +109,6 @@ src/sys/Makefile \
 src/tbutc/Makefile \
 src/tests/Makefile \
 src/tests/run-tests \
-src/tests/OpenAFS/Dirpath.pm \
 src/tsalvaged/Makefile \
 src/tsm41/Makefile \
 src/tviced/Makefile \
index 9591579..b86189e 100644 (file)
@@ -58,7 +58,7 @@ runcmd() {
    echo
 }
 
-SYSCNF=/etc/sysconfig/afs
+SYSCNF=${SYSCNF:-/etc/sysconfig/afs}
 KERNEL_VERSION=`uname -r`
 
 # Gather up options and post startup script name, if present
@@ -69,6 +69,10 @@ fi
 CACHEINFO=${CACHEINFO:-/usr/vice/etc/cacheinfo}
 CACHE=${CACHEDIR:-/usr/vice/cache}
 AFS=${AFSDIR:-/afs}
+AFSD=${AFSD:-/usr/vice/etc/afsd}
+BOSSERVER=${BOSSERVER:-/usr/afs/bin/bosserver}
+BOS=${BOS:-/usr/bin/bos}
+KILLAFS=${KILLAFS:-/usr/vice/etc/killafs}
 
 # is_on returns 1 if value of arg is "on"
 is_on() {
@@ -183,7 +187,7 @@ set_prefix()
        esac
 }
 
-MODLOADDIR=/usr/vice/etc/modload
+MODLOADDIR=${MODLOADDIR:-/usr/vice/etc/modload}
 # load_client loads the AFS client module if it's not already loaded. 
 load_client() {
        # If LIBAFS is set, use it.
@@ -279,13 +283,13 @@ case "$1" in
 
        echo "Starting AFS services..... "
        # Start bosserver, it if exists
-       if  is_on $AFS_SERVER && test -x /usr/afs/bin/bosserver  ; then
-               /usr/afs/bin/bosserver 
+       if  is_on $AFS_SERVER && test -x $BOSSERVER  ; then
+               $BOSSERVER 
                test "$afs_rh" && touch /var/lock/subsys/afs
                if is_on $WAIT_FOR_SALVAGE; then
                        # wait for fileserver to finish salvaging
                        sleep 10
-                       while /usr/bin/bos status localhost fs 2>&1 | grep 'Auxiliary.*salvaging'; do
+                       while $BOS status localhost fs 2>&1 | grep 'Auxiliary.*salvaging'; do
                                echo "Waiting for salvager to finish..... "
                                sleep 10
                        done
@@ -293,10 +297,10 @@ case "$1" in
        fi
 
        # Start AFS client
-       if  is_on $AFS_CLIENT && test -x /usr/vice/etc/afsd  ; then
+       if  is_on $AFS_CLIENT && test -x $AFSD  ; then
                generate_cacheinfo
                choose_afsdoptions
-               /usr/vice/etc/afsd ${AFSD_OPTIONS}
+               $AFSD ${AFSD_OPTIONS}
                test "$afs_rh" && touch /var/lock/subsys/afs
                $AFS_POST_INIT
        fi
@@ -309,16 +313,16 @@ case "$1" in
        echo "Stopping AFS services..... "
 
        if  is_on $AFS_CLIENT  ; then
-               if [ -x /usr/vice/etc/killafs ] ; then
-                       runcmd "Sending all processes using /afs the TERM signal ..." /usr/vice/etc/killafs TERM
-                       runcmd "Sending all processes using /afs the KILL signal ..." /usr/vice/etc/killafs KILL
+               if [ -x $KILLAFS ] ; then
+                       runcmd "Sending all processes using /afs the TERM signal ..." $KILLAFS TERM
+                       runcmd "Sending all processes using /afs the KILL signal ..." $KILLAFS KILL
                fi
                umount /afs
        fi
 
-       if  is_on $AFS_SERVER && test -x /usr/bin/bos ; then
+       if  is_on $AFS_SERVER && test -x $BOS ; then
                echo "Stopping AFS bosserver"
-               /usr/bin/bos shutdown localhost -localauth -wait
+               $BOS shutdown localhost -localauth -wait
                killall -HUP bosserver
        fi
 
index 7e372db..13639e5 100644 (file)
@@ -144,9 +144,6 @@ TEST_SRCS     = write-ro-file.c read-vs-mmap.c read-vs-mmap2.c                 \
 
 EXTRA_OBJS = err.o errx.o warn.o warnx.o vwarn.o vwarnx.o verr.o verrx.o warnerr.o snprintf.o 
 
-OpenAFS/OS.pm: OpenAFS/OS-$(MKAFS_OSTYPE).pm
-       $(CP) OpenAFS/OS-$(MKAFS_OSTYPE).pm OpenAFS/OS.pm
-
 fsx: fsx.o $(EXTRA_OBJS)
        $(CC) $(LDFLAGS) -o $@ fsx.o $(EXTRA_OBJS) $(LIBS)
 
@@ -342,13 +339,13 @@ install:
 
 uninstall:
 
-all: run-tests OpenAFS/OS.pm libxfiles.a libdumpscan.a $(TEST_PROGRAMS)\
+all: run-tests dirpath.conf OpenAFS/Dirpath.pm libxfiles.a libdumpscan.a $(TEST_PROGRAMS)\
        afsdump_scan afsdump_dirlist afsdump_extract dumptool
        @chmod +x run-tests
 
 clean:
        -rm -f xf_errs.c xf_errs.h dumpscan_errs.c dumpscan_errs.h *.o \
-       $(TARGETS) run-tests $(TEST_PROGRAMS) OS.pm
+       $(TARGETS) run-tests $(TEST_PROGRAMS) OpenAFS/Dirpath.pm
 
 include ../config/Makefile.version
 
@@ -361,4 +358,54 @@ check: run-tests $(TEST_PROGRAMS)
 check-fast: run-tests $(TEST_PROGRAMS)
        ./run-tests -all -fast
 
+dirpath.conf: Makefile
+       @echo "creating $@"
+       @echo "# auto-generated by src/tests/Makefile"      >$@
+       @echo "# DO NOT EDIT"                               >>$@
+       @echo "afsconfdir=@afsconfdir@"                     >>$@
+       @echo "viceetcdir=@viceetcdir@"                     >>$@
+       @echo "afssrvbindir=@afssrvbindir@"                 >>$@
+       @echo "afssrvsbindir=@afssrvsbindir@"               >>$@
+       @echo "afssrvlibexecdir=@afssrvlibexecdir@"         >>$@
+       @echo "afsdbdir=@afsdbdir@"                         >>$@
+       @echo "afslogsdir=@afslogsdir@"                     >>$@
+       @echo "afslocaldir=@afslocaldir@"                   >>$@
+       @echo "afsbackupdir=@afsbackupdir@"                 >>$@
+       @echo "afsbosconfigdir=@afsbosconfigdir@"           >>$@
+       @echo "afskerneldir=@afskerneldir@"                 >>$@
+       @echo "initdir=@sysconfdir@"                        >>$@
+       @echo "localstatedir=@localstatedir@"               >>$@
+       @echo "ostype=@MKAFS_OSTYPE@"                       >>$@
+
+OpenAFS/Dirpath.pm: Makefile
+       @echo "Creating OpenAFS/Dirpath.pm"
+       @echo "# This is -*- perl -*-"                          >$@
+       @echo "# auto-generated by src/tests/Makefile"          >>$@
+       @echo "# DO NOT EDIT"                                   >>$@
+       @echo "package OpenAFS::Dirpath;"                       >>$@
+       @echo "use strict;"                                     >>$@
+       @echo "use vars qw( @ISA @EXPORT \$$openafsdirpath);"   >>$@
+       @echo "@ISA = qw(Exporter);"                            >>$@
+       @echo "require Exporter;"                               >>$@
+       @echo "@EXPORT = qw(\$$openafsdirpath);"                >>$@
+       @echo ""                                                >>$@
+       @echo "\$$openafsdirpath = {"                           >>$@
+       @echo "  'afsconfdir'       => '@afsconfdir@',"         >>$@
+       @echo "  'viceetcdir'       => '@viceetcdir@',"         >>$@
+       @echo "  'afssrvbindir'     => '@afssrvbindir@',"       >>$@
+       @echo "  'afssrvsbindir'    => '@afssrvsbindir@',"      >>$@
+       @echo "  'afssrvlibexecdir' => '@afssrvlibexecdir@',"   >>$@
+       @echo "  'afsdbdir'         => '@afsdbdir@',"           >>$@
+       @echo "  'afslogsdir'       => '@afslogsdir@',"         >>$@
+       @echo "  'afslocaldir'      => '@afslocaldir@',"        >>$@
+       @echo "  'afsbackupdir'     => '@afsbackupdir@',"       >>$@
+       @echo "  'afsbosconfigdir'  => '@afsbosconfigdir@',"    >>$@
+       @echo "  'afskerneldir'     => '@afskerneldir@',"       >>$@
+       @echo "  'initdir'          => '@sysconfdir@',"         >>$@
+       @echo "  'localstatedir'    => '@localstatedir@',"      >>$@
+       @echo "  'ostype'           => '@MKAFS_OSTYPE@',"       >>$@
+       @echo "};"                                              >>$@
+       @echo ""                                                >>$@
+       @echo "1;"                                              >>$@
+
 .PHONY:                all install clean realclean distclean mostlyclean install uninstall check
index ca56d60..06f7f4c 100644 (file)
@@ -3,24 +3,40 @@
 package OpenAFS::ConfigUtils;
 
 use strict;
-use vars qw( @ISA @EXPORT @unwinds);
+use vars qw( @ISA @EXPORT @unwinds $debug);
 @ISA = qw(Exporter);
 require Exporter;
 @EXPORT = qw(@unwinds run unwind);
 
-sub run ($) {
-  print join(' ', @_);
-  print "\n";
-  system (@_)  == 0
-    or die "Failed: $?\n";
+$debug = 0;
+
+#--------------------------------------------------------------------
+# run(cmd) - run a command. Takes a command to be executed or 
+#            a perl code reference to be eval'd.
+sub run($) {
+  my $cmd = shift;
+  if (ref($cmd) eq 'CODE') {
+    eval { &$cmd };
+       if ($@) {
+      die "ERROR: $@\n";
+       }
+  }
+  else {
+    if ($debug) {
+      print "debug: $cmd\n";
+    }
+    my $rc = system($cmd);
+    unless ($rc==0) {
+      die "ERROR: Command failed: $cmd\nerror code=$?\n";
+    }
+  }
 }
 
 # This subroutine takes a command to run in case of failure.  After
 # each succesful step, this routine should be run with a command to
 # undo the successful step.
-
-        sub unwind($) {
-          push @unwinds, $_[0];
-        }
+sub unwind($) {
+   push @unwinds, $_[0];
+}
 
 1;
index 0de0a54..9e5333b 100644 (file)
@@ -66,7 +66,7 @@ an exotic locally-compiled version of AFS.
 
 =cut
 
-$def_ConfDir = "$openafsdirpath->{'viceetcdir'}";
+$def_ConfDir = $OpenAFS::Dirpath::openafsdirpath->{'viceetcdir'};
 #$def_ConfDir = "/usr/vice/etc";
 
 
@@ -95,7 +95,7 @@ what you want...
 =cut
 
 @CmdPath = (split(/:/, $ENV{PATH}),
-            "$openafsdirpath->{'afssrvbindir'}",        # For servers
+            $OpenAFS::Dirpath::openafsdirpath->{'afssrvbindir'},        # For servers
            '/usr/local/bin',      # Many sites put AFS in /usr/local
            '/usr/local/etc',
            '/usr/afsws/bin',      # For people who use Transarc's
index 91a2428..b2bf362 100755 (executable)
@@ -1,18 +1,17 @@
-#!/usr/bin/env perl -w
+#!/usr/bin/env perl
 # Copyright (C) 2000 by Sam Hartman
 # This file may be copied either under the terms of the GNU GPL or the IBM Public License
 # either version 2 or later of the GPL or version 1.0 or later of the IPL.
 
-use Term::ReadLine;
+use warnings;
 use strict;
+use Term::ReadLine;
 use OpenAFS::ConfigUtils;
 use OpenAFS::Dirpath;
 use OpenAFS::OS;
 use OpenAFS::Auth;
 use Getopt::Long;
-use vars qw($admin $server $cellname $cachesize $part
-          $requirements_met  $shutdown_needed $csdb);
-my $rl = new Term::ReadLine('afs-newcell');
+use Pod::Usage;
 
 =head1  NAME
 
@@ -20,20 +19,37 @@ my $rl = new Term::ReadLine('afs-newcell');
 
 =head1 SYNOPSIS
 
-B<afs-newcell> [B<--requirements-met>] [B<--admin> admin_user] [B<--cellname> cellname] [B<--cachesize> size] [B<--partition> partition-letter]
+B<afs-newcell>
+       B<--batch>
+       B<--debug>
+       B<--dont-unwind>
+       B<--help>
+       B<--ostype>=os
+       B<--server>=hostname
+       B<--cellname>=cell
+       B<--partition>=partition
+       B<--admin>=administrator
+       B<--kerberos-type>=authentication_type
+       B<--kerberos-realm>=realm_name
+       B<--kerberos-keytab>=keytab_file
+       B<--skip-make-keyfile>
+       B<--with-dafs>
+       B<--options-fileserver>=options
+       B<--options-volserver>=options
+       B<--options-salvageserver>=options
+          B<--options-salvager>=options 
 
 =head1 DESCRIPTION
 
-
 This script sets up the initial AFS database and configures the first
-database/file server. It also sets up an AFS cell's root volumes.  It 
-assumes that you already have a fileserver and database servers.  The 
-fileserver should have an empty root.afs. This script creates root.cell, 
-user, service and populates root.afs.  
+database/file server. It also sets up an AFS cell's root volumes.  It assumes
+that you already have a fileserver and database servers installed.  The
+fileserver should have an empty root.afs. This script creates root.cell, user,
+service and populates root.afs.  
 
-The B<requirements-met> option specifies that the initial requirements
-have been met and that the script can proceed without displaying the
-initial banner or asking for confirmation.
+The B<batch> option specifies that the initial requirements have been met and
+that the script can proceed without displaying the initial banner or asking for
+confirmation.
 
 The B<admin> option specifies the name of the administrative user.
 This user will be given system:administrators and susers permission in
@@ -41,254 +57,560 @@ the cell.
 
 The B<cellname> option specifies the name of the cell.
 
-The B<cachesize> option specifies the size of the AFS cache.
+The B<partition> option specifies the partition letter of the AFS partition. The
+default value is 'a', for /vicepa.
 
-=head1 AUTHOR
+=head1 PREREQUISITES
 
-Sam Hartman <hartmans@debian.org>
+The following requirements must be met before running
+this script.
 
-=cut
+This machine must have a working, empty filesystem mounted on /vicepa. A
+different partition letter may be specified by the partition command line
+option. For example, to use /vicepb, specify '--partition=b' on the command
+line.
 
-# main script
+The OpenAFS client and server binaries must be installed on this machine. 
 
-# mkvol(volume, mount)
-sub mkvol($$) {
-    my ($vol, $mnt) = @_;
-    run("$openafsdirpath->{'afssrvsbindir'}/vos create $server $part $vol -localauth");
-    unwind("$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part $vol -localauth");
-    run("$openafsdirpath->{'afssrvbindir'}/fs mkm $mnt $vol ");
-    run("$openafsdirpath->{'afssrvbindir'}/fs sa $mnt system:anyuser rl");
-}
+A working Kerberos realm with Kerberos4 support must be available. Supported
+Kerberos implementations are Heimdal with Kth-kerberos compatibility, MIT
+Kerberos5, and Kaserver (deprecated).  
 
-GetOptions (
-           "requirements-met" => \$requirements_met, 
-           "cellname=s" => \$cellname, 
-          "cachesize=s" => \$cachesize,
-           "partition=s" => \$part,
-           "admin=s" => \$admin);
+Create the single-DES AFS key and write it to a keytab file using the kerberos
+kadmin program.
+   
+Create a principal called afs/cellname in your realm.  The cell name should be
+all lower case, unlike Kerberos realms which are all upper case.  You can use
+the asetkey command or if you used AFS3 salt to create the key, the bos addkey
+command. The asetkey command is built when OpenAFS built with Kerberos support.
+The asetkey command requires a cell configuration.
 
-unless ($requirements_met) {
-  print <<eoreqs;
-                           Prerequisites
-
-In order to set up a new AFS cell, you must meet the following:
-
-1) You need a working Kerberos realm with Kerberos4 support.  You
-   should install Heimdal with Kth-kerberos compatibility or MIT
-   Kerberos5.
-
-2) You need to create the single-DES AFS key and load it into
-   $openafsdirpath->{'afsconfdir'}/KeyFile.  If your cell's name is the same as
-   your Kerberos realm then create a principal called afs.  Otherwise,
-   create a principal called afs/cellname in your realm.  The cell
-   name should be all lower case, unlike Kerberos realms which are all
-   upper case.  You can use asetkey from the openafs-krb5 package, or
-   if you used AFS3 salt to create the key, the bos addkey command.
-
-3) This machine should have a filesystem mounted on /vicepa.  If you
-   do not have a free partition, on Linux you can create a large file by using
-   dd to extract bytes from /dev/zero.  Create a filesystem on this file
-   and mount it using -oloop.  
-
-4) You will need an administrative principal created in a Kerberos
-   realm.  This principal will be added to susers and
-   system:administrators and thus will be able to run administrative
-   commands.  Generally the user is a root instance of some administravie
-   user.  For example if jruser is an administrator then it would be
-   reasonable to create jruser/root and specify jruser/root as the user
-   to be added in this script.
-
-5) The AFS client must not be running on this workstation.  It will be
-   at the end of this script.
+You will need an administrative principal created in a Kerberos realm.  This
+principal will be added to system:administrators and thus will be able to run
+administrative commands.  Generally the user is a root instance of some
+administravie user.  For example if jruser is an administrator then it would be
+reasonable to create jruser/root and specify jruser/root as the user to be
+added in this script using the 'admin' command line option.  You will also need
+to create a keyfile for this adminstrative user which is used by the script to
+obtain a ticket. The keyfile must be located in
+$openafsdirpath->{'afsconfdir'}/krb5.conf.
 
-eoreqs
+The AFS client must not be running on this workstation.  It will be started
+during the execution of this script.
 
-  $_ = $rl->readline("Do you meet these requirements? [y/n] ");
-  unless (/^y/i ) {
-    print "Run this script again when you meet the requirements\n";
-    exit(1);
-  }
-       
-  if ($> != 0) {
-    die "This script should almost always be run as root.  Use the --requirements-met option to run as non-root.\n";
+=head1 AUTHOR
+
+Sam Hartman <hartmans@debian.org>
+
+=cut
+
+
+my $term = new Term::ReadLine('afs-newcell');
+my $path = $OpenAFS::Dirpath::openafsdirpath;
+
+#-----------------------------------------------------------------------------------
+# prompt(message, default_value)
+#
+sub prompt($$) {
+  my ($message,$default) = @_;
+  my $value = $term->readline("$message [$default] ");
+  unless ($value) {
+    $value = $default;
   }
+  return $value;
+}
+
+#-----------------------------------------------------------------------------------
+# mkvol(volume, mount, partition)
+#
+sub mkvol($$$$) {
+    my ($vol, $mnt, $srv, $part) = @_;
+    run("$path->{'afssrvsbindir'}/vos create $srv $part $vol -maxquota 0 -localauth");
+    unwind("$path->{'afssrvsbindir'}/vos remove $srv $part $vol -localauth");
+    run("$path->{'afssrvbindir'}/fs mkm $mnt $vol ");
+    run("$path->{'afssrvbindir'}/fs sa $mnt system:anyuser rl");
 }
-open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
-while(<MOUNT>) {
-  if(m:^AFS:) {
-    print "The AFS client is currently running on this workstation.\n";
-    print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n";
-    exit(1);
+
+#-----------------------------------------------------------------------------------
+# check_program($prog) - verify the program is installed.
+#
+sub check_program($) {
+    my ($program) = @_;
+  unless ( -f $program ) {
+     die "error: Missing program: $program\n";
   }
-  if(m:^/afs on AFS:) {
-    print "The AFS client is currently running on this workstation.\n";
-    print "Please restart this script after running $openafsinitcmd->{'client-stop'}\n";
-    exit(1);
+  unless ( -x $program ) {
+     die "error: Not executable: $program\n";
   }
 }
-close MOUNT;
 
-unless ( -f "$openafsdirpath->{'afsconfdir'}/KeyFile") {
-  print "You do not have an AFS keyfile.  Please create this using asetkey from openafs-krb5 or 
-the bos addkey command";
-  exit(1);
-}
+#-----------------------------------------------------------------------------------
+# main script
+
+# options
+my $batch = 0;
+my $debug = 0;
+my $dont_unwind = 0;
+my $help = 0;
+my $ostype = $path->{'ostype'};
+my $server = 'localhost';
+my $cellname = 'testcell';
+my $partition = '/vicepa';
+my $admin = 'admin';
+my $kerberos_type = 'MIT';
+my $kerberos_realm = 'TESTCELL';
+my $kerberos_keytab = "$path->{'afsconfdir'}/krb5.keytab";
+my $skip_make_keyfile = 0;
+my $with_dafs = 0;
+my $options_fileserver = '';
+my $options_volserver = '';
+my $options_salvageserver = '';
+my $options_salvager = '';
 
-print "If the fileserver is not running, this may hang for 30 seconds.\n";
-run("$openafsinitcmd->{'filesrv-stop'}");
 $server = `hostname`;
 chomp $server;
-$admin = $rl->readline("What administrative principal should be used? ") unless $admin;
- die "Please specify an administrative user\n" unless $admin;
-$admin =~ s:/:.:g;
-if($admin =~ /@/) {
-die "The administrative user must be in the same realm as the cell and no realm may be specified.\n";
+
+GetOptions (
+       "batch" => \$batch, 
+       "debug!" => \$debug,
+       "dont-unwind!" => \$dont_unwind,
+       "help" => \$help,
+       "ostype=s" => \$ostype,
+       "server=s" => \$server,
+       "cellname=s" => \$cellname, 
+       "partition=s" => \$partition,
+       "admin=s" => \$admin,
+       "kerberos-type=s" => \$kerberos_type,
+       "kerberos-realm=s" => \$kerberos_realm,
+       "kerberos-keytab=s" => \$kerberos_keytab,
+       "skip-make-keyfile" => \$skip_make_keyfile,
+       "with-dafs" => \$with_dafs,
+       "options-fileserver=s" => \$options_fileserver,
+       "options-volserver=s" => \$options_volserver,
+       "options-salvageserver=s" => \$options_salvageserver,
+       "options-salvager=s" => \$options_salvager,
+       );
+
+if ($help) {
+  pod2usage(1);
+  exit 0;
 }
 
-$cellname = $rl->readline("What cellname should be used? ") unless $cellname;
-die "Please specify a cellname\n" unless $cellname;
+# print debug messages when running commands.
+$OpenAFS::ConfigUtils::debug = $debug;
 
-if (! -f "$openafsdirpath->{'afsconfdir'}/ThisCell") {
-    open(CELL, "> $openafsdirpath->{'afsconfdir'}/ThisCell");
-    print CELL "${cellname}";
-    close CELL;
-}
+#
+# Verify we have a clean slate before starting.
+#
+my @problems = ();
+my $try_rm_cell = 0;
 
-open(CELL, "$openafsdirpath->{'afsconfdir'}/ThisCell") or
-    die "Cannot open $openafsdirpath->{'afsconfdir'}/ThisCell: $!\n";
-
-my $lcell = <CELL>;
-chomp $lcell;
-close CELL;
-
-run( "echo \\>$lcell >$openafsdirpath->{'afsconfdir'}/CellServDB");
-$csdb = `host $server|awk '{print $4 " #" $1}'`;
-run( "echo $csdb >>$openafsdirpath->{'afsconfdir'}/CellServDB");
-run("$openafsinitcmd->{'filesrv-start'}");
-unwind("$openafsinitcmd->{'filesrv-stop'}");
-$shutdown_needed = 1;
-run ("$openafsdirpath->{'afssrvbindir'}/bos addhost $server $server -localauth ||true");
-run("$openafsdirpath->{'afssrvbindir'}/bos adduser $server $admin -localauth");
-unwind("$openafsdirpath->{'afssrvbindir'}/bos removeuser $server $admin -localauth");
-if ( -f "$openafsdirpath->{'afsdbdir'}/prdb.DB0" ) {
-  die "Protection database already exists; cell already partially created\n";
- }
-open(PRDB, "|$openafsdirpath->{'afssrvsbindir'}/pt_util -p $openafsdirpath->{'afsdbdir'}/prdb.DB0 -w ")
-or die "Unable to start pt_util: $!\n";
-print PRDB "$admin 128/20 1 -204 -204\n";
-print PRDB "system:administrators 130/20 -204 -204 -204\n";
-print PRDB" $admin 1\n";
-close PRDB;
-unwind( "rm $openafsdirpath->{'afsdbdir'}/prdb* ");
-# Start up ptserver and vlserver
-run("$openafsdirpath->{'afssrvbindir'}/bos create $server ptserver simple $openafsdirpath->{'afssrvlibexecdir'}/ptserver -localauth");
-unwind("$openafsdirpath->{'afssrvbindir'}/bos delete $server ptserver -localauth");
-
-run("$openafsdirpath->{'afssrvbindir'}/bos create $server vlserver simple $openafsdirpath->{'afssrvlibexecdir'}/vlserver -localauth");
-unwind("$openafsdirpath->{'afssrvbindir'}/bos delete $server vlserver -localauth");
-
-run( "$openafsdirpath->{'afssrvbindir'}/bos create $server fs fs ".
-     "-cmd $openafsdirpath->{'afssrvlibexecdir'}/fileserver ".
-     "-cmd $openafsdirpath->{'afssrvlibexecdir'}/volserver ".
-     "-cmd $openafsdirpath->{'afssrvlibexecdir'}/salvager -localauth");
-unwind( "$openafsdirpath->{'afssrvbindir'}/bos delete $server fs -localauth ");
-
-print "Waiting for database elections: ";
-sleep(30);
-print "done.\n";
-# Past this point we want to control when bos shutdown happens
-$shutdown_needed = 0;
-unwind( "$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth ");
-run("$openafsdirpath->{'afssrvsbindir'}/vos create $server a root.afs -localauth");
-# bring up client
-
-$cachesize = $rl->readline("What size cache (in 1k blocks)? ") unless $cachesize;
-die "Please specify a cache size\n" unless $cachesize;
-
-run("echo $lcell >$openafsdirpath->{'viceetcdir'}/ThisCell");
-run("cp $openafsdirpath->{'afsconfdir'}/CellServDB $openafsdirpath->{'viceetcdir'}/CellServDB");
-run("echo /afs:/usr/vice/cache:${cachesize} >$openafsdirpath->{'viceetcdir'}/cacheinfo");
-run("$openafsinitcmd->{'client-forcestart'}");
-my $afs_running = 0;
-open(MOUNT, "mount |") or die "Failed to run mount: $!\n";
-while(<MOUNT>) {
-if(m:^AFS:) {
-       $afs_running = 1;
-}
-       }
-unless ($afs_running) {
-print "*** The AFS client failed to start.\n";
-print  "Please fix whatever problem kept it from running.\n";
-       exit(1);
+if ($> != 0) {
+  push(@problems, "This script should run as root.");
 }
-unwind("$openafsinitcmd->{'client-stop'}");
 
-unless ($part) {
-    $part = $rl    ->readline("What partition? [a] ");
-    $part = "a" unless $part;
+my @afsconfigfiles = (
+  "$path->{'afsconfdir'}/ThisCell",
+  "$path->{'afsconfdir'}/CellServDB",
+  "$path->{'afsconfdir'}/UserList",
+  "$path->{'afsdbdir'}/prdb.DB0",
+  "$path->{'afsbosconfigdir'}/BosConfig",
+);
+foreach my $configfile (@afsconfigfiles) {
+  if ( -f $configfile ) {
+    push(@problems, "Configuration file already exists, $configfile.");
+    $try_rm_cell = 1;
+  }
 }
 
-&OpenAFS::Auth::authadmin();
-
-run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs system:anyuser rl");
-
-run("$openafsdirpath->{'afssrvsbindir'}/vos create $server $part root.cell -localauth");
-unwind("$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell -localauth");
-# We make root.cell s:anyuser readable after we mount in the next
-# loop.
-open(CELLSERVDB, "$openafsdirpath->{'viceetcdir'}/CellServDB")
-    or die "Unable to open $openafsdirpath->{'viceetcdir'}/CellServDB: $!\n";
-while(<CELLSERVDB>) {
-    chomp;
-    if (/^>\s*([a-z0-9_\-.]+)/ ) {
-       run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$1 root.cell -cell $1 -fast");
-       unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/$1");
-   }
+if (@problems) {
+  foreach my $problem (@problems) {
+    print "error: $problem\n";
+  }
+  print "info: Try running afs-rmcell.pl\n" if $try_rm_cell;
+  exit 1;
 }
 
-run("$openafsdirpath->{'afssrvbindir'}/fs sa /afs/$lcell system:anyuser rl");
-run ("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.$lcell root.cell -cell $lcell -rw");
-unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.$lcell");
-run("$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/.root.afs root.afs -rw");
-unwind ("$openafsdirpath->{'afssrvbindir'}/fs rmm /afs/.root.afs");
+#
+# Interactive mode
+#
+unless ($batch) {
+
+  print <<eoreqs;
+                           REQUIREMENTS
+
+The following requirements must be meet before running
+this script. See 'pod2text $0' for more details.
+
+1) A filesystem must be mounted on /vicepa. (See
+   the --partition option for alternative mount points.)
+
+2) The OpenAFS client and server binaries must be installed.
+   The init scripts to start and stop the client and servers 
+   must be installed and configured. OpenAFS/OS.pm must be 
+   configured for your system. There should be no remants
+   from a previous cell. Run afs-rmcell to remove any.
+
+3) A Kerberos realm with Kerberos4 support must be available.
+   Supported Kerberos implementations are Heimdal with
+   Kth-kerberos compatibility, MIT Kerberos 5, and 
+   Kaserver (deprecated). OpenAFS/Auth.pm must be configured
+   for your system.
+
+4) A Kerberos keytab file containing the afs principal 
+   and the administrator principal must be be present at
+   $path->{'afsconfdir'}/krb5.keytab.
+   See the asetkey man page for information about creating the
+   keytab file.  The default name of the administrator 
+   principal is 'admin'. See the --admin option for
+   alternative names.
 
-mkvol( "user", "/afs/$lcell/user" );
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part user -localauth ");
+eoreqs
 
-mkvol( "service", "/afs/$lcell/service" );
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part service -localauth ");
+  my $answer = prompt("Does your system meet these requirements? (yes/no)", "no");
+  unless ($answer=~/^y/i ) {
+    print "OK: Aborted.\n";
+  exit 0;
+  }
 
-mkvol( "rep", "/afs/$lcell/.replicated" );
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep -localauth ");
-run( "$openafsdirpath->{'afssrvbindir'}/fs mkm /afs/$lcell/replicated rep.readonly " );
+  print "\nServer options:\n"; 
+  $ostype = prompt("Which OS?", $ostype);
+  $server = prompt("What server name should be used?", $server);
+  $cellname = prompt("What cellname should be used?", $cellname);
+  $partition = prompt("What vice partition?", $partition);
+  $admin = prompt("What administrator username?", $admin);
+  if($admin =~ /@/) {
+    die "error: Please specify the username without the realm name.\n";
+  }
 
-run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part rep -localauth" );
-run( "$openafsdirpath->{'afssrvsbindir'}/vos release rep -localauth" );
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part rep.readonly -localauth ");
+  print "\nKerberos options:\n";
+  $kerberos_type = prompt("Which Kerberos is to be used?", $kerberos_type);
+  if ($kerberos_type!~/kaserver/i) {
+    $kerberos_realm  = prompt("What Kerberos realm?", $kerberos_realm);
+    $kerberos_keytab = prompt("What keytab file?", $kerberos_keytab);
+    $answer = prompt("Create OpenAFS KeyFile from a keytab? (yes/no)", "yes");
+    $skip_make_keyfile = ($answer=~/^y/i) ? 0 : 1;
+  }
 
-mkvol( "unrep", "/afs/$lcell/unreplicated" );
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part unrep -localauth ");
+  print "\nFileserver options:\n";
+  $answer = prompt("Use DAFS fileserver (requires DAFS build option)? (yes/no)", "no");
+  $with_dafs = ($answer=~/^y/i) ? 1 : 0;
+  $options_fileserver = prompt("fileserver options:", $options_fileserver);
+  $options_volserver = prompt("volserver options:",  $options_volserver);
+  $options_salvageserver = prompt("salvageserver options:",  $options_salvageserver);
+  $options_salvager = prompt("salvager options:", $options_salvager);
+
+  print "\nConfirmation:\n";
+  print "OS Type                : $ostype\n";
+  print "Server name            : $server\n";
+  print "Cell name              : $cellname\n";
+  print "Partition              : $partition\n";
+  print "Administrator          : $admin\n";
+  print "Kerberos               : $kerberos_type\n";
+  if ($kerberos_type!~/kaserver/i) {
+    print "Realm                  : $kerberos_realm\n";
+    print "Keytab file            : $kerberos_keytab\n";
+    print "Make KeyFile           : ", $skip_make_keyfile ? "yes" : "no", "\n";
+  }
+  print "DAFS fileserver        : ", $with_dafs ? "yes" : "no", "\n";
+  print "fileserver options     : $options_fileserver\n";
+  print "volserver options      : $options_volserver\n";
+  print "salvagerserver options : $options_salvageserver\n";
+  print "salvager options       : $options_salvager\n";
+  print "\n";
+
+  $answer = prompt("Continue? (yes/no)", "yes");
+  unless ($answer=~/^y/i ) {
+    print "OK: Aborted.\n";
+  exit 0;
+  }
 
-$lcell =~ /^([^.]*)/;
-my $cellpart = $1;
-run("ln -s /afs/$lcell /afs/$cellpart");
-unwind ("rm /afs/$cellpart");
-run( "ln -s /afs/.$lcell /afs/.$cellpart" );
-unwind ("rm /afs/.$cellpart");
+  # Save the options for the next time.
+  $answer = prompt("Save as command-line options? (yes/no)", "yes");
+  if ($answer=~/^y/i ) {
+    my $switches = "";
+    $switches .= "--batch";
+    $switches .= " --debug"                                          if $debug;
+    $switches .= " --dont_unwind"                                    if $dont_unwind;
+    $switches .= " --ostype='$ostype'"                               if $ostype;
+    $switches .= " --server='$server'"                               if $server;
+    $switches .= " --cellname='$cellname'"                           if $cellname;
+    $switches .= " --partition='$partition'"                         if $partition;
+    $switches .= " --admin='$admin'"                                 if $admin;
+    $switches .= " --kerberos-type='$kerberos_type'"                 if $kerberos_type;
+    $switches .= " --kerberos-realm='$kerberos_realm'"               if $kerberos_realm;
+    $switches .= " --kerberos-keytab='$kerberos_keytab'"             if $kerberos_keytab;
+    $switches .= " --skip-make-keyfile"                              if $skip_make_keyfile;
+    $switches .= " --with-dafs"                                      if $with_dafs;
+    $switches .= " --options-fileserver='$options_fileserver'"       if $options_fileserver;
+    $switches .= " --options-volserver='$options_volserver'"         if $options_volserver;;
+    $switches .= " --options-salvageserver='$options_salvageserver'" if $options_salvageserver;;
+    $switches .= " --options-salvager='$options_salvager'"           if $options_salvager;
+  
+    my $conf = prompt("Filename for save?", "afs-newcell.conf");
+    open(CONF, "> $conf") or die "error: Cannot open file $conf: $!\n";
+    print CONF "$switches\n";
+    close CONF;
+  }
+}
 
-run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.afs -localauth" );
-run( "$openafsdirpath->{'afssrvsbindir'}/vos addsite $server $part root.cell -localauth" );
-run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.afs -localauth" );
-run( "$openafsdirpath->{'afssrvsbindir'}/vos release root.cell -localauth" );
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.cell.readonly -localauth ");
-unwind( "$openafsdirpath->{'afssrvsbindir'}/vos remove $server $part root.afs.readonly -localauth ");
+if ($debug) {
+  print "debug: afs-newcell options\n";
+  print "debug:  \$batch = '$batch'\n";
+  print "debug:  \$debug = '$debug'\n";
+  print "debug:  \$dont_unwind = '$dont_unwind'\n";
+  print "debug:  \$help = '$help'\n";
+  print "debug:  \$ostype = '$ostype'\n";
+  print "debug:  \$server = '$server'\n";
+  print "debug:  \$cellname = '$cellname'\n";
+  print "debug:  \$partition = '$partition'\n";
+  print "debug:  \$admin = '$admin'\n";
+  print "debug:  \$kerberos_type = '$kerberos_type'\n";
+  print "debug:  \$kerberos_realm = '$kerberos_realm'\n";
+  print "debug:  \$kerberos_keytab = '$kerberos_keytab'\n";
+  print "debug:  \$skip_make_keyfile = '$skip_make_keyfile'\n";
+  print "debug:  \$with_dafs = '$with_dafs'\n";
+  print "debug:  \$options_fileserver = '$options_fileserver'\n";
+  print "debug:  \$options_volserver = '$options_volserver'\n";
+  print "debug:  \$options_salvageserver = '$options_salvageserver'\n";
+  print "debug:  \$options_salvager = '$options_salvager'\n";
+}
 
+# 
+# Create an auth object for the type of kerberos
+# to be used for authentication in our cell.
+#
+my $auth = OpenAFS::Auth::create(
+      'debug'=>$debug,
+      'type'=>$kerberos_type, 
+      'cell'=>$cellname,
+      'realm'=>$kerberos_realm,
+      'keytab'=>$kerberos_keytab,
+      );
+
+my $os = OpenAFS::OS::create(
+      'debug'=>$debug,
+      'ostype'=>$ostype,
+      );
+
+#
+# Sanity checks before we begin. Make sure we have correct
+# binaries, directories, and permissions.
+#
+
+my $bosserver = "$path->{'afssrvsbindir'}/bosserver";
+my $bos       = "$path->{'afssrvbindir'}/bos";
+my $fs        = "$path->{'afssrvbindir'}/fs";
+my $pts       = "$path->{'afssrvbindir'}/pts";
+my $vos       = "$path->{'afssrvsbindir'}/vos";
+
+check_program($bosserver);
+check_program($bos);
+check_program($fs);
+check_program($pts);
+check_program($vos);
+
+
+#
+# Sanity check admin username and convert kerberos 5 notation to afs.
+#
+if ($admin =~ /@/) {
+   die "error: Please specify the username without the realm name.\n";
+}
+my $username = $admin;
+$username=~s:/:.:g;   # convert kerberos separators to afs separators.
+
+# Shutdown the client and server, if running.
+run($os->command('client-stop'));
+run($os->command('fileserver-stop'));
+
+#
+# Attempt the client setup for this system before we try to create the cell.
+#
+$os->configure_client();
+
+#
+# Create the initial server configuration and the server administrator, temporarily running
+# with -noauth.
+#
+
+# bosserver attempts to create the following directories with these limited 
+# permissions. However, bosserver does not create parent directories as needed, so
+# the directories are not successfully created when they are more than one level
+# deep. 
+run("mkdir -m 0775 -p $path->{'afsconfdir'}");
+run("mkdir -m 0700 -p $path->{'afslocaldir'}");
+run("mkdir -m 0700 -p $path->{'afsdbdir'}");
+run("mkdir -m 0755 -p $path->{'afslogsdir'}"); 
+run("mkdir -m 0777 -p $path->{'viceetcdir'}");
+
+# In case the directories were created earlier with the wrong permissions.
+run("chmod 0775 $path->{'afsconfdir'}");
+run("chmod 0700 $path->{'afslocaldir'}");
+run("chmod 0700 $path->{'afsdbdir'}");
+run("chmod 0755 $path->{'afslogsdir'}"); 
+run("chmod 0777 $path->{'viceetcdir'}");
+
+print "debug: Starting bosserver...\n" if $debug;
+run("$path->{'afssrvsbindir'}/bosserver -noauth");
+    unwind($os->command('remove', "$path->{'afsconfdir'}/ThisCell"));
+    unwind($os->command('remove', "$path->{'afsconfdir'}/CellServDB"));
+    unwind($os->command('remove', "$path->{'afsconfdir'}/UserList"));
+    unwind($os->command('remove', "$path->{'afsbosconfigdir'}/BosConfig"));
+    unwind($os->command('fileserver-stop'));
+
+run("$bos setcellname $server $cellname -localauth");
+run("$bos addhost $server $server -localauth");
+run("$bos adduser $server $username -localauth");
+    unwind("$bos removeuser $server $username -localauth");
+
+#
+# Create the AFS KeyFile. (This must be done after bosserver creates the configuration files.)
+#
+unless ($skip_make_keyfile) {
+  print "debug: Making the keyfile...\n" if $debug;
+  $auth->make_keyfile();
+}
+unless ( -f "$path->{'afsconfdir'}/KeyFile") {
+  die "You do not have an AFS keyfile.  Please create this using asetkey or the bos addkey command.\n";
+}
 
+# make the krb.conf file if the realm name is different than the cell name.
+$auth->make_krb_config();
+
+#
+# Start up the ptserver and vlserver.
+#
+print "debug: Starting the ptserver and vlserver...\n" if $debug;
+run("$bos create $server ptserver simple $path->{'afssrvlibexecdir'}/ptserver -localauth");
+    unwind($os->command('remove', "$path->{'afsdbdir'}/prdb.DB0"));
+    unwind($os->command('remove', "$path->{'afsdbdir'}/prdb.DBSYS1"));
+    unwind("$bos delete $server ptserver -localauth");
+    unwind("$bos stop $server ptserver -localauth");
+
+run("$path->{'afssrvbindir'}/bos create $server vlserver simple $path->{'afssrvlibexecdir'}/vlserver -localauth");
+    unwind($os->command('remove', "$path->{'afsdbdir'}/vldb.DB0"));
+    unwind($os->command('remove', "$path->{'afsdbdir'}/vldb.DBSYS1"));
+    unwind("$bos delete $server vlserver -localauth");
+    unwind("$bos stop $server vlserver -localauth");
+
+#
+# Start the file server.
+#
+print "debug: Starting the fileserver...\n" if $debug;
+if ($with_dafs) {
+  run( "$bos create $server dafs dafs ".
+       "-cmd $path->{'afssrvlibexecdir'}/fileserver $options_fileserver ".
+       "-cmd $path->{'afssrvlibexecdir'}/volserver $options_volserver ".
+       "-cmd $path->{'afssrvlibexecdir'}/salvageserver $options_salvageserver".
+       "-cmd $path->{'afssrvlibexecdir'}/salvager $options_salvager".
+     "-localauth");
+}
+else {
+  run( "$bos create $server fs fs ".
+       "-cmd $path->{'afssrvlibexecdir'}/fileserver $options_fileserver ".
+       "-cmd $path->{'afssrvlibexecdir'}/volserver $options_volserver ".
+       "-cmd $path->{'afssrvlibexecdir'}/salvager $options_salvager ".
+     "-localauth");
+}
+  unwind("$bos delete $server fs -localauth ");
+  unwind("$bos stop $server fs -localauth ");
+
+#
+# Create the AFS administrator (with the same name as the server administrator).
+#
+print "debug: Creating users...\n" if $debug;
+sleep(10); # wait to avoid "no quorum elected" errors.
+
+run("$pts createuser -name $username -cell $cellname -noauth");
+run("$pts adduser $username system:administrators -cell $cellname -noauth");
+run("$pts membership $username -cell $cellname -noauth");
+
+#
+# Create the root afs volume.
+#
+print "debug: Creating root.afs volume...\n" if $debug;
+run("$vos create $server $partition root.afs -cell $cellname -noauth");
+    unwind($os->command('remove', "$partition/AFSIDat "));
+    unwind($os->command('remove', "$partition/V*.vol"));
+    unwind($os->command('remove', "$partition/Lock"));
+    unwind("$vos remove $server $partition root.afs -cell $cellname -noauth");
+
+# The initial configuration is done, turn on authorization checking.
+#run("$bos setauth $server -authrequired on -cell $cellname -localauth");
+#    unwind("$bos setauth $server -authrequired off -cell $cellname -localauth");
+
+
+#
+# Bring up the AFS client.
+#
+print "debug: Starting the OpenAFS client...\n" if $debug;
+run($os->command('client-start'));
+    unwind($os->command('client-stop'));
+
+#
+# Run as the administrator.
+#
+$auth->authorize($admin);
+
+#
+# Create the root cell volumes, read-only and read-write.
+#
+print "debug: Creating the root volumes...\n" if $debug;
+run("$fs setacl /afs system:anyuser rl");
+
+run("$vos create $server $partition root.cell -localauth");
+    unwind("$vos remove $server $partition root.cell -localauth");
+
+run("$fs mkmount /afs/$cellname root.cell -cell $cellname -fast");
+    unwind("$fs rmmount /afs/$cellname");
+
+run("$fs setacl /afs/$cellname system:anyuser rl");
+run("$fs mkmount /afs/.$cellname root.cell -cell $cellname -rw");
+    unwind("$fs rmmount /afs/.$cellname");
+
+#run("$fs mkmount /afs/.root.afs root.afs -rw");
+#    unwind("$fs rmmmount /afs/.root.afs");
+
+#
+# Create some volumes in our new cell.
+#
+print "debug: Creating the test volumes...\n" if $debug;
+mkvol("user", "/afs/$cellname/user", $server, $partition);
+mkvol("service", "/afs/$cellname/service", $server, $partition);
+mkvol("unrep", "/afs/$cellname/unreplicated", $server, $partition);
+
+# make a read-only volume
+mkvol("rep", "/afs/$cellname/.replicated", $server, $partition);
+run("$fs mkmount /afs/$cellname/replicated rep.readonly");
+run("$vos addsite $server $partition rep -localauth");
+run("$vos release rep -localauth");
+    unwind("$vos remove $server $partition rep.readonly -localauth");
+
+
+#
+# Create readonly volumes of our roots.
+#
+run("$vos addsite $server $partition root.afs -localauth");
+run("$vos addsite $server $partition root.cell -localauth");
+run("$vos release root.afs -localauth");
+run("$vos release root.cell -localauth");
+    unwind("$vos remove $server $partition root.cell.readonly -localauth");
+    unwind("$vos remove $server $partition root.afs.readonly -localauth");
+
+# done.
+@unwinds = (); # clear unwinds
 
-@unwinds = ();
 END {
-# If we fail before all the instances are created, we need to perform 
-# our own bos shutdown
-    system("$openafsdirpath->{'afssrvbindir'}/bos shutdown $server -localauth") if $shutdown_needed;
-  run(pop @unwinds) while @unwinds;
+  if (!$dont_unwind && scalar @unwinds) {
+    print "\ninfo: Error encountered, unwinding...\n"; 
+    while (@unwinds) {
+      eval { 
+        run(pop(@unwinds));
+      };
+      if ($@) {
+        print "warn: Unwind command failed.\n$@\n"; 
+      }
+    }
   }
+}
index 3477593..f0cc29a 100755 (executable)
@@ -11,7 +11,7 @@ my ($host, $ret);
 $host = `hostname`;
 &AFS_Init();
 
-&AFS_vos_restore("badvol","localhost","a","/usr/tmp/t.uniq-bad","100","full",);
+&AFS_vos_restore("badvol","localhost","a","/tmp/t.uniq-bad","100","full",);
 &AFS_bos_salvage("localhost","a","badvol",,,,,,);
 &AFS_fs_mkmount("badvol", "badvol",,,);
 if ( -f "badvol/test" ) {
index 37a3487..f679b12 100755 (executable)
@@ -15,11 +15,11 @@ $host = `hostname`;
 &AFS_Init();
 
 &AFS_bos_exec(localhost,"$openafsdirpath->{'afssrvbindir'}/foo.sh",);
-if (-f "/usr/tmp/garbage") {
+if (-f "/tmp/garbage") {
 } else {
     exit(1);
 }
-unlink "/usr/tmp/garbage";
+unlink "/tmp/garbage";
 exit(0);
 
 
index ddaa7c2..2bba178 100755 (executable)
@@ -13,7 +13,7 @@ $host = `hostname`;
 
 open(FOO, ">foo.sh"); 
 print FOO "#!/bin/sh\n";
-print FOO "touch /usr/tmp/garbage\n";
+print FOO "touch /tmp/garbage\n";
 print FOO "exit 0\n";
 close FOO;
 chmod 0755, "foo.sh";
index a5f5790..3242583 100755 (executable)
@@ -1,11 +1,11 @@
 #!/bin/sh
 FS=${FS:-${objdir}/../appl/fs/fs}
 ${FS} sa . system:anyuser all || exit 1
-${objdir}/write-rand /usr/tmp/$$ 262144 || exit 1
-${objdir}/afscp -i -b 56k /usr/tmp/$$ `pwd`/$$ || exit 1
-diff /usr/tmp/$$ `pwd`/$$ || exit 1
-${objdir}/afscp -i -b 32k /usr/tmp/$$ `pwd`/$$ || exit 1
-diff /usr/tmp/$$ `pwd`/$$ || exit 1
+${objdir}/write-rand /tmp/$$ 262144 || exit 1
+${objdir}/afscp -i -b 56k /tmp/$$ `pwd`/$$ || exit 1
+diff /tmp/$$ `pwd`/$$ || exit 1
+${objdir}/afscp -i -b 32k /tmp/$$ `pwd`/$$ || exit 1
+diff /tmp/$$ `pwd`/$$ || exit 1
 exit 0
 
 
index 0347dd8..19f0d1e 100755 (executable)
@@ -2,10 +2,10 @@
 FS=${FS:-${objdir}/../appl/fs/fs}
 ${FS} sa . system:anyuser all || exit 1
 ${objdir}/write-rand $$ 262144 || exit 1
-${objdir}/afscp -o -b 56k `pwd`/$$ /usr/tmp/$$ || exit 1
-diff /usr/tmp/$$ `pwd`/$$ || exit 1
-${objdir}/afscp -o -b 32k `pwd`/$$ /usr/tmp/$$ || exit 1
-diff /usr/tmp/$$ `pwd`/$$ || exit 1
+${objdir}/afscp -o -b 56k `pwd`/$$ /tmp/$$ || exit 1
+diff /tmp/$$ `pwd`/$$ || exit 1
+${objdir}/afscp -o -b 32k `pwd`/$$ /tmp/$$ || exit 1
+diff /tmp/$$ `pwd`/$$ || exit 1
 exit 0
 
 
index 3a1ab1b..65d4e81 100644 (file)
@@ -5,7 +5,10 @@ if test "X$FAST" != "X" ; then echo "Not running $0" ;  exit 0 ; fi
 
 FS=${FS:-${objdir}/../appl/fs/fs}
 
+# Should not be able to create a hardlink across volumes. In this test
+# ../../service is mounted on the separate volume. Suppress the expected
+# error message from the ln command which clutters the test output.
 touch file
-ln file ../../service/file && exit 1
+ln file ../../service/file 2>/dev/null && (echo "hardlink ../../service/file should not have been created"; exit 1)
 rm file
 
index 8ff8039..7aa9f24 100755 (executable)
@@ -1,12 +1,34 @@
 #!/usr/bin/env perl
-use Term::ReadLine;
 use strict;
-use OpenAFS::ConfigUtils;
+use warnings;
 use OpenAFS::Dirpath;
-use OpenAFS::OS;
 use OpenAFS::Auth;
 use Getopt::Long;
-use vars qw($admin $server $cellname $cachesize $part
-          $requirements_met  $shutdown_needed $csdb);
 
-&OpenAFS::Auth::authadmin();
+# options
+my $debug = 0;
+my $cellname = 'testcell';
+my $admin = 'admin';
+my $kerberos_type = 'MIT';
+my $kerberos_realm = 'TESTCELL';
+my $kerberos_keytab = "$openafsdirpath->{'afsconfdir'}/krb5.keytab";
+
+GetOptions (
+       "debug!" => \$debug,
+       "cellname=s" => \$cellname, 
+       "admin=s" => \$admin,
+       "kerberos-type=s" => \$kerberos_type,
+       "kerberos-realm=s" => \$kerberos_realm,
+       "kerberos-keytab=s" => \$kerberos_keytab,
+       );
+
+my $auth = OpenAFS::Auth::create(
+      'debug'=>$debug,
+      'type'=>$kerberos_type, 
+      'cell'=>$cellname,
+      'realm'=>$kerberos_realm,
+      'keytab'=>$kerberos_keytab,
+      );
+
+# Run as the administrator.
+$auth->authorize($admin);
index 13540b8..600e038 100755 (executable)
@@ -2,6 +2,19 @@
 #
 # $Id$
 #
+
+# Directory paths configured during the build.
+if test -f dirpath.conf; then
+  . dirpath.conf
+else
+  echo "error: Missing dirpath.conf file, try make dirpath.conf"
+fi
+
+if test -f run-test.conf; then
+  . run-test.conf
+fi  
+
+
 srcdir=@srcdir@
 objdir=`pwd`
 SHELL=/bin/sh
@@ -9,13 +22,22 @@ SHELLVERBOSE=
 VERSION=@VERSION@
 PACKAGE=@PACKAGE@
 host=@host@
-RUNAS=nobody
-FS=@afssrvbindir@/fs
+RUNAS=
+FS=${afssrvbindir}/fs
+CELLNAME=${CELLNAME-testcell}
 export FS
 export SHELL
 
+
+PERL5LIB=${PERL5LIB-`pwd`}
 AFSROOT=${AFSROOT-/afs}
+TESTDIR=${TESTDIR-unreplicated}
+WORKDIR=$AFSROOT/$CELLNAME/$TESTDIR
 export AFSROOT
+export TESTDIR
+export WORKDIR
+export PERL5LIB
+
 
 BASIC_TESTS="creat1                    \
            mkdir1                      \
@@ -55,8 +77,7 @@ ACL_TESTS="acladduser.pl              \
            aclcopy.pl"
 
 EXEC_TESTS="exec                       \
-           hello-world                 \
-           build-openafs"
+           hello-world"
 
 MMAP_TESTS="append-over-page           \
            mmap-shared-write           \
@@ -184,7 +205,6 @@ ALL_TESTS="creat1                   \
            aclcopy.pl                  \
            exec                        \
            hello-world                 \
-           build-openafs               \
            append-over-page            \
            mmap-shared-write           \
            mmap-vs-read2               \
@@ -285,7 +305,7 @@ do
   -large) LARGE=yes;;
   -j) PARALLELL="&";;
   -verbose) VERBOSE=yes;;
-  -user) RUNAS=$1; shift;;
+  -user) RUNAS=$2; shift;;
   -x) SHELLVERBOSE="-x";;
   -p) PRINT_CACHESIZE="yes";;
   -basic) TESTS="$BASIC_TESTS";TEST_MODE="basic";;
@@ -386,7 +406,9 @@ for a in $RUNTESTS; do
   if test "$a" = "setgroups" ; then
      b="${objdir}/asu root $b"
   else
-     b="${objdir}/asu $RUNAS $b"
+     if test "X$RUNAS" != "X" ; then
+        b="${objdir}/asu $RUNAS $b"
+        fi 
   fi
   tmpdir="`hostname`-$a-`date +%Y-%m-%d-%H-%M-%S`-$$"
   cd $WORKDIR && mkdir $tmpdir && (cd $tmpdir && $b ${PARALLELL})
@@ -412,8 +434,10 @@ date
 if test "$FAILEDTESTS"; then
   echo "-----------------------------------------------------------"
   echo "Failed test(s) were: $FAILEDTESTS"
+  exitval=1
 else
   echo "All test(s) were succesful!"
+  exitval=0
 fi
 
 exit $exitval
index eabc5a2..5fa152d 100755 (executable)
@@ -11,7 +11,7 @@ my ($host, $ret);
 $host = `hostname`;
 &AFS_Init();
 
-&AFS_vos_dump("service",0,"/usr/tmp/service.dump",);
+&AFS_vos_dump("service",0,"/tmp/service.dump",);
 
 exit(0);
 
index 9ab0d93..2827571 100755 (executable)
@@ -11,7 +11,7 @@ my ($host, $ret);
 $host = `hostname`;
 &AFS_Init();
 
-&AFS_vos_restore("service2","localhost","a","/usr/tmp/service.dump",,"full",);
+&AFS_vos_restore("service2","localhost","a","/tmp/service.dump",,"full",);
 
 exit(0);