Notifier allows to override global configuration files on a per-command base by checking for existence of all required configuration values as environment values.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e6b9e4a800
commit
15e4775679
14 changed files with 62 additions and 29 deletions
15
README.md
15
README.md
|
@ -61,6 +61,21 @@ NOTIFIER_MAIL_ENABLED=true
|
||||||
NOTIFIER_GOTIFY_ENABLED=false
|
NOTIFIER_GOTIFY_ENABLED=false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Important:** You can also change notifier behavior on a per-command basis, e.g. disable mail or gotify by providing ALL notifier variables as environment variables where the command is issued, for example in a systemd .service file.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# ...
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
# ...
|
||||||
|
Environment="NOTIFIER_GOTIFY_ENABLED=false"
|
||||||
|
Environment="NOTIFIER_MAIL_ENABLED=true"
|
||||||
|
Environment="NOTIFIER_MAIL_ADDRESS=another-mail-different-from-your-global-config@domain.tld"
|
||||||
|
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
Otherwise, services and scripts don't depend on each other, but have hints that they can be combined (out-commented line in service files for `systemd_failure_notify@.service` for example).
|
Otherwise, services and scripts don't depend on each other, but have hints that they can be combined (out-commented line in service files for `systemd_failure_notify@.service` for example).
|
||||||
|
|
||||||
Examples are given inside `usr/share/doc/system-helpers` and *man pages* are also available.
|
Examples are given inside `usr/share/doc/system-helpers` and *man pages* are also available.
|
||||||
|
|
|
@ -15,6 +15,8 @@ It's part of **system-helpers**.
|
||||||
|
|
||||||
By default, **notifier** tries to read from *$HOME/.notifier.conf* and */etc/notifier.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file.
|
By default, **notifier** tries to read from *$HOME/.notifier.conf* and */etc/notifier.conf* for configuration. It will exit with a non-zero exit code if it cannot find a proper configuration file.
|
||||||
|
|
||||||
|
If all of the below variables are set and not empty as environment variables, then **notifier** skips sourcing config files. This allows a per-command configuration without relying on the global configs.
|
||||||
|
|
||||||
The following configuration values can be set, defaults are shown as well:\
|
The following configuration values can be set, defaults are shown as well:\
|
||||||
|
|
||||||
- **NOTIFIER_MAIL_ENABLED="true"** which enables or disables notification via mail to *NOTIFIER_MAIL_ADDRESS*.
|
- **NOTIFIER_MAIL_ENABLED="true"** which enables or disables notification via mail to *NOTIFIER_MAIL_ADDRESS*.
|
||||||
|
|
|
@ -29,13 +29,9 @@ if [ -z "$NOTIFIER_CONTENT" ]; then
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NOTIFIER_MAIL_ENABLED="true";
|
|
||||||
NOTIFIER_GOTIFY_ENABLED="false";
|
|
||||||
NOTIFIER_MAIL_ADDRESS=$3;
|
|
||||||
|
|
||||||
argsMailProvided="false"
|
argsMailProvided="false"
|
||||||
|
|
||||||
if [[ -n "${NOTIFIER_MAIL_ADDRESS}" ]]; then
|
if [[ -n "$3" ]]; then
|
||||||
argsMailProvided="true"
|
argsMailProvided="true"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -88,6 +84,17 @@ source_config() {
|
||||||
local configFallback=$1;
|
local configFallback=$1;
|
||||||
local configGlobalFallback=$2;
|
local configGlobalFallback=$2;
|
||||||
|
|
||||||
|
checkMailEnabled=${NOTIFIER_MAIL_ENABLED:-1}
|
||||||
|
checkGotifyEnabled=${NOTIFIER_GOTIFY_ENABLED:-1}
|
||||||
|
checkMailAddress=${NOTIFIER_MAIL_ADDRESS:-1}
|
||||||
|
|
||||||
|
if [[ ! -v "$checkMailEnabled" && ! -v "$checkGotifyEnabled" && ! -v "$checkMailAddress" ]]; then
|
||||||
|
echo "Using environment variables for configuration instead of configuration files";
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
echo "Using configuration files";
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -f "$configFallback" ]]; then
|
if [[ -f "$configFallback" ]]; then
|
||||||
apply_config "$configFallback";
|
apply_config "$configFallback";
|
||||||
return;
|
return;
|
||||||
|
@ -106,12 +113,16 @@ if [[ "${argsMailProvided}" == "true" ]]; then
|
||||||
echo "Overwriting mail with argument value"
|
echo "Overwriting mail with argument value"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Using NOTIFIER_MAIL_ENABLED=${NOTIFIER_MAIL_ENABLED}"
|
||||||
|
echo "Using NOTIFIER_GOTIFY_ENABLED=${NOTIFIER_GOTIFY_ENABLED}"
|
||||||
|
echo "Using NOTIFIER_MAIL_ADDRESS=${NOTIFIER_MAIL_ADDRESS}"
|
||||||
|
|
||||||
SUBJECT="${NOTIFIER_SUBJECT}"
|
SUBJECT="${NOTIFIER_SUBJECT}"
|
||||||
MESSAGE="${NOTIFIER_CONTENT}"
|
MESSAGE="${NOTIFIER_CONTENT}"
|
||||||
|
|
||||||
if [[ "${NOTIFIER_MAIL_ENABLED}" == "true" ]]; then
|
if [[ "${NOTIFIER_MAIL_ENABLED}" == "true" ]]; then
|
||||||
echo "$MESSAGE"|mailx -Ssendwait -s "$SUBJECT" "$NOTIFIER_MAIL_ADDRESS";
|
echo "$MESSAGE"|mailx -Ssendwait -s "$SUBJECT" "$NOTIFIER_MAIL_ADDRESS";
|
||||||
echo "Sent notifiction via mail"
|
echo "Sent notifiction via mail to $NOTIFIER_MAIL_ADDRESS"
|
||||||
else
|
else
|
||||||
echo "Sending notifictions via mail is disabled"
|
echo "Sending notifictions via mail is disabled"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -76,4 +76,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -73,4 +73,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -80,4 +80,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -98,4 +98,4 @@ Success
|
||||||
\f[B]1\f[R]
|
\f[B]1\f[R]
|
||||||
Error
|
Error
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -85,4 +85,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -64,4 +64,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -39,6 +39,11 @@ configuration.
|
||||||
It will exit with a non-zero exit code if it cannot find a proper
|
It will exit with a non-zero exit code if it cannot find a proper
|
||||||
configuration file.
|
configuration file.
|
||||||
.PP
|
.PP
|
||||||
|
If all of the below variables are set and not empty as environment
|
||||||
|
variables, then \f[B]notifier\f[R] skips sourcing config files.
|
||||||
|
This allows a per-command configuration without relying on the global
|
||||||
|
configs.
|
||||||
|
.PP
|
||||||
The following configuration values can be set, defaults are shown as
|
The following configuration values can be set, defaults are shown as
|
||||||
well:
|
well:
|
||||||
.PD 0
|
.PD 0
|
||||||
|
@ -50,7 +55,7 @@ notification via mail to \f[I]NOTIFIER_MAIL_ADDRESS\f[R].
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
\f[B]NOTIFIER_MAIL_ADDRESS=\[lq]\[lq]\f[R] which requires
|
\f[B]NOTIFIER_MAIL_ADDRESS=\[lq]\[lq]\f[R] which requires
|
||||||
\f[I]mail.rc\f[R] to be configured and `\f[I]mailx\f[R]' command has be
|
\f[I]mail.rc\f[R] to be configured and `\f[I]mailx\f[R]' command has be
|
||||||
available\[ac]
|
available¸
|
||||||
.IP \[bu] 2
|
.IP \[bu] 2
|
||||||
\f[B]NOTIFIER_GOTIFY_ENABLED=\[lq]false\[rq]\f[R] which `gotify' command
|
\f[B]NOTIFIER_GOTIFY_ENABLED=\[lq]false\[rq]\f[R] which `gotify' command
|
||||||
has be available and needs to be properly configured by having a
|
has be available and needs to be properly configured by having a
|
||||||
|
@ -77,4 +82,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]system-helpers\f[R]
|
\f[B]system-helpers\f[R]
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -68,4 +68,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -58,4 +58,4 @@ See \f[I]/usr/share/doc/system-helpers/system-helpers\f[R] for example
|
||||||
configurations which should be copied inside \f[B]$HOME\f[R] or
|
configurations which should be copied inside \f[B]$HOME\f[R] or
|
||||||
\f[B]/etc\f[R] depending on the helper script.
|
\f[B]/etc\f[R] depending on the helper script.
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -71,4 +71,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.\" Automatically generated by Pandoc 2.19.2
|
.\" Automatically generated by Pandoc 3.0.1
|
||||||
.\"
|
.\"
|
||||||
.\" Define V font for inline verbatim, using C font in formats
|
.\" Define V font for inline verbatim, using C font in formats
|
||||||
.\" that render this, and otherwise B font.
|
.\" that render this, and otherwise B font.
|
||||||
|
@ -71,4 +71,4 @@ Error
|
||||||
.PP
|
.PP
|
||||||
\f[B]notifier\f[R] - used as notification application
|
\f[B]notifier\f[R] - used as notification application
|
||||||
.SH AUTHORS
|
.SH AUTHORS
|
||||||
Alexander Sch\[:a]ferdiek.
|
Alexander Schäferdiek.
|
||||||
|
|
Loading…
Reference in a new issue