Ensure to include sudoers.d in the main config
This commit is contained in:
		
							parent
							
								
									929a6bde98
								
							
						
					
					
						commit
						606e534f77
					
				|  | @ -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}" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue