]> birchwood-abbey.net Git - Network.git/commitdiff
Handle zero arguments to the ./abbey command quietly.
authorMatt Birkholz <matt@birchwood-abbey.net>
Mon, 22 Dec 2025 16:02:53 +0000 (09:02 -0700)
committerMatt Birkholz <matt@birchwood-abbey.net>
Mon, 22 Dec 2025 16:02:53 +0000 (09:02 -0700)
Avoid lots of warnings about undefined ~$ARGV[0]~.

README.org
abbey

index 5a5184aaed1085b73126edd8d81590d66801050d..f2cb1e8333756bf50487d6b06e8ec07dfd61da04 100644 (file)
@@ -2848,7 +2848,8 @@ The script begins with the following prefix and trampolines.
 
 use strict;
 
-if (grep { $_ eq $ARGV[0] } qw(CA config new old pass client)) {
+if (defined $ARGV[0]
+    && grep { $_ eq $ARGV[0] } qw(CA config new old pass client)) {
   exec "./Institute/inst", @ARGV;
 }
 #+END_SRC
@@ -2888,7 +2889,7 @@ a limit pattern.  For example:
 #+CAPTION: [[file:abbey][=abbey=]]
 #+BEGIN_SRC perl :tangle abbey
 
-if ($ARGV[0] eq "upgrade") {
+if (defined $ARGV[0] && $ARGV[0] eq "upgrade") {
   shift;
   my @args = ( "-e", "\@Secret/become.yml" );
   if (defined $ARGV[0] && $ARGV[0] eq "-n") {
@@ -2938,7 +2939,7 @@ The script implements a ~reboots~ sub-command that looks for
 
 #+CAPTION: [[file:abbey][=abbey=]]
 #+BEGIN_SRC perl :tangle abbey
-if ($ARGV[0] eq "reboots") {
+if (defined $ARGV[0] && $ARGV[0] eq "reboots") {
   exec ("ansible-playbook", "-e", "\@Secret/become.yml",
        "playbooks/reboots.yml");
 }
@@ -2966,7 +2967,7 @@ operating system version of all abbey managed machines.
 
 #+CAPTION: [[file:abbey][=abbey=]]
 #+BEGIN_SRC perl :tangle abbey
-if ($ARGV[0] eq "versions") {
+if (defined $ARGV[0] && $ARGV[0] eq "versions") {
   exec ("ansible-playbook", "-e", "\@Secret/become.yml",
        "playbooks/versarch.yml");
 }
@@ -2990,7 +2991,7 @@ The script implements a ~facts~ sub-command to collect the Ansible
 
 #+CAPTION: [[file:abbey][=abbey=]]
 #+BEGIN_SRC perl :tangle abbey
-if ($ARGV[0] eq "facts") {
+if (defined $ARGV[0] && $ARGV[0] eq "facts") {
   my $line = ("ansible all -m gather_facts -e \@Secret/become.yml"
              . " >facts");
   print "$line\n";
@@ -3021,7 +3022,7 @@ last host in the previous play.
 
 #+CAPTION: [[file:abbey][=abbey=]]
 #+BEGIN_SRC perl :tangle abbey
-if ($ARGV[0] eq "tz") {
+if (defined $ARGV[0] && $ARGV[0] eq "tz") {
   exec ("ansible-playbook", "-e", "\@Secret/become.yml",
        "playbooks/timezone.yml");
 }
diff --git a/abbey b/abbey
index e44a032d2fed0fb176c82335799b697e01785387..8b9e890b213a8d4df91ee8c2cc8a82130db1d776 100755 (executable)
--- a/abbey
+++ b/abbey
@@ -4,11 +4,12 @@
 
 use strict;
 
-if (grep { $_ eq $ARGV[0] } qw(CA config new old pass client)) {
+if (defined $ARGV[0]
+    && grep { $_ eq $ARGV[0] } qw(CA config new old pass client)) {
   exec "./Institute/inst", @ARGV;
 }
 
-if ($ARGV[0] eq "upgrade") {
+if (defined $ARGV[0] && $ARGV[0] eq "upgrade") {
   shift;
   my @args = ( "-e", "\@Secret/become.yml" );
   if (defined $ARGV[0] && $ARGV[0] eq "-n") {
@@ -25,17 +26,17 @@ if ($ARGV[0] eq "upgrade") {
   exec ("ansible-playbook", @args, "playbooks/upgrade.yml");
 }
 
-if ($ARGV[0] eq "reboots") {
+if (defined $ARGV[0] && $ARGV[0] eq "reboots") {
   exec ("ansible-playbook", "-e", "\@Secret/become.yml",
        "playbooks/reboots.yml");
 }
 
-if ($ARGV[0] eq "versions") {
+if (defined $ARGV[0] && $ARGV[0] eq "versions") {
   exec ("ansible-playbook", "-e", "\@Secret/become.yml",
        "playbooks/versarch.yml");
 }
 
-if ($ARGV[0] eq "facts") {
+if (defined $ARGV[0] && $ARGV[0] eq "facts") {
   my $line = ("ansible all -m gather_facts -e \@Secret/become.yml"
              . " >facts");
   print "$line\n";
@@ -44,7 +45,7 @@ if ($ARGV[0] eq "facts") {
   exit;
 }
 
-if ($ARGV[0] eq "tz") {
+if (defined $ARGV[0] && $ARGV[0] eq "tz") {
   exec ("ansible-playbook", "-e", "\@Secret/become.yml",
        "playbooks/timezone.yml");
 }