1 # systemd-cryptenroll(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1-or-later
4 # This file is part of systemd.
6 # systemd is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation; either version 2.1 of the License, or
9 # (at your option) any later version.
11 # systemd is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
20 local w word=$1; shift
22 [[ $w = "$word" ]] && return
26 __get_fido2_devices() {
28 for i in /dev/hidraw*; do
29 [ -c "$i" ] && printf '%s\n' "$i"
33 __get_tpm2_devices() {
35 for i in /dev/tpmrm*; do
36 [ -c "$i" ] && printf '%s\n' "$i"
40 __get_block_devices() {
43 [ -b "$i" ] && printf '%s\n' "$i"
47 _systemd-cryptenroll() {
49 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
51 [STANDALONE]='-h --help --version
52 --password --recovery-key'
53 [ARG]='--unlock-key-file
56 --fido2-credential-algorithm
58 --fido2-with-client-pin
59 --fido2-with-user-presence
60 --fido2-with-user-verification
64 --tpm2-public-key-pcrs
70 _init_completion || return
72 if __contains_word "$prev" ${OPTS[ARG]}; then
74 --unlock-key-file|--tpm2-public-key|--tpm2-signature)
75 comps=$(compgen -A file -- "$cur")
78 --unlock-fido2-device)
79 comps="auto $(__get_fido2_devices)"
82 comps='auto list pkcs11:'
84 --fido2-credential-algorithm)
85 comps='es256 rs256 eddsa'
88 comps="auto list $(__get_fido2_devices)"
90 --fido2-with-client-pin|--fido2-with-user-presence|--fido2-with-user-verification|--tpm2-with-pin)
94 comps="auto list $(__get_tpm2_devices)"
97 comps='all empty password recovery pkcs11 fido2 tpm2'
100 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
104 if [[ "$cur" = -* ]]; then
105 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
109 comps=$(__get_block_devices)
110 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
114 complete -F _systemd-cryptenroll systemd-cryptenroll