checkShellScripts.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (c) 2019 The Tor Project, Inc.
  4. # See LICENSE for license information
  5. #
  6. # checkShellScripts.sh
  7. # --------------------
  8. # If shellcheck is installed, check all the shell scripts that we can fix.
  9. set -e
  10. # Only run this script if shellcheck is installed
  11. # command echoes the path to shellcheck, which is a useful diagnostic log
  12. if ! command -v shellcheck; then
  13. printf "%s: Install shellcheck to check shell scripts.\\n" "$0"
  14. exit 0
  15. fi
  16. # Some platforms don't have realpath
  17. if command -v realpath ; then
  18. HERE=$(dirname "$(realpath "$0")")
  19. else
  20. HERE=$(dirname "$0")
  21. if [ ! -d "$HERE" ] || [ "$HERE" = "." ]; then
  22. HERE=$(dirname "$PWD/$0")
  23. fi
  24. fi
  25. TOPLEVEL=$(dirname "$(dirname "$HERE")")
  26. # Check we actually have a tor/src directory
  27. if [ ! -d "$TOPLEVEL/src" ]; then
  28. printf "Error: Couldn't find src directory in expected location: %s\\n" \
  29. "$TOPLEVEL/src"
  30. exit 1
  31. fi
  32. # Check *.sh scripts, but ignore the ones that we can't fix
  33. find "$TOPLEVEL/contrib" "$TOPLEVEL/doc" "$TOPLEVEL/scripts" "$TOPLEVEL/src" \
  34. -name "*.sh" \
  35. -not -path "$TOPLEVEL/src/ext/*" \
  36. -not -path "$TOPLEVEL/src/rust/registry/*" \
  37. -exec shellcheck {} +
  38. # Check scripts that aren't named *.sh
  39. if [ -d "$TOPLEVEL/scripts/test" ]; then
  40. shellcheck \
  41. "$TOPLEVEL/scripts/test/cov-diff" \
  42. "$TOPLEVEL/scripts/test/coverage"
  43. fi
  44. if [ -e \
  45. "$TOPLEVEL/contrib/dirauth-tools/nagios-check-tor-authority-cert" \
  46. ]; then
  47. shellcheck \
  48. "$TOPLEVEL/contrib/dirauth-tools/nagios-check-tor-authority-cert"
  49. fi
  50. if [ -e "$TOPLEVEL/contrib/client-tools/torify" ]; then
  51. shellcheck "$TOPLEVEL/contrib/client-tools/torify"
  52. fi
  53. if [ -d "$TOPLEVEL/scripts/git" ]; then
  54. shellcheck "$TOPLEVEL/scripts/git/"*.git-hook
  55. fi