summaryrefslogtreecommitdiff
path: root/completions/ipsec
blob: b1161b0a19622661e052fbb45dfc65bcd2a939fa (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Linux ipsec(8) completion (for FreeS/WAN and strongSwan) -*- shell-script -*-

# Complete ipsec.conf conn entries.
#
# Reads a file from stdin in the ipsec.conf(5) format.
_ipsec_connections()
{
    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 [[ $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 ${words[1]} in
        auto)
            COMPREPLY=( $( compgen -W '--asynchronous --up --add --delete
                --replace --down --route --unroute --ready --status
                --rereadsecrets' -- "$cur" ) )
            ;;
        manual)
            COMPREPLY=( $( compgen -W '--up --down --route --unroute --union' \
                -- "$cur" ) )
            ;;
        ranbits)
            COMPREPLY=( $( compgen -W '--quick --continuous --bytes' \
                -- "$cur" ) )
            ;;
        setup)
            COMPREPLY=( $( compgen -W '--start --stop --restart' -- "$cur" ) )
            ;;
        *)
            ;;
    esac

    return 0
}

_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