[Fai-commit] r6406 - in trunk: bin lib/setup-storage man

Michael Tautschnig mt at alioth.debian.org
Fri Apr 15 13:02:31 UTC 2011


Author: mt
Date: 2011-04-15 13:02:27 +0000 (Fri, 15 Apr 2011)
New Revision: 6406

Modified:
   trunk/bin/setup-storage
   trunk/lib/setup-storage/Commands.pm
   trunk/lib/setup-storage/Exec.pm
   trunk/lib/setup-storage/Init.pm
   trunk/lib/setup-storage/Volumes.pm
   trunk/man/setup-storage.8
Log:
setup-storage: If $disklist or $LOGDIR are not provided, find sane default values.

* setup-storage,setup-storage/{Init,Commands,Volumes,Exec}.pm: Do not require
  that $disklist and $LOGDIR are provided by the environment, compute input
  values via disk-info and default to /tmp/fai for $LOGDIR.
* setup-storage.8: Correspondingly updated documentation.


Modified: trunk/bin/setup-storage
===================================================================
--- trunk/bin/setup-storage	2011-04-15 12:58:38 UTC (rev 6405)
+++ trunk/bin/setup-storage	2011-04-15 13:02:27 UTC (rev 6406)
@@ -70,20 +70,6 @@
        [-h]                     print this help message
 EOF
 
-################################################################################
-#
-# @brief Really write any changes to disk
-#
-################################################################################
-if ($opt_X) {
-  # we use $ENV{LOGDIR} later on, make sure it is actually set
-  defined ($ENV{LOGDIR}) or die "Environment variable LOGDIR is not set\n";
-  $FAI::no_dry_run = 1;
-} else {
-  warn "setup-harddisks is running in test-only mode\n";
-  $FAI::no_dry_run = 0;
-}
-
 # include all subparts, which are part of the FAI perl package
 use lib "/usr/share/fai/setup-storage/";
 use Init;
@@ -97,11 +83,32 @@
 # enable debug mode, if requested using -d
 $opt_d and $FAI::debug = 1;
 
-# $disklist must be provided by the environment
-defined ($ENV{disklist}) or die "Environment variable disklist is not set\n";
- at FAI::disks = split( /\n/, $ENV{disklist} );
-print "disklist was: $ENV{disklist}\n" if ($FAI::debug);
+# Really write any changes to disk
+$opt_X and $FAI::no_dry_run = 1;
+warn "setup-storage is running in test-only mode\n" unless ($FAI::no_dry_run);
 
+# Find out whether $LOGDIR is usable or default to /tmp/fai
+if (! -d $FAI::DATADIR) {
+  defined ($ENV{LOGDIR}) and die
+    "Environment variable LOGDIR is set, but $FAI::DATADIR is not a directory\n";
+  mkdir $FAI::DATADIR or die
+    "Failed to create directory $FAI::DATADIR\n";
+  warn "\$LOGDIR not set in environment; created data directory $FAI::DATADIR\n";
+}
+
+# $disklist may be provided by the environment
+my $disklist = $ENV{disklist};
+if (! defined($disklist)) {
+  &FAI::in_path("disk-info") or die "disk-info not found in PATH\n";
+  $disklist = `disk-info | sort`;
+}
+
+ at FAI::disks = split( /\n/, $disklist);
+if ($FAI::debug) {
+  print "disklist: ";
+  print "$_\n" foreach(@FAI::disks);
+}
+
 # the config source file
 my $config_file = undef;
 # use the config file, if given
@@ -223,23 +230,23 @@
 # print fstab
 $FAI::debug and print "$_\n" foreach (@fstab);
 
-# write the proposed contents of fstab to $LOGDIR/fstab
+# write the proposed contents of fstab to $FAI::DATADIR/fstab
 if ($FAI::no_dry_run) {
-  open(FSTAB, ">$ENV{LOGDIR}/fstab")
-    or die "Failed to open $ENV{LOGDIR}/fstab for writing\n";
+  open(FSTAB, ">$FAI::DATADIR/fstab")
+    or die "Failed to open $FAI::DATADIR/fstab for writing\n";
   print FSTAB "$_\n" foreach (@fstab);
   close FSTAB;
 }
 
-# write variables to $LOGDIR/disk_var.sh
+# write variables to $FAI::DATADIR/disk_var.sh
 # debugging
 $FAI::debug and print "$_=\${$_:-$FAI::disk_var{$_}}\n"
   foreach (keys %FAI::disk_var);
 
 if ($FAI::no_dry_run)
 {
-  open(DISK_VAR, ">$ENV{LOGDIR}/disk_var.sh")
-    or die "Unable to write to file $ENV{LOGDIR}/disk_var.sh\n";
+  open(DISK_VAR, ">$FAI::DATADIR/disk_var.sh")
+    or die "Unable to write to file $FAI::DATADIR/disk_var.sh\n";
   print DISK_VAR "$_=\${$_:-$FAI::disk_var{$_}}\n" foreach (keys %FAI::disk_var);
   close DISK_VAR;
 }
@@ -247,10 +254,10 @@
 # print crypttab
 $FAI::debug and print "$_\n" foreach (@FAI::crypttab);
 
-# write the proposed contents of fstab to $LOGDIR/fstab
+# write the proposed contents of fstab to $FAI::DATADIR/fstab
 if ($FAI::no_dry_run && scalar(@FAI::crypttab)) {
-  open(CRYPTTAB, ">$ENV{LOGDIR}/crypttab")
-    or die "Failed to open $ENV{LOGDIR}/crypttab for writing\n";
+  open(CRYPTTAB, ">$FAI::DATADIR/crypttab")
+    or die "Failed to open $FAI::DATADIR/crypttab for writing\n";
   print CRYPTTAB "$_\n" foreach (@FAI::crypttab);
   close CRYPTTAB;
 }

