
The original cgcs-patch is rpm based which requires a complete re-write to work on ostree/dpkg systems like Debian. The code has been forked, since the older Centos env and python2.7 are end-of-life. Forking the code allows all new development to not require re-testing on Centos. The debian folder under cgcs-patch has been moved under sw-patch Renaming and refactoring will be done in later commits. pylint is un-clamped in order to work on python3.9 Some minor pylint suppressions have been added. Test Plan: Verify that this builds on Debian Verify that the ISO installs the new content on Debian without breaking packages that import cgcs_patch. Verify patching service runs on Debian Co-Authored-By: Jessica Castelino <jessica.castelino@windriver.com> Story: 2009101 Task: 43076 Signed-off-by: Al Bailey <al.bailey@windriver.com> Change-Id: I3f1bca749404053bae63d4bcc9fb2477cf909fcd
149 lines
5.2 KiB
Plaintext
149 lines
5.2 KiB
Plaintext
#
|
|
# Copyright (c) 2016 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
#
|
|
# This file provides bash-completion functionality for the sw-patch CLI
|
|
#
|
|
|
|
function _swpatch()
|
|
{
|
|
COMPREPLY=()
|
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
local subcommand=${COMP_WORDS[1]}
|
|
|
|
#
|
|
# The available sw-patch subcommands
|
|
#
|
|
local subcommands="
|
|
apply
|
|
commit
|
|
delete
|
|
query
|
|
query-dependencies
|
|
query-hosts
|
|
remove
|
|
show
|
|
upload
|
|
upload-dir
|
|
what-requires
|
|
drop-host
|
|
is-applied
|
|
is-available
|
|
report-app-dependencies
|
|
query-app-dependencies
|
|
"
|
|
if [ -f /etc/platform/.initial_config_complete ]; then
|
|
# Post-config, so the host-install commands are accessible
|
|
subcommands="${subcommands} host-install host-install-async"
|
|
else
|
|
# Pre-config, so the install-local command is accessible
|
|
subcommands="${subcommands} install-local"
|
|
fi
|
|
|
|
# Appends the '/' when completing dir names
|
|
set mark-directories on
|
|
|
|
if [ $COMP_CWORD -gt 1 ]; then
|
|
#
|
|
# Complete the arguments to the subcommands.
|
|
#
|
|
case "$subcommand" in
|
|
apply|delete|show|what-requires|is-applied|is-available)
|
|
# Query the list of known patches
|
|
local patches=$(sw-patch completion patches 2>/dev/null)
|
|
COMPREPLY=( $(compgen -W "${patches}" -- ${cur}) )
|
|
return 0
|
|
;;
|
|
remove)
|
|
# Query the list of known patches
|
|
local patches=$(sw-patch completion patches 2>/dev/null)
|
|
COMPREPLY=( $(compgen -W "--skipappcheck ${patches}" -- ${cur}) )
|
|
return 0
|
|
;;
|
|
host-install|host-install-async|drop-host)
|
|
if [ "${prev}" = "${subcommand}" -o "${prev}" = "--force" ]; then
|
|
# Query the list of known hosts
|
|
local names=$(sw-patch completion hosts 2>/dev/null)
|
|
COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
|
|
else
|
|
# Only one host can be specified, so no more completion
|
|
COMPREPLY=( $(compgen -- ${cur}) )
|
|
fi
|
|
return 0
|
|
;;
|
|
upload)
|
|
# Allow dirs and files with .patch extension for completion
|
|
COMPREPLY=( $(compgen -f -o plusdirs -X '!*.patch' -- ${cur}) )
|
|
return 0
|
|
;;
|
|
upload-dir)
|
|
# Allow dirs only for completion
|
|
COMPREPLY=( $(compgen -d -- ${cur}) )
|
|
return 0
|
|
;;
|
|
query)
|
|
if [ "${prev}" = "--release" ]; then
|
|
# If --release has been specified, provide installed releases for completion
|
|
local releases=$(/bin/ls -d /var/www/pages/feed/rel-* 2>/dev/null | sed 's#/var/www/pages/feed/rel-##')
|
|
COMPREPLY=( $(compgen -W "${releases}" -- ${cur}) )
|
|
else
|
|
# --release is only completion option for query
|
|
COMPREPLY=( $(compgen -W "--release" -- ${cur}) )
|
|
fi
|
|
return 0
|
|
;;
|
|
query-hosts|install-local)
|
|
# These subcommands have no options/arguments
|
|
COMPREPLY=( $(compgen -- ${cur}) )
|
|
return 0
|
|
;;
|
|
query-dependencies)
|
|
# Query the list of known patches
|
|
local patches=$(sw-patch completion patches 2>/dev/null)
|
|
COMPREPLY=( $(compgen -W "--recursive ${patches}" -- ${cur}) )
|
|
return 0
|
|
;;
|
|
commit)
|
|
if [ "${prev}" = "--release" ]; then
|
|
# If --release has been specified, provide installed releases for completion
|
|
local releases=$(/bin/ls -d /var/www/pages/feed/rel-* 2>/dev/null | sed 's#/var/www/pages/feed/rel-##')
|
|
COMPREPLY=( $(compgen -W "${releases}" -- ${cur}) )
|
|
else
|
|
# Query the list of known patches
|
|
local patches=$(sw-patch completion patches 2>/dev/null)
|
|
COMPREPLY=( $(compgen -W "--all --dry-run --release ${patches}" -- ${cur}) )
|
|
fi
|
|
return 0
|
|
;;
|
|
report-app-dependencies)
|
|
if [ "${prev}" = "${subcommand}" ]; then
|
|
COMPREPLY=( $(compgen -W "--app" -- ${cur}) )
|
|
elif [ "${prev}" = "--app" ]; then
|
|
COMPREPLY=
|
|
else
|
|
local patches=$(sw-patch completion patches 2>/dev/null)
|
|
COMPREPLY=( $(compgen -W "${patches}" -- ${cur}) )
|
|
fi
|
|
return 0
|
|
;;
|
|
query-app-dependencies)
|
|
return 0
|
|
;;
|
|
*)
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
# Provide subcommands for completion
|
|
COMPREPLY=($(compgen -W "${subcommands}" -- ${cur}))
|
|
return 0
|
|
}
|
|
|
|
# Bind the above function to the sw-patch CLI
|
|
complete -F _swpatch -o filenames sw-patch
|
|
|