aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2021-02-19 18:52:33 +0100
committerGuilhem Moulin <guilhem@fripost.org>2021-02-20 20:16:34 +0100
commit3e49ef22ba3fbbe4e73bc4ad151770603ffa5ef1 (patch)
treef6717683f11f606405d40dd9055cdc5f9b9b4b8d
parent95534d55bd27ec9311a484ddc4e4a550191aa496 (diff)
lacme-accountd: Don't error out when the default configuration file is missing.
Instead, treat it as an empty file. This makes it possible to use lacme-accountd(1) without configuration file under ~/.config/lacme.
-rwxr-xr-xlacme-accountd23
-rw-r--r--lacme-accountd.1.md9
2 files changed, 19 insertions, 13 deletions
diff --git a/lacme-accountd b/lacme-accountd
index 1dc5f03..b9a6e33 100755
--- a/lacme-accountd
+++ b/lacme-accountd
@@ -69,16 +69,19 @@ do {
( ($ENV{XDG_CONFIG_HOME} // "$ENV{HOME}/.config") . "/lacme/$NAME.conf"
, "@@sysconfdir@@/lacme/$NAME.conf"
);
- die "Error: Can't find configuration file\n" unless defined $conffile;
- print STDERR "Using configuration file: $conffile\n" if $OPTS{debug};
-
- my $h = Config::Tiny::->read($conffile) or die Config::Tiny::->errstr()."\n";
- my $h2 = delete $h->{_} // {};
- die "Invalid section(s): ".join(', ', keys %$h)."\n" if %$h;
- my %h = map { $_ => delete $h2->{$_} } qw/privkey gpg socket quiet/;
- die "Unknown option(s): ".join(', ', keys %$h2)."\n" if %$h2;
- $h{quiet} = lc $h{quiet} eq 'yes' ? 1 : 0 if defined $h{quiet};
- $OPTS{$_} //= $h{$_} foreach grep {defined $h{$_}} keys %h;
+
+ if (defined $OPTS{config} or -e $conffile) {
+ print STDERR "Using configuration file: $conffile\n" if $OPTS{debug};
+ my $h = Config::Tiny::->read($conffile) or die Config::Tiny::->errstr()."\n";
+ my $h2 = delete $h->{_} // {};
+ die "Invalid section(s): ".join(', ', keys %$h)."\n" if %$h;
+ my %h = map { $_ => delete $h2->{$_} } qw/privkey gpg socket quiet/;
+ die "Unknown option(s): ".join(', ', keys %$h2)."\n" if %$h2;
+ $h{quiet} = lc $h{quiet} eq 'yes' ? 1 : 0 if defined $h{quiet};
+ $OPTS{$_} //= $h{$_} foreach grep {defined $h{$_}} keys %h;
+ } else {
+ print STDERR "Ignoring missing configuration file at default location $conffile\n" if $OPTS{debug};
+ }
$OPTS{quiet} = 0 if $OPTS{debug};
die "Error: 'privkey' is not specified\n" unless defined $OPTS{privkey};
diff --git a/lacme-accountd.1.md b/lacme-accountd.1.md
index e628476..5303418 100644
--- a/lacme-accountd.1.md
+++ b/lacme-accountd.1.md
@@ -41,9 +41,12 @@ Options
`--config=`*filename*
-: Use *filename* as configuration file. See the **[configuration
- file](#configuration-file)** section below for the configuration
- options.
+: Use *filename* as configuration file. `lacme-accountd` fails when
+ `--config=` is used with a non-existent file, but a non-existent
+ default location is treated as if it were an empty file.
+
+ See the **[configuration file](#configuration-file)** section below
+ for the configuration options.
`--privkey=`*value*