Debian Codegraph @

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

raw
1 #!/bin/bash
2
3 CONFIG="$1"
4
5 if [ -z "${CONFIG}" ] ; then
6 echo $"Usage: ifup <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 Activate the desired profile with \`nmcli connection up \"\$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 up filename "$f" \
30 && exit 0
31
32 usage_and_fail "Failure to activate file \"$CONFIG\""
33 done
34
35 IFS=$'\n '
36 UUIDS=( $(nmcli -g connection.uuid connection show "$CONFIG" 2>/dev/null) )
37 IFS="$OLD_IFS"
38 if [ "${#UUIDS[@]}" -eq 1 ] ; then
39 nmcli connection up uuid "${UUIDS[0]}" \
40 && exit 0
41 usage_and_fail "Failure to activate profile \"$CONFIG\" (uuid ${UUIDS[0]})"
42 fi
43
44 usage_and_fail "No suitable profile \"$CONFIG\" found"