Browse Source

closes #1 - case replace ifs, also change vars

master
Brandon Nolet 1 year ago
parent
commit
cd7357ae6f
1 changed files with 27 additions and 27 deletions
  1. 27
    27
      nmcli-basic.sh

+ 27
- 27
nmcli-basic.sh View File

@@ -40,17 +40,17 @@ function setstatic() {

#Setting Static IP info
echo "Configuring..."
nmcli con mod $IntID ipv4.addresses $IPAdd/$PrefLen
nmcli con mod $IntID ipv4.gateway $GatewayIP
nmcli con mod $IntID ipv4.dns "$DNSAdd" #Surrounded in quotes for multiple DNS servers
nmcli con mod $IntID ipv4.method manual
nmcli con mod ${IntID} ipv4.addresses ${IPAdd}/${PrefLen}
nmcli con mod ${IntID} ipv4.gateway ${GatewayIP}
nmcli con mod ${IntID} ipv4.dns "${DNSAdd}" #Surrounded in quotes for multiple DNS servers
nmcli con mod ${IntID} ipv4.method manual

apply
}

function setdynamic() {
echo "Configuring..."
nmcli con mod $IntID ipv4.method auto
nmcli con mod ${IntID} ipv4.method auto

apply
}
@@ -59,30 +59,31 @@ function apply() {

#Applying the changes
echo "Applying changes..."
nmcli con down $IntID > /dev/null
nmcli con up $IntID > /dev/null
nmcli con down ${IntID} > /dev/null
nmcli con up ${IntID} > /dev/null
echo "Done!"
}

if [[ $1 == "static" ]]; then
setstatic
fi

if [[ $1 == "dynamic" ]] || [[ $1 == "auto" ]] || [[ $1 == "automatic" ]] || [[ $1 == "dhcp" ]]; then
setdynamic
fi

if [[ $1 == "" ]]; then
read -p "Static or dynamic? " CHOICE
if [[ $CHOICE == "static" ]]; then
setstatic
fi
if [[ $CHOICE == "dynamic" ]]; then
case "$1" in
[dD]ynamic | [aA]uto | [aA]utomatic | [dD][hH][cC][pP])
setdynamic
fi
fi

exit
;;
[sS]tatic | [mM]anual)
setstatic
;;
"")
read -p "Static or DHCP? " CHOICE
case ${CHOICE} in
[dD]ynamic | [aA]uto | [aA]utomatic | [dD][hH][cC][pP])
setdynamic
;;
[sS]tatic | [mM]anual)
setstatic
;;
esac
esac

exit 0


# This program is free software: you can redistribute it and/or modify
@@ -96,5 +97,4 @@ exit
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>

# along with this program. If not, see <http://www.gnu.org/licenses/>

Loading…
Cancel
Save