Browse Source

Merge branch 'dev-master'

master
Brandon Nolet 1 year ago
parent
commit
0d241cf3ba
1 changed files with 60 additions and 36 deletions
  1. 60
    36
      nmcli-basic.sh

+ 60
- 36
nmcli-basic.sh View File

@@ -1,6 +1,6 @@
#!/bin/bash

# Version 0.2
# Version 0.3
# Author/Copyright: Brandon Nolet
# Contact: nolet.brandon@gmail.com

@@ -17,14 +17,7 @@
# The script will also take automatic, auto, and dhcp
# as valid dynamic address inputs.


nmcli con show



echo
read -p "Which interface to configure? " IntID
echo
NMCLI_BIN=$(which nmcli)

function setstatic() {

@@ -40,17 +33,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
}
@@ -58,31 +51,63 @@ function setdynamic() {
function apply() {

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

if [[ $1 == "static" ]]; then
setstatic
fi
function conshow() {
${NMCLI_BIN} con show
echo
read -p "Which interface to configure? " IntID
echo
}

if [[ $1 == "dynamic" ]] || [[ $1 == "auto" ]] || [[ $1 == "automatic" ]] || [[ $1 == "dhcp" ]]; then
setdynamic
fi
function usage() {
echo "
Description: This is a basic script that makes use
of the nmcli command, setting either a static or
dynamic IPv4 address. The script will take one or
no arguments. Should no arguments be passed to the
script, then the user will be prompted for the mode
to set the interface to. Otherwise the syntax is as follows

Syntax:
./nmcli-basic.sh [dynamic|static]

The script will also take automatic, auto, and dhcp
as valid inputs for dynamic addressing.
"
}

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])
conshow
setdynamic
fi
fi

exit
;;
[sS]tatic | [mM]anual)
conshow
setstatic
;;

[uU]sage)
usage
;;
"")
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 +121,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