From b28a16c803f47491102b76f355e894c98a48a0f3 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Sat, 9 Mar 2024 15:36:45 -0600 Subject: [PATCH] Update update-dns.sh --- update-dns.sh | 93 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/update-dns.sh b/update-dns.sh index edd0f90..efd2a25 100755 --- a/update-dns.sh +++ b/update-dns.sh @@ -1,45 +1,60 @@ #!/bin/bash -echo "HERE: ${1}" +if [ -d /opt/idssys/defaults ]; then + source /opt/idssys/defaults/colors.inc + source /opt/idssys/defaults/default.inc +else + source /dev/stdin <<< "$(curl -sL http://go.scity.us/colorsinc)" + source /dev/stdin <<< "$(curl -sL http://go.scity.us/defaultinc)" +fi -# if [ -d /opt/idssys/defaults ]; then -# source /opt/idssys/defaults/colors.inc -# source /opt/idssys/defaults/default.inc -# else -# source /dev/stdin <<< "$(curl -sL http://go.scity.us/colorsinc)" -# source /dev/stdin <<< "$(curl -sL http://go.scity.us/defaultinc)" -# fi -# -# if [ -f /etc/netplan/eth0.yaml ]; then -# cat /etc/netplan/eth0.yaml -# else -# cat /etc/network/interfaces -# fi -# echo -# -# read -n 1 -p "Do you wish to continue changing the DNS? (Y/n) " choice -# case "$choice" in -# [Nn]) -# echo -e "${Green}The DNS servers have NOT been updated${Color_Off}" -# exit 0 -# ;; -# -# * ) if [ -f /etc/netplan/eth0.yaml ]; then -# sed -i 's/10.10.10.10,10.10.10.11/10.10.10.10,10.10.10.11,10.2.1.2/g' /etc/netplan/eth0.yaml -# -# /usr/sbin/netplan apply -# -# cat /etc/netplan/eth0.yaml -# else -# sed -i 's/10.10.10.10 10.10.10.11/10.10.10.10 10.10.10.11 10.2.1.2/g' /etc/network/interfaces -# -# /usr/sbin/service networking restart -# -# cat /etc/network/interfaces -# fi -# echo -e "${Green}The DNS servers have been updated${Color_Off}" -# ;; -# esac +if [ -f /etc/netplan/eth0.yaml ]; then + cat /etc/netplan/eth0.yaml + netfile=/etc/netplan/eth0.yaml +elif [ -f /etc/netplan/network.yaml ]; then + cat /etc/netplan/network.yaml + netfile=/etc/netplan/network.yaml +elif [ -f /etc/network/interfaces ]; then + cat /etc/network/interfaces + netfile=/etc/network/interfaces +else + echo -e "No network configs found\n" + exit 1 +fi +echo + +read -n 1 -p "Do you wish to continue changing the DNS? (Y/n) " choice +case "$choice" in +[Nn]) + echo -e "${Green}The DNS servers have NOT been updated${Color_Off}" + exit 0 + ;; + +* ) if [ -f /etc/netplan/eth0.yaml ] || [ -f /etc/netplan/network.yaml ]; then + if [ "${1}" = "offsite" ]; then + sed -i 's/10.10.10.10,10.10.10.11/10.2.1.5,10.2.1.6,10.10.10.5/g' ${netfile} + sed -i 's/127.0.0.1,10.10.10.10/10.2.1.5,10.2.1.6,10.10.10.5/g' ${netfile} + else + sed -i 's/10.10.10.10,10.10.10.11/10.10.10.10,10.10.10.11,10.2.1.2/g' ${netfile} + fi + + /usr/sbin/netplan apply + + cat ${netfile} + else + if [ "${1}" = "offsite" ]; then + sed -i 's/10.10.10.10 10.10.10.11/10.10.10.10 10.10.10.11 10.2.1.2/g' ${netfile} + else + sed -i 's/10.10.10.10 10.10.10.11/10.10.10.10 10.10.10.11 10.2.1.2/g' ${netfile} + fi + + /usr/sbin/service networking restart + + cat ${netfile} + fi + echo -e "${Green}The DNS servers have been updated${Color_Off}" + ;; +esac echo