From: Jonatan Schlag <jonatan.schlag@ipfire.org>
To: network@lists.ipfire.org
Subject: [PATCH 6/6] ipsec: add basic bash completion for ipsec
Date: Thu, 03 Aug 2017 12:51:27 +0200 [thread overview]
Message-ID: <1501757487-5782-6-git-send-email-jonatan.schlag@ipfire.org> (raw)
In-Reply-To: <1501757487-5782-1-git-send-email-jonatan.schlag@ipfire.org>
[-- Attachment #1: Type: text/plain, Size: 5307 bytes --]
Signed-off-by: Jonatan Schlag <jonatan.schlag(a)ipfire.org>
---
src/bash-completion/network | 185 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 184 insertions(+), 1 deletion(-)
diff --git a/src/bash-completion/network b/src/bash-completion/network
index 34d3f2f..4e392b9 100644
--- a/src/bash-completion/network
+++ b/src/bash-completion/network
@@ -340,6 +340,186 @@ _network_settings() {
COMPREPLY=( $(compgen -W "${keys}" -- "${cur}") )
}
+_network_vpn() {
+ local words=( $@ )
+
+ local commands="ipsec"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+
+
+ local args="${words[@]:1}"
+ case "${cmd}" in
+ ipsec)
+ _network_vpn_ipsec ${args}
+ ;;
+ esac
+}
+
+_network_vpn_ipsec() {
+ local words=( $@ )
+
+ local commands="connection"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+
+
+ local args="${words[@]:1}"
+ case "${cmd}" in
+ connection)
+ _network_vpn_ipsec_connection ${args}
+ ;;
+ esac
+}
+
+_network_vpn_ipsec_connection() {
+ local words=( $@ )
+
+ local commands="destroy new $(network raw list-ipsec-connections)"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+
+
+ local args="${words[@]:1}"
+ case "${cmd}" in
+ destroy)
+ :
+ ;;
+ new)
+ :
+ ;;
+ *)
+ if network raw ipsec-connection-exists ${cmd}; then
+ _network_vpn_ipsec_connection_subcommands ${cmd} ${args}
+ fi
+ ;;
+ esac
+}
+
+_network_vpn_ipsec_connection_subcommands() {
+ local connection=${1}
+ shift
+ local words=( $@ )
+
+ local commands="authentication inactivity-timout local mode peer remote security-policy show"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+
+
+ local args="${words[@]:1}"
+ case "${cmd}" in
+ authentication)
+ _network_vpn_ipsec_connection_subcommands_authentication ${connection} ${args}
+ ;;
+ local)
+ _network_vpn_ipsec_connection_subcommands_local_remote ${connection} "local" ${args}
+ ;;
+ mode)
+ _network_vpn_ipsec_connection_subcommands_mode ${args}
+ ;;
+ remote)
+ _network-vpn_ipsec_connection_subcommands_local_remote ${connection} "remote" ${args}
+ ;;
+ security-policy)
+ _network_vpn_ipsec_connection_subcommands_security_policy ${args}
+ ;;
+ esac
+}
+
+_network_vpn_ipsec_connection_subcommands_authentication() {
+ local connection=${1}
+ shift
+ local words=( $@ )
+
+ local commands="psk mode"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+
+
+ local args="${words[@]:1}"
+ case "${cmd}" in
+ mode)
+ _network_vpn_ipsec_connection_subcommands_authentication_mode ${connection} ${args}
+ ;;
+ esac
+}
+
+_network_vpn_ipsec_connection_subcommands_local_remote() {
+ local connection=${1}
+ local type=${2}
+ shift 2
+ local words=( $@ )
+
+ local commands="id prefix"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+
+
+ local args="${words[@]:1}"
+ case "${cmd}" in
+ prefix)
+ _network_vpn_ipsec_connection_subcommands_prefix "${connection}" "${type}" ${args}
+ ;;
+ esac
+}
+
+_network_vpn_ipsec_connection_subcommands_prefix() {
+ :
+}
+
+_network_vpn_ipsec_connection_subcommands_authentication_mode() {
+ local connection=${1}
+ shift
+ local words=( $@ )
+
+ local commands="PSK"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+}
+
+_network_vpn_ipsec_connection_subcommands_mode() {
+ local words=( $@ )
+
+ local commands="gre-transport tunnel vti"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+}
+
+_network_vpn_ipsec_connection_subcommands_security_policy() {
+ local words=( $@ )
+
+ local commands="$(network raw list-vpn-security-policies-all)"
+ local cmd="$(_network_find_on_cmdline "${commands}")"
+ if [[ -z "${cmd}" ]]; then
+ COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
+ return 0
+ fi
+}
+
_network_zone() {
local words=( $@ )
@@ -543,7 +723,7 @@ _network() {
;;
*)
COMPREPLY=( $(compgen -W "device dhcpv4 dhcpv6 dns-server \
- help hostname port reset route settings status zone" \
+ help hostname port reset route settings status vpn zone" \
-- "${cur}") )
;;
esac
@@ -575,6 +755,9 @@ _network() {
# start, stop and status optionally take a zone
_network_complete_zones
;;
+ vpn)
+ _network_vpn ${args}
+ ;;
zone)
_network_zone ${args}
;;
--
2.6.3
prev parent reply other threads:[~2017-08-03 10:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-03 10:51 [PATCH 1/6] ipsec: add new function ipsec_list_connections Jonatan Schlag
2017-08-03 10:51 ` [PATCH 2/6] vpn-security-policies: add new function vpn_security_policies_list_all Jonatan Schlag
2017-08-03 10:51 ` [PATCH 3/6] raw: add new command ipsec-connection-exists Jonatan Schlag
2017-08-03 10:51 ` [PATCH 4/6] raw: add new command list-ipsec-connections Jonatan Schlag
2017-08-03 10:51 ` [PATCH 5/6] raw: add command new list-vpn-security-policies-all Jonatan Schlag
2017-08-03 10:51 ` Jonatan Schlag [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1501757487-5782-6-git-send-email-jonatan.schlag@ipfire.org \
--to=jonatan.schlag@ipfire.org \
--cc=network@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox