-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnmcli-cli-autoconnect-list
executable file
·58 lines (47 loc) · 1.19 KB
/
nmcli-cli-autoconnect-list
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
56
57
#!/bin/bash
#
# nmcli-cli-autoconnect-list
#
# Copyright (c) 2019 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
# list
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
main() {
[[ $# -lt 1 ]] && usage && exit 1
autoconnect_list "${@}"
}
[[ ${#BASH_SOURCE[@]} = 1 ]] && main "${@}"