backuppc_client/client/fix_backuppc_linux_sudo.sh

64 lines
1.5 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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