Add a script in order to fix backuppc sudo rights

This commit is contained in:
Jeremy Gardais 2018-05-28 16:20:58 +02:00
parent 641eaf5ae6
commit 764b9e6c94
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,63 @@
#!/bin/sh
# S'assurer que BackupPC peux exécuter rsync avec les droits sudo
# Jérémy GARDAIS — Mai 2018
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# Vars [[[
SUCCESS=0
ERROR=1
DEBUG=0
EUID=$(id -u)
BACKUP_USER_LOGIN="backup"
#BACKUP_USER_LOGIN="backuppc"
SUDOERS_LINE_REGEXP="${BACKUP_USER_LOGIN}.*ALL.*=.*(ALL:ALL).*NOEXEC:NOPASSWD:.*/usr/bin/rsync"
# ]]]
# Functions [[[
is_user() ## [[[
{
user_to_check="${1}"
if [ "$(id -- "${user_to_check}" 2> /dev/null)" ] ; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: ${user_to_check} user is available."
return "${SUCCESS}"
else
printf '\e[1;31m%-6s\e[m\n' "ERROR: ${user_to_check} user is unavailable."
exit "${ERROR}"
fi
}
## ]]]
is_sudoers_line() ## [[[
{
line_to_check="${1}"
if grep -Rq -- "${line_to_check}" /etc/sudoers.d/
then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: ${line_to_check} line is available in sudo configuration."
return "${SUCCESS}"
else
printf '\e[1;31m%-6s\e[m\n' "ERROR: ${line_to_check} was not found in sudo configuration."
exit "${ERROR}"
fi
}
## ]]]
# ]]]
# Test permissions [[[
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Check admin rights."
if [ "${EUID}" -ne "0" ]; then
printf '\e[1;31m%-6s\e[m\n' "ERROR: You need to run with SUDO/Admin permissions."
exit "${ERROR}"
fi
# ]]]
is_user "${BACKUP_USER_LOGIN}"
is_sudoers_line "${SUDOERS_LINE_REGEXP}"
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: End"
exit 0