From 606e534f777356c489a1374b4580c39e8efd5a5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Tue, 28 May 2019 14:48:48 +0200 Subject: [PATCH] Ensure to include sudoers.d in the main config --- client/fix_backuppc_linux_sudo.sh | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/client/fix_backuppc_linux_sudo.sh b/client/fix_backuppc_linux_sudo.sh index 7fb3b4e..46c8c6a 100755 --- a/client/fix_backuppc_linux_sudo.sh +++ b/client/fix_backuppc_linux_sudo.sh @@ -69,6 +69,21 @@ is_backup_sudoers_line() fi } ## ]]] +## Add some configuration to the main sudoers conf [[[ +add_sudoers_conf() +{ + sudoers_conf="${1}" + sudoers_file="/etc/sudoers" + + ## Set sudoers configuration for BackupPC + cat << EOF >> "${sudoers_file}" +# Added by a script +${sudoers_conf} +EOF + + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Function add_sudoers_conf() — ${sudoers_file} was modified." +} +## ]]] ## Add some configuration to a specific file under sudoers.d/ [[[ add_backup_sudoers_conf() { @@ -103,7 +118,21 @@ fi is_backup_user "${BACKUP_USER_LIST}" # Ensure sudoers.d is include in the sudoers main configuration -is_sudoers_line "${SUDOERS_D_INCLUDE_LINE}" +if ! is_sudoers_line "${SUDOERS_D_INCLUDE_LINE}" +then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : First try — ${SUDOERS_D_INCLUDE_LINE} was not found in sudo main configuration." + ## Add the expected line + add_sudoers_conf "${SUDOERS_D_INCLUDE_LINE}" + + ## Test again if the line is now available + if ! is_sudoers_line "${SUDOERS_D_INCLUDE_LINE}" + then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Second try — ${SUDOERS_D_INCLUDE_LINE} was not found in sudo main configuration." + printf '\e[1;31m%-6s\e[m\n' "ERROR : The sudo configuration was not successfully modified." + printf '\e[1;31m%-6s\e[m\n' "ERROR : Please contact your administrator." + exit "${ERROR}" + fi +fi # Test if sudoers conf is already set if ! is_backup_sudoers_line "${BACKUP_SUDOERS_LINE_REGEXP}"