RFC: bcc tools launcher
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
I propose creating `bcc` tool to launch bcc-tools python scripts. This is already tested on ALT Linux. `bcc` binary is not used by bcc so name is available, `/usr/bin/bcc` binary is used by `dev86` compiler package, so we install it into `/usr/sbin/bcc` (for root only) to not create conflict.
```sh
#!/bin/bash -efu
#
# Launcher for bcc tools
#
# Copyright (c) 2022 Vitaly Chikunov
toolsdir="/usr/share/bcc/tools"
list_commands() {
local lib
for lib in "${@-}"; do
find "$toolsdir$lib" -maxdepth 1 -type f -perm /1 -printf '%f\n'
done | sort
}
usage() {
echo "bcc-tools laucher"
echo "Usage: bcc [command options, such as --help]"
echo
echo "Available commands:"
cd "$toolsdir"
ls -d -x --color=auto $(list_commands)
echo
echo "Run 'bcc --man' to see manual page for the command (if available)."
echo " Or run 'man bcc-' directly."
echo "Run 'bcc --example' to see usage example for the command (if available)."
echo
echo "Add '$toolsdir' to the PATH to run commands directly, eg:"
echo " PATH=\$PATH:$toolsdir"
exit 0
}
[ -n "${1-}" ] || usage
declare -a args
for opt; do
case "$opt" in
--help) usage ;;
--list-commands) list_commands / /lib; exit ;;
-*) args+=("$opt") ;;
*) cmd="$opt"; break ;;
esac
shift
done
[ -n "${cmd:-}" ] || usage
cmd=$(basename "$cmd")
for lib in '/' '/lib/' ''; do
if [ -z "$lib" ]; then
echo >&2 "No such command '$cmd', run 'bcc' to see list of available commands."
exit 1
fi
[ -f "$toolsdir$lib$cmd" ] && [ -x "$toolsdir$lib$cmd" ] && break
done
# Rewind prepended options after cmd.
set -- "${args[@]}" "$@"
# Handle special (global) options ourselves.
for opt; do
case "$opt" in
--man)
man "bcc-$cmd"
exit
;;
--example*)
example="$toolsdir/doc$lib${cmd}_example.txt"
if [ -s "$example" ]; then
less "$example"
exit
else
echo >&2 "No example for '$cmd'."
exit 1
fi
;;
esac
done
shift
exec "$toolsdir$lib$cmd" "$@"
```
[bash-completion](https://github.com/scop/bash-completion) script for it:
```sh
# bash completion for bcc -*- shell-script -*-
_bcc()
{
local cur prev words cword
_init_completion || return
case "$prev" in
-l | --lib) _filedir; return ;;
-n | --name) _pnames; return ;;
-p | --pid) _pids; return ;;
-u | --uid) _uids; return ;;
--signal) _signals; return ;;
esac
local arg
_get_first_arg
if [[ -z $arg ]]; then
if [[ $cur == -* ]]; then
COMPREPLY=( $(compgen -W '--help' -- "$cur") )
else
COMPREPLY=( $(compgen -W '$(bcc --list-commands)' -- "$cur") )
fi
else
COMPREPLY=( $(compgen -W '$(bcc $arg -h --help | _parse_help -) --example --man' -- "$cur") )
fi
} &&
complete -F _bcc bcc
# ex: filetype=sh sw=4 et
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by checking how bcc-tools scripts are installed under /usr/share/bcc/tools and how packaged command-line utilities are exposed. Review the proposed /usr/sbin/bcc launcher and bash-completion behavior, then verify that commands, --man, --example, and --list-commands work without conflicting with the dev86 bcc binary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, shell
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100