]>
Commit | Line | Data |
---|---|---|
f8457290 | 1 | # shellcheck shell=bash |
9a2d94dd AAF |
2 | # systemd-cryptenroll(1) completion -*- shell-script -*- |
3 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
4 | # | |
5 | # This file is part of systemd. | |
6 | # | |
7 | # systemd is free software; you can redistribute it and/or modify it | |
8 | # under the terms of the GNU Lesser General Public License as published by | |
9 | # the Free Software Foundation; either version 2.1 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # systemd is distributed in the hope that it will be useful, but | |
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | # General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU Lesser General Public License | |
85fce6f4 | 18 | # along with systemd; If not, see <https://www.gnu.org/licenses/>. |
9a2d94dd AAF |
19 | |
20 | __contains_word() { | |
21 | local w word=$1; shift | |
22 | for w in "$@"; do | |
23 | [[ $w = "$word" ]] && return | |
24 | done | |
25 | } | |
26 | ||
27 | __get_fido2_devices() { | |
28 | local i | |
29 | for i in /dev/hidraw*; do | |
30 | [ -c "$i" ] && printf '%s\n' "$i" | |
31 | done | |
32 | } | |
33 | ||
34 | __get_tpm2_devices() { | |
35 | local i | |
36 | for i in /dev/tpmrm*; do | |
37 | [ -c "$i" ] && printf '%s\n' "$i" | |
38 | done | |
39 | } | |
40 | ||
41 | __get_block_devices() { | |
42 | local i | |
43 | for i in /dev/*; do | |
44 | [ -b "$i" ] && printf '%s\n' "$i" | |
45 | done | |
46 | } | |
47 | ||
c13d9199 | 48 | _systemd_cryptenroll() { |
9a2d94dd AAF |
49 | local comps |
50 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword | |
51 | local -A OPTS=( | |
52 | [STANDALONE]='-h --help --version | |
53 | --password --recovery-key' | |
82ff978d | 54 | [ARG]='--unlock-key-file |
4d206f1c | 55 | --unlock-fido2-device |
631cf7f0 | 56 | --unlock-tpm2-device |
82ff978d | 57 | --pkcs11-token-uri |
9a2d94dd AAF |
58 | --fido2-credential-algorithm |
59 | --fido2-device | |
60 | --fido2-with-client-pin | |
61 | --fido2-with-user-presence | |
62 | --fido2-with-user-verification | |
63 | --tpm2-device | |
c13d9199 AAF |
64 | --tpm2-device-key |
65 | --tpm2-seal-key-handle | |
9a2d94dd | 66 | --tpm2-pcrs |
82ff978d AAF |
67 | --tpm2-public-key |
68 | --tpm2-public-key-pcrs | |
69 | --tpm2-signature | |
9a2d94dd | 70 | --tpm2-with-pin |
c13d9199 | 71 | --tpm2-pcrlock |
9a2d94dd AAF |
72 | --wipe-slot' |
73 | ) | |
74 | ||
75 | _init_completion || return | |
76 | ||
77 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
78 | case $prev in | |
c13d9199 | 79 | --unlock-key-file|--tpm2-device-key|--tpm2-public-key|--tpm2-signature|--tpm2-pcrlock) |
82ff978d AAF |
80 | comps=$(compgen -A file -- "$cur") |
81 | compopt -o filenames | |
82 | ;; | |
4d206f1c AAF |
83 | --unlock-fido2-device) |
84 | comps="auto $(__get_fido2_devices)" | |
85 | ;; | |
631cf7f0 GAP |
86 | --unlock-tpm2-device) |
87 | comps="auto $(__get_tpm2_devices)" | |
88 | ;; | |
9a2d94dd AAF |
89 | --pkcs11-token-uri) |
90 | comps='auto list pkcs11:' | |
91 | ;; | |
92 | --fido2-credential-algorithm) | |
93 | comps='es256 rs256 eddsa' | |
94 | ;; | |
95 | --fido2-device) | |
96 | comps="auto list $(__get_fido2_devices)" | |
97 | ;; | |
98 | --fido2-with-client-pin|--fido2-with-user-presence|--fido2-with-user-verification|--tpm2-with-pin) | |
99 | comps='yes no' | |
100 | ;; | |
101 | --tpm2-device) | |
102 | comps="auto list $(__get_tpm2_devices)" | |
103 | ;; | |
104 | --wipe-slot) | |
105 | comps='all empty password recovery pkcs11 fido2 tpm2' | |
106 | ;; | |
107 | esac | |
108 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
109 | return 0 | |
110 | fi | |
111 | ||
112 | if [[ "$cur" = -* ]]; then | |
113 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
114 | return 0 | |
115 | fi | |
116 | ||
117 | comps=$(__get_block_devices) | |
118 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
119 | return 0 | |
120 | } | |
121 | ||
c13d9199 | 122 | complete -F _systemd_cryptenroll systemd-cryptenroll |