From eec9b284b89cc5fec5dfb3efd28d759f6abbd18a Mon Sep 17 00:00:00 2001 From: Jose Carlos Venegas Munoz Date: Tue, 13 Mar 2018 11:53:54 -0600 Subject: [PATCH] scripts: Remove scripts for now. As part of initial import this is not need. Signed-off-by: Jose Carlos Venegas Munoz --- cli/Makefile | 11 - cli/data/cc-collect-data.sh.in | 367 ------------------------ cli/data/collect-data.sh.in | 367 ------------------------ cli/data/completions/bash/cc-runtime | 148 ---------- cli/data/completions/bash/cc-runtime.in | 148 ---------- cli/data/completions/bash/runtime.in | 148 ---------- 6 files changed, 1189 deletions(-) delete mode 100755 cli/data/cc-collect-data.sh.in delete mode 100755 cli/data/collect-data.sh.in delete mode 100644 cli/data/completions/bash/cc-runtime delete mode 100644 cli/data/completions/bash/cc-runtime.in delete mode 100644 cli/data/completions/bash/runtime.in diff --git a/cli/Makefile b/cli/Makefile index c4167b1811..3c916f5c41 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -239,17 +239,6 @@ DESTSYSCONFIG := $(abspath $(DESTSYSCONFDIR)/$(CONFIG_FILE)) DESTSHAREDIR := $(DESTDIR)/$(SHAREDIR) -BASH_COMPLETIONS_SRC := data/completions/bash/runtime.in -BASH_COMPLETIONS := data/completions/bash/$(TARGET) -BASH_COMPLETIONS_PROJ := $(BASH_COMPLETIONS).in - -BASH_COMPLETIONSDIR := $(DESTSHAREDIR)/bash-completion/completions -GENERATED_FILES += $(BASH_COMPLETIONS) - -COLLECT_SCRIPT_SRC = data/collect-data.sh.in -COLLECT_SCRIPT = data/$(PROJECT_TYPE)-collect-data.sh -COLLECT_SCRIPT_PROJ = $(COLLECT_SCRIPT).in - SCRIPTS += $(COLLECT_SCRIPT) SCRIPTS_DIR := $(BINDIR) diff --git a/cli/data/cc-collect-data.sh.in b/cli/data/cc-collect-data.sh.in deleted file mode 100755 index 20dbe5ebae..0000000000 --- a/cli/data/cc-collect-data.sh.in +++ /dev/null @@ -1,367 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2017-2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -script_name=${0##*/} -runtime_name="@RUNTIME_NAME@" -runtime=$(command -v "$runtime_name" 2>/dev/null) -issue_url="@PROJECT_BUG_URL@" -script_version="@VERSION@ (commit @COMMIT@)" - -# Maximum number of errors to show for a single system component -# (such as runtime or proxy). -PROBLEM_LIMIT=${PROBLEM_LIMIT:-50} - -# List of patterns used to detect problems in logfiles. -problem_pattern="(" -problem_pattern+="\&2 "ERROR: $script_name: $msg" - exit 1 -} - -msg() -{ - local msg="$*" - echo "$msg" -} - -heading() -{ - local name="$*" - echo -e "\n# $name\n" -} - -subheading() -{ - local name="$*" - echo -e "\n## $name\n" -} - -separator() -{ - echo -e '\n---\n' -} - -have_cmd() -{ - local cmd="$1" - - command -v "$cmd" &>/dev/null - local ret=$? - - if [ $ret -eq 0 ]; then - msg "Have \`$cmd\`" - else - msg "No \`$cmd\`" - fi - - [ $ret -eq 0 ] -} - -show_quoted_text() -{ - local text="$*" - - echo "\`\`\`" - echo "$text" - echo "\`\`\`" -} - -run_cmd_and_show_quoted_output() -{ - local cmd="$*" - - msg "Output of \"\`$cmd\`\":" - output=$(eval "$cmd" 2>&1) - show_quoted_text "$output" -} - -show_runtime_configs() -{ - local configs config - - heading "Runtime config files" - - configs=$($runtime --@PROJECT_TYPE@-show-default-config-paths) - if [ $? -ne 0 ]; then - version=$($runtime --version|tr '\n' ' ') - die "failed to check config files - runtime is probably too old ($version)" - fi - - subheading "Runtime default config files" - - show_quoted_text "$configs" - - # add in the standard defaults for good measure "just in case" - configs+=" /etc/@PROJECT_TAG@/configuration.toml" - configs+=" /usr/share/defaults/@PROJECT_TAG@/configuration.toml" - configs+=" @DESTCONFIG@" - configs+=" @DESTSYSCONFIG@" - - # create a unique list of config files - configs=$(echo $configs|tr ' ' '\n'|sort -u) - - subheading "Runtime config file contents" - - for config in $configs; do - if [ -e "$config" ]; then - run_cmd_and_show_quoted_output "cat \"$config\"" - else - msg "Config file \`$config\` not found" - fi - done - - separator -} - -show_log_details() -{ - heading "Logfiles" - - show_runtime_log_details - show_proxy_log_details - show_shim_log_details - - separator -} - -show_runtime_log_details() -{ - subheading "Runtime logs" - - find_system_journal_problems "runtime" "@RUNTIME_NAME@" "" -} - -find_system_journal_problems() -{ - local name="$1" - local program="$2" - local unit="$3" - - # select by identifier - local selector="-t" - - local data_source="system journal" - - local problems=$(journalctl -q -o cat -a "$selector" "$program" |\ - grep "time=" |\ - egrep -i "$problem_pattern" |\ - egrep -iv "$problem_exclude_pattern" |\ - tail -n ${PROBLEM_LIMIT}) - - if [ -n "$problems" ]; then - msg "Recent $name problems found in $data_source:" - show_quoted_text "$problems" - else - msg "No recent $name problems found in $data_source." - fi -} - -show_proxy_log_details() -{ - subheading "Proxy logs" - - find_system_journal_problems "proxy" "@PROJECT_TYPE@-proxy" "" -} - -show_shim_log_details() -{ - subheading "Shim logs" - - find_system_journal_problems "shim" "@PROJECT_TYPE@-shim" "" -} - -show_package_versions() -{ - heading "Packages" - - local pattern="(" - - # CC 2.x runtime. This shouldn't be installed but let's check anyway - pattern+="cc-oci-runtime" - - # core components - for project in @PROJECT_TYPES@ - do - pattern+="|${project}-proxy" - pattern+="|${project}-runtime" - pattern+="|${project}-shim" - done - - # assets - pattern+="|clear-containers-image" - pattern+="|linux-container" - - # optimised hypervisor - pattern+="|qemu-lite" - - # default distro hypervisor - pattern+="|qemu-system-x86" - - pattern+=")" - - if have_cmd "dpkg"; then - run_cmd_and_show_quoted_output "dpkg -l|egrep \"$pattern\"" - fi - - if have_cmd "rpm"; then - run_cmd_and_show_quoted_output "rpm -qa|egrep \"$pattern\"" - fi - - separator -} - -show_container_mgr_details() -{ - heading "Container manager details" - - if have_cmd "docker"; then - subheading "Docker" - run_cmd_and_show_quoted_output "docker version" - run_cmd_and_show_quoted_output "docker info" - run_cmd_and_show_quoted_output "systemctl show docker" - fi - - if have_cmd "kubectl"; then - subheading "Kubernetes" - run_cmd_and_show_quoted_output "kubectl version" - run_cmd_and_show_quoted_output "kubectl config view" - run_cmd_and_show_quoted_output "systemctl show kubelet" - - if have_cmd "crio"; then - run_cmd_and_show_quoted_output "crio --version" - run_cmd_and_show_quoted_output "systemctl show crio" - fi - fi - - separator -} - -show_meta() -{ - heading "Meta details" - - date=$(date '+%Y-%m-%d.%H:%M:%S.%N%z') - msg "Running \`$script_name\` version \`$script_version\` at \`$date\`." - - separator -} - -show_runtime() -{ - msg "Runtime is \`$runtime\`." - - cmd="@PROJECT_TYPE@-env" - heading "\`$cmd\`" - run_cmd_and_show_quoted_output "$runtime $cmd" - - separator -} - -main() -{ - case "$1" in - -h|--help|help) usage && exit 0;; - -v|--version|version) version && exit 0;; - esac - - [ $(id -u) -eq 0 ] || die "Need to run as root" - [ -n "$runtime" ] || die "cannot find runtime '$runtime_name'" - - show_meta - show_runtime - show_runtime_configs - show_log_details - show_container_mgr_details - show_package_versions -} - -main "$@" diff --git a/cli/data/collect-data.sh.in b/cli/data/collect-data.sh.in deleted file mode 100755 index 20dbe5ebae..0000000000 --- a/cli/data/collect-data.sh.in +++ /dev/null @@ -1,367 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2017-2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -script_name=${0##*/} -runtime_name="@RUNTIME_NAME@" -runtime=$(command -v "$runtime_name" 2>/dev/null) -issue_url="@PROJECT_BUG_URL@" -script_version="@VERSION@ (commit @COMMIT@)" - -# Maximum number of errors to show for a single system component -# (such as runtime or proxy). -PROBLEM_LIMIT=${PROBLEM_LIMIT:-50} - -# List of patterns used to detect problems in logfiles. -problem_pattern="(" -problem_pattern+="\&2 "ERROR: $script_name: $msg" - exit 1 -} - -msg() -{ - local msg="$*" - echo "$msg" -} - -heading() -{ - local name="$*" - echo -e "\n# $name\n" -} - -subheading() -{ - local name="$*" - echo -e "\n## $name\n" -} - -separator() -{ - echo -e '\n---\n' -} - -have_cmd() -{ - local cmd="$1" - - command -v "$cmd" &>/dev/null - local ret=$? - - if [ $ret -eq 0 ]; then - msg "Have \`$cmd\`" - else - msg "No \`$cmd\`" - fi - - [ $ret -eq 0 ] -} - -show_quoted_text() -{ - local text="$*" - - echo "\`\`\`" - echo "$text" - echo "\`\`\`" -} - -run_cmd_and_show_quoted_output() -{ - local cmd="$*" - - msg "Output of \"\`$cmd\`\":" - output=$(eval "$cmd" 2>&1) - show_quoted_text "$output" -} - -show_runtime_configs() -{ - local configs config - - heading "Runtime config files" - - configs=$($runtime --@PROJECT_TYPE@-show-default-config-paths) - if [ $? -ne 0 ]; then - version=$($runtime --version|tr '\n' ' ') - die "failed to check config files - runtime is probably too old ($version)" - fi - - subheading "Runtime default config files" - - show_quoted_text "$configs" - - # add in the standard defaults for good measure "just in case" - configs+=" /etc/@PROJECT_TAG@/configuration.toml" - configs+=" /usr/share/defaults/@PROJECT_TAG@/configuration.toml" - configs+=" @DESTCONFIG@" - configs+=" @DESTSYSCONFIG@" - - # create a unique list of config files - configs=$(echo $configs|tr ' ' '\n'|sort -u) - - subheading "Runtime config file contents" - - for config in $configs; do - if [ -e "$config" ]; then - run_cmd_and_show_quoted_output "cat \"$config\"" - else - msg "Config file \`$config\` not found" - fi - done - - separator -} - -show_log_details() -{ - heading "Logfiles" - - show_runtime_log_details - show_proxy_log_details - show_shim_log_details - - separator -} - -show_runtime_log_details() -{ - subheading "Runtime logs" - - find_system_journal_problems "runtime" "@RUNTIME_NAME@" "" -} - -find_system_journal_problems() -{ - local name="$1" - local program="$2" - local unit="$3" - - # select by identifier - local selector="-t" - - local data_source="system journal" - - local problems=$(journalctl -q -o cat -a "$selector" "$program" |\ - grep "time=" |\ - egrep -i "$problem_pattern" |\ - egrep -iv "$problem_exclude_pattern" |\ - tail -n ${PROBLEM_LIMIT}) - - if [ -n "$problems" ]; then - msg "Recent $name problems found in $data_source:" - show_quoted_text "$problems" - else - msg "No recent $name problems found in $data_source." - fi -} - -show_proxy_log_details() -{ - subheading "Proxy logs" - - find_system_journal_problems "proxy" "@PROJECT_TYPE@-proxy" "" -} - -show_shim_log_details() -{ - subheading "Shim logs" - - find_system_journal_problems "shim" "@PROJECT_TYPE@-shim" "" -} - -show_package_versions() -{ - heading "Packages" - - local pattern="(" - - # CC 2.x runtime. This shouldn't be installed but let's check anyway - pattern+="cc-oci-runtime" - - # core components - for project in @PROJECT_TYPES@ - do - pattern+="|${project}-proxy" - pattern+="|${project}-runtime" - pattern+="|${project}-shim" - done - - # assets - pattern+="|clear-containers-image" - pattern+="|linux-container" - - # optimised hypervisor - pattern+="|qemu-lite" - - # default distro hypervisor - pattern+="|qemu-system-x86" - - pattern+=")" - - if have_cmd "dpkg"; then - run_cmd_and_show_quoted_output "dpkg -l|egrep \"$pattern\"" - fi - - if have_cmd "rpm"; then - run_cmd_and_show_quoted_output "rpm -qa|egrep \"$pattern\"" - fi - - separator -} - -show_container_mgr_details() -{ - heading "Container manager details" - - if have_cmd "docker"; then - subheading "Docker" - run_cmd_and_show_quoted_output "docker version" - run_cmd_and_show_quoted_output "docker info" - run_cmd_and_show_quoted_output "systemctl show docker" - fi - - if have_cmd "kubectl"; then - subheading "Kubernetes" - run_cmd_and_show_quoted_output "kubectl version" - run_cmd_and_show_quoted_output "kubectl config view" - run_cmd_and_show_quoted_output "systemctl show kubelet" - - if have_cmd "crio"; then - run_cmd_and_show_quoted_output "crio --version" - run_cmd_and_show_quoted_output "systemctl show crio" - fi - fi - - separator -} - -show_meta() -{ - heading "Meta details" - - date=$(date '+%Y-%m-%d.%H:%M:%S.%N%z') - msg "Running \`$script_name\` version \`$script_version\` at \`$date\`." - - separator -} - -show_runtime() -{ - msg "Runtime is \`$runtime\`." - - cmd="@PROJECT_TYPE@-env" - heading "\`$cmd\`" - run_cmd_and_show_quoted_output "$runtime $cmd" - - separator -} - -main() -{ - case "$1" in - -h|--help|help) usage && exit 0;; - -v|--version|version) version && exit 0;; - esac - - [ $(id -u) -eq 0 ] || die "Need to run as root" - [ -n "$runtime" ] || die "cannot find runtime '$runtime_name'" - - show_meta - show_runtime - show_runtime_configs - show_log_details - show_container_mgr_details - show_package_versions -} - -main "$@" diff --git a/cli/data/completions/bash/cc-runtime b/cli/data/completions/bash/cc-runtime deleted file mode 100644 index 651af11d21..0000000000 --- a/cli/data/completions/bash/cc-runtime +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2017-2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#--------------------------------------------------------------------- - -#--------------------------------------------------------------------- -# Description: Bash tab completion script. -#--------------------------------------------------------------------- - -_runtime='cc-runtime' - -# Return a list of sub-commands -_cc_get_subcmds() -{ - "$_runtime" --generate-bash-completion -} - -# Return a list of options for the specified sub-command -# -# Limitation: Note that this only supports long-options. -_cc_get_subcmd_options() -{ - local subcmd="$1" - - "$_runtime" "$subcmd" --help |\ - egrep -- "^ *--[^ ]*[ ][^ ]*" |\ - awk '{print $1}' |\ - tr -d \, |\ - sort -} - -# Return a list of global options -_cc_get_global_options() -{ - _cc_get_subcmd_options "" -} - -# Return name of subcmd already seen, or "" -_cc_subcmd_seen() -{ - local subcmds=$(_cc_get_subcmds) - local cmd - - for cmd in $subcmds; do - local word - for word in ${COMP_WORDS[@]}; do - [ "$cmd" = "$word" ] && echo "$cmd" - done - done - - echo "" -} - -# Return 0 if the specified sub-command requires the name of an -# *existing* container, else 1. -_cc_subcmd_needs_existing_container() -{ - local subcmd="$1" - local cmd - - for cmd in \ - 'cc-check' \ - 'cc-env' \ - 'create' \ - 'help' \ - 'list' \ - 'version'; do - [ "$cmd" = "$subcmd" ] && return 1 - done - - return 0 -} - -# Returns a list of container names -_cc_get_containers() -{ - # Commands that manipulate containers need root privileges. - # If the user isn't running as root, don't attempt to obtain a list - # as it will result in an error. - [ $(id -u) -eq 0 ] || return - - "$_runtime" list --quiet -} - -_cc_bash_autocomplete() { - COMPREPLY=() - - local opts opt - - local cur="${COMP_WORDS[COMP_CWORD]}" - - for opt in \ - '-h' '--help' 'help' \ - '-v' '--version' 'version'; - do - # No further completions possible for these commands - [ "$cur" = "$opt" ] && return 0 - done - - local subcmd_seen=$(_cc_subcmd_seen) - - if [ -n "$subcmd_seen" ]; then - _cc_subcmd_needs_existing_container "$subcmd_seen" - local container_cmd=$? - - if [ -n "$cur" ]; then - # Complete with local options and maybe container names - opts=$(_cc_get_subcmd_options "$subcmd_seen") - [ $container_cmd -eq 0 ] && opts="$opts $(_cc_get_containers)" - elif [[ "${cur}" == -* ]]; then - # Complete with local options - opts=$(_cc_get_subcmd_options "$subcmd_seen") - else - # Potentially complete with container names - [ $container_cmd -eq 0 ] && opts="$(_cc_get_containers)" - fi - else - if [ -n "$cur" ]; then - # Complete with global options and subcmds - opts="$opts $(_cc_get_global_options)" - opts="$opts $(_cc_get_subcmds)" - elif [[ "${cur}" == -* ]]; then - # Complete with global options - opts=$(_cc_get_global_options) - else - # Complete with subcmds - opts=$(_cc_get_subcmds) - fi - fi - - [ -n "$opts" ] && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - - return 0 -} - -complete -F _cc_bash_autocomplete "$_runtime" diff --git a/cli/data/completions/bash/cc-runtime.in b/cli/data/completions/bash/cc-runtime.in deleted file mode 100644 index 82ac084265..0000000000 --- a/cli/data/completions/bash/cc-runtime.in +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2017-2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#--------------------------------------------------------------------- - -#--------------------------------------------------------------------- -# Description: Bash tab completion script. -#--------------------------------------------------------------------- - -_runtime='@RUNTIME_NAME@' - -# Return a list of sub-commands -_@PROJECT_TYPE@_get_subcmds() -{ - "$_runtime" --generate-bash-completion -} - -# Return a list of options for the specified sub-command -# -# Limitation: Note that this only supports long-options. -_@PROJECT_TYPE@_get_subcmd_options() -{ - local subcmd="$1" - - "$_runtime" "$subcmd" --help |\ - egrep -- "^ *--[^ ]*[ ][^ ]*" |\ - awk '{print $1}' |\ - tr -d \, |\ - sort -} - -# Return a list of global options -_@PROJECT_TYPE@_get_global_options() -{ - _@PROJECT_TYPE@_get_subcmd_options "" -} - -# Return name of subcmd already seen, or "" -_@PROJECT_TYPE@_subcmd_seen() -{ - local subcmds=$(_@PROJECT_TYPE@_get_subcmds) - local cmd - - for cmd in $subcmds; do - local word - for word in ${COMP_WORDS[@]}; do - [ "$cmd" = "$word" ] && echo "$cmd" - done - done - - echo "" -} - -# Return 0 if the specified sub-command requires the name of an -# *existing* container, else 1. -_@PROJECT_TYPE@_subcmd_needs_existing_container() -{ - local subcmd="$1" - local cmd - - for cmd in \ - '@PROJECT_TYPE@-check' \ - '@PROJECT_TYPE@-env' \ - 'create' \ - 'help' \ - 'list' \ - 'version'; do - [ "$cmd" = "$subcmd" ] && return 1 - done - - return 0 -} - -# Returns a list of container names -_@PROJECT_TYPE@_get_containers() -{ - # Commands that manipulate containers need root privileges. - # If the user isn't running as root, don't attempt to obtain a list - # as it will result in an error. - [ $(id -u) -eq 0 ] || return - - "$_runtime" list --quiet -} - -_@PROJECT_TYPE@_bash_autocomplete() { - COMPREPLY=() - - local opts opt - - local cur="${COMP_WORDS[COMP_CWORD]}" - - for opt in \ - '-h' '--help' 'help' \ - '-v' '--version' 'version'; - do - # No further completions possible for these commands - [ "$cur" = "$opt" ] && return 0 - done - - local subcmd_seen=$(_@PROJECT_TYPE@_subcmd_seen) - - if [ -n "$subcmd_seen" ]; then - _@PROJECT_TYPE@_subcmd_needs_existing_container "$subcmd_seen" - local container_cmd=$? - - if [ -n "$cur" ]; then - # Complete with local options and maybe container names - opts=$(_@PROJECT_TYPE@_get_subcmd_options "$subcmd_seen") - [ $container_cmd -eq 0 ] && opts="$opts $(_@PROJECT_TYPE@_get_containers)" - elif [[ "${cur}" == -* ]]; then - # Complete with local options - opts=$(_@PROJECT_TYPE@_get_subcmd_options "$subcmd_seen") - else - # Potentially complete with container names - [ $container_cmd -eq 0 ] && opts="$(_@PROJECT_TYPE@_get_containers)" - fi - else - if [ -n "$cur" ]; then - # Complete with global options and subcmds - opts="$opts $(_@PROJECT_TYPE@_get_global_options)" - opts="$opts $(_@PROJECT_TYPE@_get_subcmds)" - elif [[ "${cur}" == -* ]]; then - # Complete with global options - opts=$(_@PROJECT_TYPE@_get_global_options) - else - # Complete with subcmds - opts=$(_@PROJECT_TYPE@_get_subcmds) - fi - fi - - [ -n "$opts" ] && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - - return 0 -} - -complete -F _@PROJECT_TYPE@_bash_autocomplete "$_runtime" diff --git a/cli/data/completions/bash/runtime.in b/cli/data/completions/bash/runtime.in deleted file mode 100644 index 82ac084265..0000000000 --- a/cli/data/completions/bash/runtime.in +++ /dev/null @@ -1,148 +0,0 @@ -#!/bin/bash -# -# Copyright (c) 2017-2018 Intel Corporation -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#--------------------------------------------------------------------- - -#--------------------------------------------------------------------- -# Description: Bash tab completion script. -#--------------------------------------------------------------------- - -_runtime='@RUNTIME_NAME@' - -# Return a list of sub-commands -_@PROJECT_TYPE@_get_subcmds() -{ - "$_runtime" --generate-bash-completion -} - -# Return a list of options for the specified sub-command -# -# Limitation: Note that this only supports long-options. -_@PROJECT_TYPE@_get_subcmd_options() -{ - local subcmd="$1" - - "$_runtime" "$subcmd" --help |\ - egrep -- "^ *--[^ ]*[ ][^ ]*" |\ - awk '{print $1}' |\ - tr -d \, |\ - sort -} - -# Return a list of global options -_@PROJECT_TYPE@_get_global_options() -{ - _@PROJECT_TYPE@_get_subcmd_options "" -} - -# Return name of subcmd already seen, or "" -_@PROJECT_TYPE@_subcmd_seen() -{ - local subcmds=$(_@PROJECT_TYPE@_get_subcmds) - local cmd - - for cmd in $subcmds; do - local word - for word in ${COMP_WORDS[@]}; do - [ "$cmd" = "$word" ] && echo "$cmd" - done - done - - echo "" -} - -# Return 0 if the specified sub-command requires the name of an -# *existing* container, else 1. -_@PROJECT_TYPE@_subcmd_needs_existing_container() -{ - local subcmd="$1" - local cmd - - for cmd in \ - '@PROJECT_TYPE@-check' \ - '@PROJECT_TYPE@-env' \ - 'create' \ - 'help' \ - 'list' \ - 'version'; do - [ "$cmd" = "$subcmd" ] && return 1 - done - - return 0 -} - -# Returns a list of container names -_@PROJECT_TYPE@_get_containers() -{ - # Commands that manipulate containers need root privileges. - # If the user isn't running as root, don't attempt to obtain a list - # as it will result in an error. - [ $(id -u) -eq 0 ] || return - - "$_runtime" list --quiet -} - -_@PROJECT_TYPE@_bash_autocomplete() { - COMPREPLY=() - - local opts opt - - local cur="${COMP_WORDS[COMP_CWORD]}" - - for opt in \ - '-h' '--help' 'help' \ - '-v' '--version' 'version'; - do - # No further completions possible for these commands - [ "$cur" = "$opt" ] && return 0 - done - - local subcmd_seen=$(_@PROJECT_TYPE@_subcmd_seen) - - if [ -n "$subcmd_seen" ]; then - _@PROJECT_TYPE@_subcmd_needs_existing_container "$subcmd_seen" - local container_cmd=$? - - if [ -n "$cur" ]; then - # Complete with local options and maybe container names - opts=$(_@PROJECT_TYPE@_get_subcmd_options "$subcmd_seen") - [ $container_cmd -eq 0 ] && opts="$opts $(_@PROJECT_TYPE@_get_containers)" - elif [[ "${cur}" == -* ]]; then - # Complete with local options - opts=$(_@PROJECT_TYPE@_get_subcmd_options "$subcmd_seen") - else - # Potentially complete with container names - [ $container_cmd -eq 0 ] && opts="$(_@PROJECT_TYPE@_get_containers)" - fi - else - if [ -n "$cur" ]; then - # Complete with global options and subcmds - opts="$opts $(_@PROJECT_TYPE@_get_global_options)" - opts="$opts $(_@PROJECT_TYPE@_get_subcmds)" - elif [[ "${cur}" == -* ]]; then - # Complete with global options - opts=$(_@PROJECT_TYPE@_get_global_options) - else - # Complete with subcmds - opts=$(_@PROJECT_TYPE@_get_subcmds) - fi - fi - - [ -n "$opts" ] && COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) - - return 0 -} - -complete -F _@PROJECT_TYPE@_bash_autocomplete "$_runtime"