HAS_TTY='y'
HAS_COLORS="n"
-VERSION="0.7"
+VERSION="0.8"
BASENAME="$(basename ${0})"
BASE_DIR="$(dirname ${0})"
}
#------------------------------------------------------------------------------
-CP() {
- local cmd="cp"
- if [[ "${VERBOSE}" == "y" ]] ; then
- cmd+=" --verbose"
- fi
+exec_cmd() {
+
local msg="Executing"
if [[ "${SIMULATE}" == "y" ]] ; then
msg="Simulating"
fi
if [[ "${SIMULATE}" == "y" || "${VERBOSE}" == "y" ]] ; then
- echo "${msg}: ${cmd} $*"
+ echo "${msg}: $*"
fi
if [[ "${SIMULATE}" != "y" ]] ; then
- eval ${cmd} "$@"
+ eval "$@"
+ fi
+}
+
+#------------------------------------------------------------------------------
+CP() {
+ local cmd="cp"
+ if [[ "${VERBOSE}" == "y" ]] ; then
+ cmd+=" --verbose"
fi
+ exec_cmd ${cmd} "$@"
}
#------------------------------------------------------------------------------
if [[ "${VERBOSE}" == "y" ]] ; then
cmd+=" --verbose"
fi
- local msg="Executing"
- if [[ "${SIMULATE}" == "y" ]] ; then
- msg="Simulating"
- fi
- if [[ "${SIMULATE}" == "y" || "${VERBOSE}" == "y" ]] ; then
- echo "${msg}: ${cmd} $*"
- fi
- if [[ "${SIMULATE}" != "y" ]] ; then
- eval ${cmd} "$@"
- fi
+ exec_cmd ${cmd} "$@"
}
#------------------------------------------------------------------------------
}
+#------------------------------------------------------------------------------
+do_nm() {
+
+ empty_line
+ info "Executing ${GREEN}NetworkManager settings${NORMAL} ..."
+
+ if [[ $( type -t ip ) != "file" ]] ; then
+ warn "Command '${YELLOW}ip${NORMAL}' not found!"
+ return
+ fi
+
+ if [[ $( type -t nmcli ) != "file" ]] ; then
+ warn "Command '${YELLOW}nmcli${NORMAL}' not found!"
+ return
+ fi
+
+ local first_if=$( ip -oneline address | \
+ grep -w 'inet' | \
+ grep -v -E '^[1-9][0-9]*:[ ][ ]*lo[ ]' | \
+ awk '{ print $2 }' | \
+ head -n 1 )
+
+ local cur_nm_ns=$( nmcli connection show "${first_if}" | \
+ grep 'ipv4.dns:' | \
+ awk '{ print $2 }' )
+ local cur_nm_search=$( nmcli connection show "${first_if}" | \
+ grep 'ipv4.dns-search:' | \
+ awk '{ print $2 }' )
+ local cur_nm_options=$( nmcli connection show "${first_if}" | \
+ grep 'ipv4.dns-options:' | \
+ awk '{ print $2 }' | \
+ sed -e 's/^[ ]*"//' -e 's/"[ ]*$//' )
+
+ local ns=
+ local i=0
+ local exp_nm_ns=''
+ local nr="${#NAME_SERVERS[*]}"
+ for ns in "${NAME_SERVERS[@]}" ; do
+ i=$(( $i + 1 ))
+ exp_nm_ns+="${ns}"
+ if [[ "${i}" != "${nr}" ]] ; then
+ exp_nm_ns+=","
+ fi
+ done
+ debug "NM Nameservers: expected: '${exp_nm_ns}', configured: '${cur_nm_ns}'."
+ if [[ "${exp_nm_ns}" != "${cur_nm_ns}" ]] ; then
+ info "Setting ${GREEN}ipv4.dns${NORMAL} of '${first_if}' to '${GREEN}${exp_nm_ns}${NORMAL}'"
+ exec_cmd nmcli connection modify "${first_if}" ipv4.dns "${exp_nm_ns}"
+ fi
+
+ local dom=
+ local exp_nm_search=""
+ i=0
+ nr="${#SEARCH_DOMAINS[*]}"
+ for dom in "${SEARCH_DOMAINS[@]}" ; do
+ i=$(( $i + 1 ))
+ exp_nm_search+="${dom}"
+ if [[ "${i}" != "${nr}" ]] ; then
+ exp_nm_search+=","
+ fi
+ done
+ debug "NM search domains: expected: '${exp_nm_search}', configured: '${cur_nm_search}'."
+ if [[ "${exp_nm_search}" != "${cur_nm_search}" ]] ; then
+ info "Setting ${GREEN}ipv4.dns-search${NORMAL} of '${first_if}' to '${GREEN}${exp_nm_search}${NORMAL}'"
+ exec_cmd nmcli connection modify "${first_if}" ipv4.dns-search "${exp_nm_search}"
+ fi
+
+ local exp_nm_options=$( echo "${RESOLV_OPTIONS}" | sed -e 's/[ ][ ]*/,/g' )
+ debug "NM DNS options: expected: '${exp_nm_options}', configured: '${cur_nm_options}'."
+ if [[ "${exp_nm_options}" != "${cur_nm_options}" ]] ; then
+ info "Setting ${GREEN}ipv4.dns-options${NORMAL} of '${first_if}' to '${GREEN}${exp_nm_options}${NORMAL}'"
+ exec_cmd nmcli connection modify "${first_if}" ipv4.dns-options "${exp_nm_options}"
+ fi
+
+}
+
################################################################################
##
check_for_root
do_backup
generate
+ do_nm
}