From e21864990d85c2d8a0cf7382c1a0daeffdcb799b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Mon, 28 May 2018 17:31:54 +0200 Subject: [PATCH] Test is_sudoers_line result --- client/fix_backuppc_linux_sudo.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/fix_backuppc_linux_sudo.sh b/client/fix_backuppc_linux_sudo.sh index 58e12f6..5eaf07e 100755 --- a/client/fix_backuppc_linux_sudo.sh +++ b/client/fix_backuppc_linux_sudo.sh @@ -21,10 +21,10 @@ 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." + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Function — ${user_to_check} user is available." return "${SUCCESS}" else - printf '\e[1;31m%-6s\e[m\n' "ERROR : ${user_to_check} user is unavailable." + printf '\e[1;31m%-6s\e[m\n' "ERROR : Function — ${user_to_check} user is unavailable." exit "${ERROR}" fi } @@ -35,10 +35,10 @@ is_sudoers_line() ## [[[ 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." + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Function — ${line_to_check} line is available in sudo configuration." return "${SUCCESS}" else - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${line_to_check} was not found in sudo configuration." + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : Function — ${line_to_check} was not found in sudo configuration." return "${ERROR}" fi } @@ -55,7 +55,14 @@ fi is_user "${BACKUP_USER_LOGIN}" -is_sudoers_line "${SUDOERS_LINE_REGEXP}" +if is_sudoers_line "${SUDOERS_LINE_REGEXP}" +then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${SUDOERS_LINE_REGEXP} is already set in sudo configuration." + printf '%b\n' "Your configuration is set up." + exit 0 +else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : First try — ${SUDOERS_LINE_REGEXP} was not found in sudo configuration." +fi [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : End"