Add checks for super user exists
This commit is contained in:
13
ReadMe.md
13
ReadMe.md
@@ -21,11 +21,13 @@ Two files must be created
|
|||||||
|
|
||||||
Example file is `pgbackrest.sample.cfg`
|
Example file is `pgbackrest.sample.cfg`
|
||||||
|
|
||||||
This file holds the sudo_user for calling the commands
|
This file holds the sudo_user for calling the commands and the main pgbackrest config file.
|
||||||
|
If the super user or config file does not exists an error will be shown
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
[PgBackRest]
|
[PgBackRest]
|
||||||
sudo_user=postgres
|
sudo_user=postgres
|
||||||
|
pgbackrest_config=/etc/pgbackrest.conf
|
||||||
```
|
```
|
||||||
|
|
||||||
### `config/stanza.cfg`
|
### `config/stanza.cfg`
|
||||||
@@ -44,7 +46,14 @@ The forth optional parameter is the super user to use
|
|||||||
|
|
||||||
If parameters are not used but laters are, the empties need to be set with just the ":"
|
If parameters are not used but laters are, the empties need to be set with just the ":"
|
||||||
|
|
||||||
`stanza::/conifg`
|
`stanza::/config`
|
||||||
|
|
||||||
|
The script checks for the following things during each run
|
||||||
|
|
||||||
|
- stanza name exists in the main config file, or in the override config file if set
|
||||||
|
- check if repo number exist in main config file, or in the override config file if set
|
||||||
|
- override config file exists
|
||||||
|
- override super does not exist
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
[stanzas]
|
[stanzas]
|
||||||
|
|||||||
@@ -71,6 +71,10 @@ if [ -z "${sudo_user}" ]; then
|
|||||||
echo "sudo_user not set in the config file ${config_file}";
|
echo "sudo_user not set in the config file ${config_file}";
|
||||||
exit;
|
exit;
|
||||||
fi;
|
fi;
|
||||||
|
if ! id "${sudo_user}" &>/dev/null; then
|
||||||
|
echo "Sudo user ${sudo_user} does not exist, skipping stanza";
|
||||||
|
exit
|
||||||
|
fi;
|
||||||
if [ -z "${pgbackrest_config}" ] ||[ ! -f "${pgbackrest_config}" ]; then
|
if [ -z "${pgbackrest_config}" ] ||[ ! -f "${pgbackrest_config}" ]; then
|
||||||
echo "Missing pgbackrest default config file ${pgbackrest_config}";
|
echo "Missing pgbackrest default config file ${pgbackrest_config}";
|
||||||
exit;
|
exit;
|
||||||
@@ -218,6 +222,10 @@ while read -r stanza; do
|
|||||||
fi;
|
fi;
|
||||||
# set override sudo user
|
# set override sudo user
|
||||||
if [ -n "${stanza_super_user}" ]; then
|
if [ -n "${stanza_super_user}" ]; then
|
||||||
|
if ! id "${stanza_super_user}" &>/dev/null; then
|
||||||
|
echo "[!] Sudo user ${stanza_super_user} for stanza ${stanza_name} does not exist, skipping stanza";
|
||||||
|
continue;
|
||||||
|
fi;
|
||||||
sudo_user="${stanza_super_user}";
|
sudo_user="${stanza_super_user}";
|
||||||
fi;
|
fi;
|
||||||
# build the call command
|
# build the call command
|
||||||
|
|||||||
Reference in New Issue
Block a user