From: Matt Birkholz Date: Mon, 22 Dec 2025 16:02:53 +0000 (-0700) Subject: Handle zero arguments to the ./abbey command quietly. X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=8e3847c341ecc904cc825ac074b12ca10e1a1231;p=Network.git Handle zero arguments to the ./abbey command quietly. Avoid lots of warnings about undefined ~$ARGV[0]~. --- diff --git a/README.org b/README.org index 5a5184a..f2cb1e8 100644 --- a/README.org +++ b/README.org @@ -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 e44a032..8b9e890 100755 --- 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"); }