]> Frank Brehm's Git Trees - pixelpark/create-terraform.git/commitdiff
Ensuring correct permissions of /etc/resolv.conf in postinstall-scripts/conf-resolver
authorFrank Brehm <frank@brehm-online.com>
Tue, 30 Aug 2022 15:14:03 +0000 (17:14 +0200)
committerFrank Brehm <frank@brehm-online.com>
Tue, 30 Aug 2022 15:14:03 +0000 (17:14 +0200)
postinstall-scripts/conf-resolver

index 189460f2e87c3890f5665a2a363ca7c91dd9f0d2..d02b02a929ac270d8e341f295a19657abff78bf7 100755 (executable)
@@ -48,6 +48,8 @@ DEFAULT_RESOLV_OPTIONS="timeout:1 attempts:2"
 UNSET_MARK="<<<unset>>>"
 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
+
 }
 
 #------------------------------------------------------------------------------