Adds support for configuration file

The script can now be configured using configuration files.
If a file named ".freemobile-smsapi" is located next to the script or in user's
home directory, such file will be read to load
Alternatively, a file path can be specified using `-c` option at runtime.

This commit makes the script accept option to specify configuration filepath
and also look for configuration files in specific places.
This commit is contained in:
C-Duv
2017-02-11 15:20:55 +01:00
parent 0105907e20
commit 29abae8a06
2 changed files with 68 additions and 5 deletions

View File

@@ -12,19 +12,19 @@ Shell Client
### Possible usages:
```
send-notification.sh "All your base are belong to us"
send-notification.sh [options] "All your base are belong to us"
```
```
uptime | send-notification.sh
uptime | send-notification.sh [options]
```
See `send-notification.sh -h`.
### Configuration :
Script can be configured
Edit `send-notification.sh` and set the following variables:
Script can be configured using the following variables:
* `USER_LOGIN`: The login to use the API.
* `API_KEY`: The secret key associated to `USER_LOGIN`.
* `MESSAGE_HEADER` (Optional): Will be prepended to all the messages.
@@ -32,6 +32,23 @@ Edit `send-notification.sh` and set the following variables:
* `NEWLINE_CHAR` (Optional): Char to use to create a new line (it depends on
receiving terminal).
Theses can be directly changed in the `send-notification.sh` file or set in a
separate configuration file named `.freemobile-smsapi` next to the script or in
the user's home directory. A given filepath can also be specify using the `-c`
script at runtime (`send-notification.sh -c foobar`).
Configuration load process is as follows:
# Uses what's in `send-notification.sh` file.
# If `-c` option is set, test given file existence and uses what's inside.
Will not load any other configuration file (stops load process here).
# Checks if a `.freemobile-smsapi` file exists next to the script and uses
what's inside. Will not load any other configuration file (stops load process
here).
# Checks if a `.freemobile-smsapi` file exists in user's home directory
(`${HOME}`) and uses what's inside. Will not load any other configuration file
(stops load process here).
PHP Client
----------