clevis 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 "Command '$cmd' is invalid" >&2
  35. echo >&2
  36. echo "Usage: clevis COMMAND [OPTIONS]" >&2
  37. echo >&2
  38. max=0
  39. for f in $0-*; do
  40. [ -f "$f" -a -x "$f" ] || continue
  41. f=${f##*/}
  42. [ ${#f} -gt $max ] && max=${#f}
  43. done
  44. for f in $0-*; do
  45. [ -f "$f" -a -x "$f" ] || continue
  46. summ=`$f --summary 2>/dev/null` || continue
  47. f=${f##*/}
  48. printf " %-*s %s\n" "$max" "${f//-/ }" "$summ" >&2
  49. done
  50. echo >&2
  51. exit 1