mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-04 21:02:29 +00:00

The offline updates environment is special, and we have to be careful to delete the trigger before doing anything that can fail to avoid boot loops. For this reason, split it out to a simple self-contained binary that is easy to understand.
165 lines
3.0 KiB
Plaintext
165 lines
3.0 KiB
Plaintext
_fwupdmgr_cmd_list=(
|
|
'activate'
|
|
'clear-history'
|
|
'clear-offline'
|
|
'clear-results'
|
|
'disable-remote'
|
|
'downgrade'
|
|
'enable-remote'
|
|
'get-approved-firmware'
|
|
'get-details'
|
|
'get-devices'
|
|
'get-history'
|
|
'get-releases'
|
|
'get-remotes'
|
|
'get-results'
|
|
'get-topology'
|
|
'get-updates'
|
|
'install'
|
|
'modify-remote'
|
|
'refresh'
|
|
'report-history'
|
|
'set-approved-firmware'
|
|
'unlock'
|
|
'update'
|
|
'verify'
|
|
'verify-update'
|
|
'--version'
|
|
)
|
|
|
|
_fwupdmgr_opts=(
|
|
'--verbose'
|
|
'--offline'
|
|
'--allow-reinstall'
|
|
'--allow-older'
|
|
'--force'
|
|
'--assume-yes'
|
|
'--no-history'
|
|
'--no-unreported-check'
|
|
'--no-metadata-check'
|
|
'--no-reboot-check'
|
|
'--show-all-devices'
|
|
)
|
|
|
|
_show_modifiers()
|
|
{
|
|
COMPREPLY+=( $(compgen -W '${_fwupdmgr_opts[@]}' -- "$cur") )
|
|
}
|
|
|
|
_show_device_ids()
|
|
{
|
|
local description
|
|
OLDIFS=$IFS
|
|
IFS=$'\n'
|
|
description="$(command fwupdmgr get-devices | command awk '!/DeviceId/ { line = $0 }; /DeviceId/ { print $2 " {" line "}"}')"
|
|
COMPREPLY+=( $(compgen -W "${description}" -- "$cur") )
|
|
IFS=$OLDIFS
|
|
}
|
|
|
|
_show_remotes()
|
|
{
|
|
local remotes
|
|
remotes="$(command fwupdmgr get-remotes | command awk '/Remote ID/ { print $3 }')"
|
|
COMPREPLY+=( $(compgen -W "${remotes}" -- "$cur") )
|
|
}
|
|
|
|
_fwupdmgr()
|
|
{
|
|
local cur prev command
|
|
COMPREPLY=()
|
|
cur=`_get_cword`
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
command=${COMP_WORDS[1]}
|
|
|
|
case $command in
|
|
activate|clear-results|downgrade|get-releases|get-results|unlock|verify|verify-update)
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_show_device_ids
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
get-details)
|
|
#browse for file
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_filedir
|
|
#modifiers
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
install)
|
|
#find files
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_filedir
|
|
#device ID or modifiers
|
|
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
|
_show_device_ids
|
|
_show_modifiers
|
|
#modifiers
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
modify-remote)
|
|
#find remotes
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_show_remotes
|
|
#add key
|
|
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
|
local keys
|
|
keys="$(command fwupdmgr get-remotes | command awk -v pattern="Remote ID:.*${prev}$" '$0~pattern{show=1; next}/Remote/{show=0}{gsub(/:.*/,"")}show')"
|
|
COMPREPLY+=( $(compgen -W "${keys}" -- "$cur") )
|
|
#modifiers
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
enable-remote)
|
|
#find remotes
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_show_remotes
|
|
#modifiers
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
disable-remote)
|
|
#find remotes
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_show_remotes
|
|
#modifiers
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
refresh)
|
|
#find first file
|
|
if [[ "$prev" = "$command" ]]; then
|
|
_filedir
|
|
#find second file
|
|
elif [[ "$prev" = "${COMP_WORDS[2]}" ]]; then
|
|
_filedir
|
|
#find remote ID
|
|
elif [[ "$prev" = "${COMP_WORDS[3]}" ]]; then
|
|
_show_remotes
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
*)
|
|
#find first command
|
|
if [[ ${COMP_CWORD} = 1 ]]; then
|
|
COMPREPLY=( $(compgen -W '${_fwupdmgr_cmd_list[@]}' -- "$cur") )
|
|
#modifiers for all commands
|
|
else
|
|
_show_modifiers
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
return 0
|
|
}
|
|
|
|
complete -F _fwupdmgr fwupdmgr
|