Modified: trunk/lib/setup-storage/Commands.pm
===================================================================
--- trunk/lib/setup-storage/Commands.pm	2011-04-15 12:58:38 UTC (rev 6405)
+++ trunk/lib/setup-storage/Commands.pm	2011-04-15 13:02:27 UTC (rev 6406)
@@ -233,7 +233,7 @@
       }
 
       if ($mode =~ /^luks(:"([^"]+)")?$/) {
-        my $keyfile = "$ENV{LOGDIR}/$enc_dev_short_name";
+        my $keyfile = "$FAI::DATADIR/$enc_dev_short_name";
 
         # generate a key for encryption
         &FAI::push_command(
@@ -291,7 +291,7 @@
 sub build_raid_commands {
 
   # check RAID arrays if there are pre-existing ones
-  &FAI::push_command("mdadm --assemble --scan --config=$ENV{LOGDIR}/mdadm-from-examine.conf",
+  &FAI::push_command("mdadm --assemble --scan --config=$FAI::DATADIR/mdadm-from-examine.conf",
     "", "mdadm_startall_examined") if (scalar(keys %FAI::current_raid_config));
   foreach my $id (keys %FAI::current_raid_config) {
     my $md = "/dev/md$id";

Modified: trunk/lib/setup-storage/Exec.pm
===================================================================
--- trunk/lib/setup-storage/Exec.pm	2011-04-15 12:58:38 UTC (rev 6405)
+++ trunk/lib/setup-storage/Exec.pm	2011-04-15 13:02:27 UTC (rev 6406)
@@ -182,7 +182,7 @@
     message      => "mdadm tried to assemble arrays but failed, ignoring as arrays might be running already\n",
     stderr_regex => '^$',
     stdout_regex => '^$',
-    program      => "mdadm --assemble --scan --config=$ENV{LOGDIR}/mdadm-from-examine.conf",
+    program      => "mdadm --assemble --scan --config=$FAI::DATADIR/mdadm-from-examine.conf",
     response     => "warn",
     exit_codes   => [2],
   },

Modified: trunk/lib/setup-storage/Init.pm
===================================================================
--- trunk/lib/setup-storage/Init.pm	2011-04-15 12:58:38 UTC (rev 6405)
+++ trunk/lib/setup-storage/Init.pm	2011-04-15 13:02:27 UTC (rev 6406)
@@ -45,10 +45,25 @@
 #
 ################################################################################
 $FAI::debug = 0;
-defined( $ENV{debug} ) and $FAI::debug = $ENV{debug};
+defined ($ENV{debug}) and $FAI::debug = $ENV{debug};
 
 ################################################################################
 #
+# @brief Directory to store generated files such as fstab, crypttab
+#
+################################################################################
+$FAI::DATADIR = "/tmp/fai";
+defined ($ENV{LOGDIR}) and $FAI::DATADIR = $ENV{LOGDIR};
+
+################################################################################
+#
+# @brief Write changes to disk only if set to 1
+#
+################################################################################
+$FAI::no_dry_run = 0;
+
+################################################################################
+#
 # @brief The command to tell udev to settle (udevsettle or udevadm settle)
 #
 ################################################################################

Modified: trunk/lib/setup-storage/Volumes.pm
===================================================================
--- trunk/lib/setup-storage/Volumes.pm	2011-04-15 12:58:38 UTC (rev 6405)
+++ trunk/lib/setup-storage/Volumes.pm	2011-04-15 13:02:27 UTC (rev 6406)
@@ -459,7 +459,7 @@
 #    devices=/dev/sde3,/dev/sdf3,/dev/sdd3
 
   # create a temporary mdadm-from-examine.conf
-  open(MDADM_EX, ">$ENV{LOGDIR}/mdadm-from-examine.conf");
+  open(MDADM_EX, ">$FAI::DATADIR/mdadm-from-examine.conf");
 
   # the id of the RAID
   my $id;

Modified: trunk/man/setup-storage.8
===================================================================
--- trunk/man/setup-storage.8	2011-04-15 12:58:38 UTC (rev 6405)
+++ trunk/man/setup-storage.8	2011-04-15 13:02:27 UTC (rev 6406)
@@ -69,9 +69,9 @@
 .B disklist
 The
 .IR disklist
-variable must contain a newline separated list of disk drives available in the
+variable may contain a newline separated list of disk drives available in the
 system. Their order matters as they may be referred to as disk1, etc. in
-disk_config.
+disk_config. If unset, disk-info will be called to determine the list.
 .TP
 .B debug
 If
@@ -88,7 +88,8 @@
 .TP
 .B LOGDIR
 \fBsetup-storage\fP
-generates disk_var.sh and fstab (see below) in this directory.
+generates disk_var.sh, fstab, and possibly crypttab (see below) in this
+directory. Defaults to /tmp/fai if unset.
 .TP
 .B flag_initial
 This variable determines if partitions should be preserved when they
@@ -110,6 +111,9 @@
 The latter two describe the partition and disk/RAID/LVM device hosting the mount
 point for /boot. If /boot has no extra mount point, / is used instead.
 You may source $LOGDIR/disk_var.sh to get the variables set.
+Furthermore, if encryption was configured, a proper
+\fBcrypttab\fP(5)
+file plus keyfiles will be generated.
 .SH SYNTAX
 This section describes the syntax of disk_config files
 




More information about the Fai-commit mailing list