summaryrefslogtreecommitdiff
path: root/completions/ipsec
diff options
context:
space:
mode:
Diffstat (limited to 'completions/ipsec')
-rw-r--r--completions/ipsec93
1 files changed, 75 insertions, 18 deletions
diff --git a/completions/ipsec b/completions/ipsec
index acb8c995..1a081028 100644
--- a/completions/ipsec
+++ b/completions/ipsec
@@ -1,22 +1,31 @@
-# Linux ipsec(8) completion (for FreeS/WAN)
+# Linux ipsec(8) completion (for FreeS/WAN and strongSwan) -*- shell-script -*-
+
+# Complete ipsec.conf conn entries.
#
-[ $UNAME = Linux ] && have ipsec &&
-_ipsec()
+# Reads a file from stdin in the ipsec.conf(5) format.
+_ipsec_connections()
{
- local cur
-
- COMPREPLY=()
- _get_comp_words_by_ref cur
+ local keyword name
+ while read -r keyword name; do
+ if [[ $keyword = [#]* ]]; then continue; fi
+ [[ $keyword == conn && $name != '%default' ]] && COMPREPLY+=( "$name" )
+ done
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]}' -- "$cur" ) )
+}
+_ipsec_freeswan()
+{
+ local cur prev words cword
+ _init_completion || return
- if [ $COMP_CWORD -eq 1 ]; then
+ if [ $cword -eq 1 ]; then
COMPREPLY=( $( compgen -W 'auto barf eroute klipsdebug look manual \
pluto ranbits rsasigkey setup showdefaults showhostkey spi spigrp \
tncfg whack' -- "$cur" ) )
return 0
fi
- case ${COMP_WORDS[1]} in
+ case ${words[1]} in
auto)
COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete \
--replace --down --route --unroute \
@@ -39,13 +48,61 @@ _ipsec()
esac
return 0
-} &&
-complete -F _ipsec ipsec
-
-# Local variables:
-# mode: shell-script
-# sh-basic-offset: 4
-# sh-indent-comment: t
-# indent-tabs-mode: nil
-# End:
+}
+
+_ipsec_strongswan()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ if [ $cword -eq 1 ]; then
+ COMPREPLY=( $( compgen -W 'down irdumm leases listaacerts listacerts \
+ listalgs listall listcacerts listcainfos listcards listcerts \
+ listcrls listgroups listocsp listocspcerts listpubkeys openac pki
+ pluto pool purgecerts purgecrls purgeike purgeocsp ready reload \
+ rereadaacerts rereadacerts rereadall rereadcacerts rereadcrls \
+ rereadgroups rereadocspcerts rereadsecrets restart route scdecrypt \
+ scencrypt scepclient secrets start starter status statusall stop \
+ stroke unroute uci up update version whack --confdir --copyright \
+ --directory --help --version --versioncode' -- "$cur" ) )
+ return 0
+ fi
+
+ case ${words[1]} in
+ down|route|status|statusall|unroute|up)
+ local confdir=$( ipsec --confdir )
+ _ipsec_connections < "$confdir/ipsec.conf"
+ ;;
+ list*)
+ COMPREPLY=( $( compgen -W '--utc' -- "$cur" ) )
+ ;;
+ restart|start)
+ COMPREPLY=( $( compgen -W '--attach-gdb --auto-update --debug \
+ --debug-all --debug-more --nofork' -- "$cur" ) )
+ ;;
+ pki)
+ COMPREPLY=( $( compgen -W '--gen --issue --keyid --print --pub \
+ --req --self --signcrl --verify' -- "$cur" ) )
+ ;;
+ pool)
+ ;;
+ irdumm)
+ _filedir 'rb'
+ ;;
+ *)
+ ;;
+ esac
+
+ return 0
+}
+
+case "$( ipsec --version 2>/dev/null )" in
+ *strongSwan*)
+ complete -F _ipsec_strongswan ipsec
+ ;;
+ *)
+ complete -F _ipsec_freeswan ipsec
+ ;;
+esac
+
# ex: ts=4 sw=4 et filetype=sh