Debian Codegraph @

src/core/settings/plugins/ifcfg-rh/nm-ifdown

raw
1 #!/bin/bash
2
3 CONFIG="$1"
4
5 if [ -z "${CONFIG}" ] ; then
6 echo $"Usage: ifdown <device name>" >&2
7 exit 1
8 fi
9
10 usage_and_fail() {
11 cat <<EOF >&2
12 $1!
13
14 See all profiles with \`nmcli connection\`.
15 Reload files from disk with \`nmcli connection reload\`
16 Deactivate the desired profile with \`nmcli connection down \"\$NAME\"\`
17 EOF
18 exit 1
19 }
20
21 OLD_IFS="$IFS"
22
23 re='^/etc/sysconfig/network-scripts/ifcfg-[^/]+$'
24 for f in "/etc/sysconfig/network-scripts/ifcfg-$CONFIG" "/etc/sysconfig/network-scripts/$CONFIG" ; do
25 [[ "$f" =~ $re ]] || continue
26 [ -f "$f" ] || continue
27
28 nmcli connection load "$f" \
29 && nmcli connection down filename "$f" \
30 && exit 0
31
32 usage_and_fail "Failure to deactivate file \"$CONFIG\""
33 done
34
35 IFS=$'\n '
36 APATHS=( $(nmcli -g GENERAL.DBUS-PATH connection show --active "$CONFIG" 2>/dev/null) )
37 IFS="$OLD_IFS"
38 if [ "${#APATHS[@]}" -eq 1 ] ; then
39 nmcli connection down apath "${APATHS[0]}" \
40 && exit 0
41 usage_and_fail "Failure to deactivate profile \"$CONFIG\" (apath ${APATHS[@]})"
42 fi
43
44 usage_and_fail "No suitable profile \"$CONFIG\" found"