clevis 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash -e
  2. # vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80:
  3. #
  4. # Copyright (c) 2017 Red Hat, Inc.
  5. # Author: Nathaniel McCallum <npmccallum@redhat.com>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. function findexe() {
  21. while read -d: path; do
  22. [ -f "$path/$1" -a -x "$path/$1" ] && echo "$path/$1" && return 0
  23. done <<< "$PATH:"
  24. return 1
  25. }
  26. cmd=clevis
  27. while [ $# -gt 0 ]; do
  28. [[ "$1" =~ ^- ]] && break
  29. cmd="$cmd-$1"
  30. shift
  31. exe=`findexe "$cmd"` && exec "$exe" "$@"
  32. done
  33. echo >&2
  34. echo "Usage: clevis COMMAND [OPTIONS]" >&2
  35. echo >&2
  36. max=0
  37. for f in $0-*; do
  38. [ -f "$f" -a -x "$f" ] || continue
  39. f=${f##*/}
  40. [ ${#f} -gt $max ] && max=${#f}
  41. done
  42. for f in $0-*; do
  43. [ -f "$f" -a -x "$f" ] || continue
  44. summ=`$f --summary 2>/dev/null` || continue
  45. f=${f##*/}
  46. printf " %-*s %s\n" "$max" "${f//-/ }" "$summ" >&2
  47. done
  48. echo >&2