#!/bin/bash CURDIR=$(dirname "$(readlink -f "$0")") source "$CURDIR"/shared-functions.so # MAIL QUEUE ACTIONS function send_mailqueue { # send queued mails $MSMTP_LIST read -p "Send these queued mails? [Y/n]: " YN if [[ $YN =~ ^(Y|y|)$ ]]; then $MSMTP_RUN else echo "Not sending emails" fi } function list_mailqueue { # list emails in queue only $MSMTP_LIST } # CHANGE ONLINE STATUS function switch_conn { echo "Current connection status: $var_conn" read -p "Switch connection status? [Y/n]: " YN if [[ $YN =~ ^(Y|y|)$ ]]; then if [ "$var_conn" == "off" ]; then var_conn="on" echo "Connection status switched to \"on\"" else var_conn="off" echo "Connection status switched to \"off\"" fi else echo "Connection status not changed." 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]" "switch nameservers" "quit") PS3="Select action: " select action in "${ACTIONS[@]}" do echo # empty line after selection case $REPLY in # $REPLY takes the numbers which is nice 1) # Show queue; ask for confirmation; if yes, send emails send_mailqueue break ;; 2) # Show queue list_mailqueue break ;; 3) # Switch online status switch_conn break ;; 4) # Switch nameservers switch_ns break ;; 5|"q") # exit silently, one can also press "q" instead of the number exit 0 break ;; esac done } while :; do # endless loop exec # interaction screen wtmp; source "$TMP" # write changes back and load them echo # empty line done