-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnmcli-cli-autoconnect-list
More file actions
executable file
·55 lines (45 loc) · 1.16 KB
/
Copy pathnmcli-cli-autoconnect-list
File metadata and controls
executable file
·55 lines (45 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#
# nmcli-cli-autoconnect-list
#
# Copyright (c) 2019-2026 Jun Futagawa (jfut)
#
# This software is released under the MIT License.
# http://opensource.org/licenses/mit-license.php
usage() {
cat << _EOF_
Usage:
$0 all
$0 yes|no or on|off
Examples:
$0 all
$0 yes
_EOF_
}
autoconnect_list() {
ON_OFF=${1:-}
if [[ "${ON_OFF}" == "all" ]]; then
ON_OFF="all"
elif [[ "${ON_OFF}" == "on" ]] || [[ "${ON_OFF}" == "yes" ]]; then
ON_OFF="yes"
elif [[ "${ON_OFF}" == "off" ]] || [[ "${ON_OFF}" == "no" ]]; then
ON_OFF="no"
else
echo "Error: option \"${ON_OFF}\" is invalid."
exit 1
fi
# Read machine-friendly nmcli output so connection names may contain spaces.
nmcli -g NAME connection show | while IFS= read -r INTERFACE
do
STATUS=$(nmcli -g connection.autoconnect connection show "${INTERFACE}")
if [[ "${ON_OFF}" == "all" ]] || [[ "${STATUS}" == "${ON_OFF}" ]]; then
echo "${INTERFACE}"
fi
done
}
# Main
main() {
[[ $# -lt 1 ]] && usage && exit 1
autoconnect_list "${@}"
}
[[ ${#BASH_SOURCE[@]} = 1 ]] && main "${@}"