From: Frank Brehm Date: Tue, 30 Aug 2022 15:14:03 +0000 (+0200) Subject: Ensuring correct permissions of /etc/resolv.conf in postinstall-scripts/conf-resolver X-Git-Tag: 1.6.8~1 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=c98402dc2480fdebf196f596cead5530cf69fae6;p=pixelpark%2Fcreate-terraform.git Ensuring correct permissions of /etc/resolv.conf in postinstall-scripts/conf-resolver --- diff --git a/postinstall-scripts/conf-resolver b/postinstall-scripts/conf-resolver index 189460f..d02b02a 100755 --- a/postinstall-scripts/conf-resolver +++ b/postinstall-scripts/conf-resolver @@ -48,6 +48,8 @@ DEFAULT_RESOLV_OPTIONS="timeout:1 attempts:2" UNSET_MARK="<<>>" RESOLV_OPTIONS="${UNSET_MARK}" +EXPECTED_PERMS="644" + #------------------------------------------------------------------- detect_color() { @@ -479,6 +481,28 @@ generate() { printf "${content}" >"${RESOLV_CONF}" fi + empty_line + debug "Ensuring correct permissions to '${CYAN}${RESOLV_CONF}${NORMAL}':" + local cur_perms= + local verbose_opt= + local cmd= + if [[ "${VERBOSE}" == "y" ]] ; then + verbose_opt=" --verbose" + cur_perms=$( stat --printf '%A' "${RESOLV_CONF}" ) + debug "Current permissions of '${RESOLV_CONF}': ${CYAN}${cur_perms}${NORMAL}" + fi + cur_perms=$( stat --printf '%a' "${RESOLV_CONF}" ) + if [[ "${cur_perms}" != "${EXPECTED_PERMS}" ]] ; then + cmd="chmod${verbose_opt} '${EXPECTED_PERMS}' '${RESOLV_CONF}'" + info "Setting permissions of '${CYAN}${RESOLV_CONF}${NORMAL}' to '${CYAN}${EXPECTED_PERMS}${NORMAL}' ..." + if [[ "${SIMULATE}" == "y" ]] ; then + info "Simulating executing: ${cmd}" + else + debug "Executing: ${cmd}" + eval ${cmd} + fi + fi + } #------------------------------------------------------------------------------