Browse Source

Misc changes made by Diabolic Preacher

All changes in this commit are inspired by suggestions made by
[@dpreacher](https://mastodon.rocks/@dpreacher)

Go follow this gracious being (on mastodon)
master
Brandon Nolet 1 year ago
parent
commit
b6f0e1c578
1 changed files with 11 additions and 7 deletions
  1. 11
    7
      nin.sh

+ 11
- 7
nin.sh View File

@@ -27,7 +27,7 @@ function usage() {
NMCLI_BIN=$(which nmcli)
TIMESTAMP=$(date +%H:%M:%S)
LOGFILE=nin.log
TEELOG='tee --append ${LOGFILE}'
TEELOG="tee --append ${LOGFILE}"

# `setstatic` works as a state machine, running through
# each case statement in order of operation. This is Done
@@ -80,7 +80,7 @@ case $1 in #case to enable returnability
${NMCLI_BIN} connection modify "${IntID}" ipv4.gateway ${GatewayIP}
${NMCLI_BIN} connection modify "${IntID}" ipv4.dns "${DNSAdd}" #Surrounded in quotes for multiple DNS servers
${NMCLI_BIN} connection modify "${IntID}" ipv4.method manual
echo "${TIMESTAMP}: IPv4 address of ${IntID} set to ${IPAdd}/${PrefLen}." >> ${LOGFILE}
echo "${TIMESTAMP}: IPv4 address of ${IntID} set to ${IPAdd}/${PrefLen}." >> ${LOGFILE}
echo "${TIMESTAMP}: ${IntID} default gateway set to ${GatewayIP}." >> ${LOGFILE}
echo "${TIMESTAMP}: ${IntID}'s DNS servers are now ${DNSAdd}." >> ${LOGFILE}
echo "${TIMESTAMP}: ${IntID}'s resulting addressing method is \"Static\"" >> ${LOGFILE}
@@ -106,6 +106,10 @@ function reloadint() {

#Cycles the state of the selected interface
#to apply the changes
echo "The network interface will be momentarily disconnected."
sleep 1 #cosmetic
read -s -p "Please pause your downloads and whatnot, then press enter when ready."; echo


echo "Applying changes..."
${NMCLI_BIN} connection down "${IntID}" | sed "s/^/${TIMESTAMP}: /" >> ${LOGFILE}
@@ -117,10 +121,10 @@ function reloadint() {
function conshow() {

echo
${NMCLI_BIN} -t -f NAME,UUID,TYPE,DEVICE connection show | ${TEELOG}
${NMCLI_BIN} connection show --active | ${TEELOG}

echo
read -p "Which interface to configure? " IntID
read -p "Type the name of the interface you wish to configure: " IntID
echo "User input: IntID=${IntID}" >> ${LOGFILE}

if [[ "${IntID}" != '' ]]; then #empty strings make grep have a fit
@@ -175,7 +179,7 @@ function validip { #made specifically for the setstatic state machine
function getchoice() {

if [[ $1 == '' ]]; then
read -p "Do you want to configure static or DHCP addressing? " CHOICE
read -p "Do you want to configure static or DHCP addressing? (static/dhcp) " CHOICE
CHOICE=`echo ${CHOICE}|tr '[:upper:]' '[:lower:]'`
else
CHOICE=`echo $1|tr '[:upper:]' '[:lower:]'`
@@ -192,8 +196,8 @@ function getchoice() {
;;
*)
echo
echo "Sorry, that's not a valid option."
echo "Try ./nin.sh usage for more information."
echo "Sorry, accepted values are 'dhcp' or 'static' without quotes."
# echo "Try ./nin.sh usage for more information." Will put back when more options are available.
echo
sleep 1
getchoice

Loading…
Cancel
Save