Skip to content

Commit

Permalink
fix: Remove dependency on /etc/sysconfig/network-scripts (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfut committed Nov 7, 2022
1 parent 40495b9 commit 5a87c33
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,12 @@ Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkMa
```
Usage:
nmcli-cli-autoconnect-list on|off
nmcli-cli-autoconnect-list all
nmcli-cli-autoconnect-list yes|no or on|off
Examples:
nmcli-cli-autoconnect-list off
nmcli-cli-autoconnect-list on
nmcli-cli-autoconnect-list all
nmcli-cli-autoconnect-list yes
```

Run examples:
Expand Down
23 changes: 17 additions & 6 deletions nmcli-cli-autoconnect-list
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,40 @@ usage() {
cat << _EOF_
Usage:
$0 on|off
$0 all
$0 yes|no or on|off
Examples:
$0 off
$0 on
$0 all
$0 yes
_EOF_
}

autoconnect_list() {
ON_OFF=${1:-}

if [[ "${ON_OFF}" = on ]]; then
if [[ "${ON_OFF}" == "all" ]]; then
ON_OFF="all"
elif [[ "${ON_OFF}" == "on" ]] || [[ "${ON_OFF}" == "yes" ]]; then
ON_OFF="yes"
elif [[ "${ON_OFF}" = off ]]; then
elif [[ "${ON_OFF}" == "off" ]] || [[ "${ON_OFF}" == "no" ]]; then
ON_OFF="no"
else
echo "Error: option \"${ON_OFF}\" is invalid."
exit 1
fi

# list
grep "^ONBOOT=${ON_OFF}" /etc/sysconfig/network-scripts/ifcfg-* | cut -d':' -f 1 | sed 's|.*/ifcfg-||g'
LIST=$(nmcli connection | awk '{ print $1 }' | grep -v "^NAME$")
for INTERFACE in ${LIST}
do
STATUS_LINE=$(nmcli connection show "${INTERFACE}" | grep connection.autoconnect:)
STATUS=$(echo "${STATUS_LINE}" | awk '{ print $2 }')
if [[ "${ON_OFF}" == "all" ]] || [[ "${STATUS}" == "${ON_OFF}" ]]; then
echo "${INTERFACE}"
fi
done
}

# Main
Expand Down
8 changes: 4 additions & 4 deletions nmcli-cli-bond-delete
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ check() {
bond_delete() {
local BOND_IF_NAME=${1:-}

# Find slave interfaces
SLAVE_LIST=$(grep "^MASTER=${BOND_IF_NAME}$" /etc/sysconfig/network-scripts/ifcfg-* | cut -d':' -f 1 | egrep -o "bond-slave.*")
# Find lower interfaces
INTERFACE_LIST=$(ls "/sys/class/net/${BOND_IF_NAME}/" | grep "^lower_" | sed 's|lower_||')

# Delete slave interfaces
for i in ${SLAVE_LIST}
# Delete lower interfaces
for i in ${INTERFACE_LIST}
do
echo_or_execute nmcli connection delete \"${i}\"
done
Expand Down
8 changes: 4 additions & 4 deletions nmcli-cli-bridge-delete
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ check() {
bridge_delete() {
local BRIDGE_NAME=${1:-}

# Find slave interfaces
SLAVE_LIST=$(grep "^BRIDGE=${BRIDGE_NAME}$" /etc/sysconfig/network-scripts/ifcfg-* | cut -d':' -f 1 | sed 's|.*/ifcfg-||g')
# Find lower interface
INTERFACE_LIST=$(ls "/sys/class/net/${BRIDGE_NAME}/" | grep "^lower_" | sed 's|lower_||')

# Delete slave interfaces
for i in ${SLAVE_LIST}
# Delete lower interface
for i in ${INTERFACE_LIST}
do
echo_or_execute nmcli connection modify \"${i}\" connection.master \"\" connection.slave-type \"\"
done
Expand Down
29 changes: 8 additions & 21 deletions nmcli-cli-slave-list
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,14 @@ _EOF_
slave_list() {
local IF_NAME=${1:-}

# Bond
# Find slave interfaces
SLAVE_LIST=$(grep "^MASTER=${IF_NAME}$" /etc/sysconfig/network-scripts/ifcfg-* | cut -d':' -f 1 | egrep -o "bond-slave.*")
for i in ${SLAVE_LIST}
do
echo "${i}"
done

# Bridge
# Find slave interfaces
SLAVE_LIST=$(grep "^BRIDGE=${IF_NAME}$" /etc/sysconfig/network-scripts/ifcfg-* | cut -d':' -f 1 | sed 's|.*/ifcfg-||g')
for i in ${SLAVE_LIST}
do
echo "${i}"
done

# VLAN
# Find physical interface
IFCFG_FILE="/etc/sysconfig/network-scripts/ifcfg-${IF_NAME}"
if [[ -f "${IFCFG_FILE}" ]]; then
grep "^PHYSDEV=" "${IFCFG_FILE}" | cut -d'=' -f 2
# Find lower interfaces
TARGET="/sys/class/net/${IF_NAME}/"
if [[ -e "${TARGET}" ]]; then
INTERFACE_LIST=$(ls "${TARGET}" | grep "^lower_" | sed 's|lower_||')
for i in ${INTERFACE_LIST}
do
echo "${i}"
done
fi
}

Expand Down

0 comments on commit 5a87c33

Please sign in to comment.