Skip to content

Commit

Permalink
add option -y, write a disk_var.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Lange committed Sep 17, 2018
1 parent b053fe2 commit b3314b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 22 additions & 2 deletions bin/setup-storage
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ $|=1;
use Getopt::Std;
$main::VERSION = $version;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
our ($opt_X, $opt_f, $opt_h, $opt_d, $opt_s, $opt_D, $opt_L); # the variables for getopt
(&getopts('Xf:hdsD:L:') && !$opt_h) || die <<EOF;
our ($opt_X, $opt_f, $opt_h, $opt_d, $opt_s, $opt_D, $opt_L,$opt_y); # the variables for getopt
(&getopts('Xf:hdsD:L:y') && !$opt_h) || die <<EOF;
setup-storage version $version
USAGE: [-X] no test, your harddisks will be formated
Expand All @@ -71,6 +71,7 @@ USAGE: [-X] no test, your harddisks will be formated
[-D<disks>] override disklist variable by space-separated <disks>
[-L<logdir>] use <logdir> instead of LOGDIR variable
[-h] print this help message
[-y] print disk variables as YAML file into disk_var.yml
EOF

# include all subparts, which are part of the FAI perl package
Expand Down Expand Up @@ -264,6 +265,25 @@ if ($FAI::no_dry_run) {
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;

if ($opt_y) {
open(DISK_YML, ">$FAI::DATADIR/disk_var.yml")
or die "Unable to write to file $FAI::DATADIR/disk_var.yml\n";

print DISK_YML "---\n# disk_var.sh as YAML\n";
foreach (keys %FAI::disk_var) {
$FAI::disk_var{$_} =~ s/"//g;
if ( $FAI::disk_var{$_} =~ m/\s/ ) {
# print an array
print DISK_YML "$_:\n";
my $a = join("\n - ", split(/ /,$FAI::disk_var{$_}));
print DISK_YML " - $a\n";
} else {
print DISK_YML "$_: $FAI::disk_var{$_}\n";
}
}
close DISK_YML;
}
}

# print crypttab
Expand Down
4 changes: 4 additions & 0 deletions man/setup-storage.8
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Use the specified directory instead of
.TP
\fB\-h\fP
Display the synopsis and version info and exit.

.TP
\fB\-y\fP
Print disk variables as YAML file into disk_var.yml
.SH ENVIRONMENT
\fBsetup-storage\fP
will use the following environment variables:
Expand Down

0 comments on commit b3314b7

Please sign in to comment.