]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-cryptenroll
66c6524fe8b4e803567503687bf93e5eeb0e69b3
[thirdparty/systemd.git] / shell-completion / bash / systemd-cryptenroll
1 # systemd-cryptenroll(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 #
4 # This file is part of systemd.
5 #
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.
10 #
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.
15 #
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/>.
18
19 __contains_word() {
20 local w word=$1; shift
21 for w in "$@"; do
22 [[ $w = "$word" ]] && return
23 done
24 }
25
26 __get_fido2_devices() {
27 local i
28 for i in /dev/hidraw*; do
29 [ -c "$i" ] && printf '%s\n' "$i"
30 done
31 }
32
33 __get_tpm2_devices() {
34 local i
35 for i in /dev/tpmrm*; do
36 [ -c "$i" ] && printf '%s\n' "$i"
37 done
38 }
39
40 __get_block_devices() {
41 local i
42 for i in /dev/*; do
43 [ -b "$i" ] && printf '%s\n' "$i"
44 done
45 }
46
47 _systemd-cryptenroll() {
48 local comps
49 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
50 local -A OPTS=(
51 [STANDALONE]='-h --help --version
52 --password --recovery-key'
53 [ARG]='--unlock-key-file
54 --unlock-fido2-device
55 --pkcs11-token-uri
56 --fido2-credential-algorithm
57 --fido2-device
58 --fido2-with-client-pin
59 --fido2-with-user-presence
60 --fido2-with-user-verification
61 --tpm2-device
62 --tpm2-pcrs
63 --tpm2-public-key
64 --tpm2-public-key-pcrs
65 --tpm2-signature
66 --tpm2-with-pin
67 --wipe-slot'
68 )
69
70 _init_completion || return
71
72 if __contains_word "$prev" ${OPTS[ARG]}; then
73 case $prev in
74 --unlock-key-file|--tpm2-public-key|--tpm2-signature)
75 comps=$(compgen -A file -- "$cur")
76 compopt -o filenames
77 ;;
78 --unlock-fido2-device)
79 comps="auto $(__get_fido2_devices)"
80 ;;
81 --pkcs11-token-uri)
82 comps='auto list pkcs11:'
83 ;;
84 --fido2-credential-algorithm)
85 comps='es256 rs256 eddsa'
86 ;;
87 --fido2-device)
88 comps="auto list $(__get_fido2_devices)"
89 ;;
90 --fido2-with-client-pin|--fido2-with-user-presence|--fido2-with-user-verification|--tpm2-with-pin)
91 comps='yes no'
92 ;;
93 --tpm2-device)
94 comps="auto list $(__get_tpm2_devices)"
95 ;;
96 --wipe-slot)
97 comps='all empty password recovery pkcs11 fido2 tpm2'
98 ;;
99 esac
100 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
101 return 0
102 fi
103
104 if [[ "$cur" = -* ]]; then
105 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
106 return 0
107 fi
108
109 comps=$(__get_block_devices)
110 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
111 return 0
112 }
113
114 complete -F _systemd-cryptenroll systemd-cryptenroll