Test if a backup user is available from a list
This commit is contained in:
parent
e0e6800c3c
commit
c1e7d54ad1
|
@ -10,7 +10,7 @@ ERROR=1
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
USER_ID=$(id -u)
|
USER_ID=$(id -u)
|
||||||
|
|
||||||
BACKUP_USER_LOGIN="backup"
|
BACKUP_USER_LIST="backup backuppc"
|
||||||
BACKUP_SUDOERS_LINE_REGEXP="backuppc.*ALL.*=.*(ALL:ALL).*NOEXEC:NOPASSWD:.*/usr/bin/rsync"
|
BACKUP_SUDOERS_LINE_REGEXP="backuppc.*ALL.*=.*(ALL:ALL).*NOEXEC:NOPASSWD:.*/usr/bin/rsync"
|
||||||
BACKUP_SUDOERS_LINE="backup ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync
|
BACKUP_SUDOERS_LINE="backup ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync
|
||||||
backuppc ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync"
|
backuppc ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync"
|
||||||
|
@ -18,17 +18,22 @@ BACKUP_SUDOERS_FILE="/etc/sudoers.d/backuppc_noexec"
|
||||||
# ]]]
|
# ]]]
|
||||||
|
|
||||||
# Functions [[[
|
# Functions [[[
|
||||||
is_user() ## [[[
|
|
||||||
{
|
|
||||||
user_to_check="${1}"
|
|
||||||
|
|
||||||
|
## Check if a backup user is present on the system from a list of users
|
||||||
|
is_backup_user() ## [[[
|
||||||
|
{
|
||||||
|
userlist_to_check="${1}"
|
||||||
|
|
||||||
|
for user_to_check in ${userlist_to_check}; do
|
||||||
if [ "$(id -- "${user_to_check}" 2> /dev/null)" ] ; then
|
if [ "$(id -- "${user_to_check}" 2> /dev/null)" ] ; then
|
||||||
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Function is_user() — ${user_to_check} user is available."
|
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Function is_backup_user() — ${user_to_check} user is available."
|
||||||
return "${SUCCESS}"
|
return "${SUCCESS}"
|
||||||
else
|
|
||||||
printf '\e[1;31m%-6s\e[m\n' "ERROR : Function is_user() — ${user_to_check} user is unavailable."
|
|
||||||
exit "${ERROR}"
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
## Otherwise exit with error status
|
||||||
|
printf '\e[1;31m%-6s\e[m\n' "ERROR : Function is_backup_user() — none of these users : ${userlist_to_check} are available on the system."
|
||||||
|
exit "${ERROR}"
|
||||||
}
|
}
|
||||||
## ]]]
|
## ]]]
|
||||||
is_sudoers_line() ## [[[
|
is_sudoers_line() ## [[[
|
||||||
|
@ -75,7 +80,7 @@ fi
|
||||||
# ]]]
|
# ]]]
|
||||||
|
|
||||||
# Ensure the backup user is available
|
# Ensure the backup user is available
|
||||||
is_user "${BACKUP_USER_LOGIN}"
|
is_backup_user "${BACKUP_USER_LIST}"
|
||||||
|
|
||||||
# Test if sudoers conf is already set
|
# Test if sudoers conf is already set
|
||||||
if ! is_sudoers_line "${BACKUP_SUDOERS_LINE_REGEXP}"
|
if ! is_sudoers_line "${BACKUP_SUDOERS_LINE_REGEXP}"
|
||||||
|
|
Loading…
Reference in New Issue