Skip to content

Commit

Permalink
add option -p
Browse files Browse the repository at this point in the history
this is similar to dry-mode but the commands are printed without a
prefix in each line and -p stops directly after printing
  • Loading branch information
Mrfai committed Feb 16, 2024
1 parent 6d2143b commit 0e59e98
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bin/setup-storage
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,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,$opt_y); # the variables for getopt
(&getopts('Xf:hdsD:L:y') && !$opt_h) || die <<EOF;
our ($opt_X, $opt_f, $opt_h, $opt_d, $opt_s, $opt_D, $opt_L,$opt_y,$opt_p); # the variables for getopt
(&getopts('Xf:hdsD:L:yp') && !$opt_h) || die <<EOF;
setup-storage version $version
USAGE: [-X] no test, your harddisks will be formated
Expand All @@ -68,6 +68,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
[-p] print the commands that would be executed, then exit.
[-y] print disk variables as YAML file into disk_var.yml
EOF

Expand Down Expand Up @@ -222,6 +223,16 @@ if ($FAI::debug) {
}
}

# only print the commands that would be executed
if ($opt_p) {
print "These commands would be executed:\n";
foreach (&numsort(keys %FAI::commands)) {
next if ($FAI::commands{$_}{cmd} eq "true");
print "$FAI::commands{$_}{cmd}\n";
}
exit 0;
}

# run the commands (if $FAI::no_dry_run is set)
foreach (&numsort(keys %FAI::commands)) {
`$FAI::udev_settle`;
Expand Down

0 comments on commit 0e59e98

Please sign in to comment.