adding function to switch DNS nameservers + monitoring of current settings; adding a README

This commit is contained in:
2016-12-26 15:30:59 +01:00
parent 5b233c5b1a
commit 9d605278e7
4 changed files with 118 additions and 3 deletions

View File

@@ -34,9 +34,58 @@ function switch_conn {
fi
}
# SWITCH NAMESERVERS
function switch_ns {
read -p "Switch nameservers? [Y/n]: " YN
if [[ $YN =~ ^(Y|y|)$ ]]; then
NS_SETS=$(echo "$NS" | grep -o "|" | wc -l) # number of nameserver sets (separated by |)
NS_SETS=$(expr $NS_SETS + 1) # add number +1 to correct count
for ((i = 1; i <= $NS_SETS; i++)); do # circle through all nameserver sets and number them
NS_NAME[$i]=$(echo $NS | cut -d"|" -f$i | sed -E 's/(^.+?)\((.+?)\)/\1/')
NS_VALUE[$i]=$(echo $NS | cut -d"|" -f$i | sed -E 's/(^.+?)\((.+?)\)/\2/')
echo "$i. ${NS_NAME[$i]}"
done
NS_NAME[0]="auto"; NS_VALUE[0]=""
echo "0. ${NS_NAME[0]} (DHCP-given)"
# Choose nameserver number and verify selection
OK=0
while [ "$OK" != "1" ]; do
echo; read -p "Type number of nameserver set: " i
if [ "${NS_NAME[$i]}" == "" ]; then
OK=0
echo "A nameserver set with this number does not exist. Please choose again."
else
OK=1
echo "Nameserver set switched to \"${NS_NAME[$i]}\". Please reconnect with NetworkManager to put the changes into effect."
fi
done
# Set definite values
NS_NAME=${NS_NAME[$i]}
NS_VALUE=${NS_VALUE[$i]}
NONS=$(echo "$NS_VALUE" | grep -o "," | wc -l) # number of nameservers in chosen set
NONS=$(expr $NONS + 1)
echo "# Custom nameserver set: $NS_NAME" > /tmp/resolv_custom.conf # write custom resolv config, which will be interpreted by "90-custom-resolvconf"
for ((i = 1; i <= $NONS; i++)); do
echo "nameserver $(echo $NS_VALUE | cut -d"," -f$i)" >> /tmp/resolv_custom.conf
done
var_ns=$NS_NAME # save name of nameserver set for later update of status file
fi # / YN
}
# OPTION SCREEN
function exec {
ACTIONS=("send mails in queue" "list mails in queue" "switch connection status [$var_conn]" "quit")
ACTIONS=("send mails in queue" "list mails in queue" "switch connection status [$var_conn]" "switch nameservers" "quit")
PS3="Select action: "
select action in "${ACTIONS[@]}"
@@ -52,7 +101,10 @@ function exec {
3) # Switch online status
switch_conn
break ;;
4|"q") # exit silently, one can also press "q" instead of the number
4) # Switch nameservers
switch_ns
break ;;
5|"q") # exit silently, one can also press "q" instead of the number
exit 0
break ;;
esac