| 1 |
# shellcheck shell=bash |
| 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 |
| 18 |
# along with systemd; If not, see <https://www.gnu.org/licenses/>. |
| 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 |
_systemd_cryptenroll() { |
| 42 |
local comps |
| 43 |
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword |
| 44 |
local -A OPTS=( |
| 45 |
[STANDALONE]='-h --help --version |
| 46 |
--password --recovery-key --list-devices' |
| 47 |
[ARG]='--unlock-key-file |
| 48 |
--unlock-fido2-device |
| 49 |
--unlock-tpm2-device |
| 50 |
--pkcs11-token-uri |
| 51 |
--fido2-credential-algorithm |
| 52 |
--fido2-device |
| 53 |
--fido2-salt-file |
| 54 |
--fido2-parameters-in-header |
| 55 |
--fido2-with-client-pin |
| 56 |
--fido2-with-user-presence |
| 57 |
--fido2-with-user-verification |
| 58 |
--tpm2-device |
| 59 |
--tpm2-device-key |
| 60 |
--tpm2-seal-key-handle |
| 61 |
--tpm2-pcrs |
| 62 |
--tpm2-public-key |
| 63 |
--tpm2-public-key-pcrs |
| 64 |
--tpm2-signature |
| 65 |
--tpm2-with-pin |
| 66 |
--tpm2-pcrlock |
| 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|--fido2-salt-file|--tpm2-device-key|--tpm2-public-key|--tpm2-signature|--tpm2-pcrlock) |
| 75 |
comps=$(compgen -A file -- "$cur") |
| 76 |
compopt -o filenames |
| 77 |
;; |
| 78 |
--unlock-fido2-device) |
| 79 |
comps="auto $(__get_fido2_devices)" |
| 80 |
;; |
| 81 |
--unlock-tpm2-device) |
| 82 |
comps="auto $(__get_tpm2_devices)" |
| 83 |
;; |
| 84 |
--pkcs11-token-uri) |
| 85 |
comps='auto list pkcs11:' |
| 86 |
;; |
| 87 |
--fido2-credential-algorithm) |
| 88 |
comps='es256 rs256 eddsa' |
| 89 |
;; |
| 90 |
--fido2-device) |
| 91 |
comps="auto list $(__get_fido2_devices)" |
| 92 |
;; |
| 93 |
--fido2-parameters-in-header|--fido2-with-client-pin|--fido2-with-user-presence|--fido2-with-user-verification|--tpm2-with-pin) |
| 94 |
comps='yes no' |
| 95 |
;; |
| 96 |
--tpm2-device) |
| 97 |
comps="auto list $(__get_tpm2_devices)" |
| 98 |
;; |
| 99 |
--wipe-slot) |
| 100 |
comps='all empty password recovery pkcs11 fido2 tpm2' |
| 101 |
;; |
| 102 |
esac |
| 103 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 104 |
return 0 |
| 105 |
fi |
| 106 |
|
| 107 |
if [[ "$cur" = -* ]]; then |
| 108 |
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) |
| 109 |
return 0 |
| 110 |
fi |
| 111 |
|
| 112 |
comps=$(systemd-cryptenroll --list-devices) |
| 113 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 114 |
return 0 |
| 115 |
} |
| 116 |
|
| 117 |
complete -F _systemd_cryptenroll systemd-cryptenroll |