diff options
| author | Guilhem Moulin <guilhem@fripost.org> | 2021-02-19 18:52:33 +0100 | 
|---|---|---|
| committer | Guilhem Moulin <guilhem@fripost.org> | 2021-02-20 20:16:34 +0100 | 
| commit | 3e49ef22ba3fbbe4e73bc4ad151770603ffa5ef1 (patch) | |
| tree | f6717683f11f606405d40dd9055cdc5f9b9b4b8d /lacme-accountd | |
| parent | 95534d55bd27ec9311a484ddc4e4a550191aa496 (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.
Diffstat (limited to 'lacme-accountd')
| -rwxr-xr-x | lacme-accountd | 23 | 
1 files changed, 13 insertions, 10 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};  | 
