checkShellScripts.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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" ]; 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. fi
  31. # Check *.sh scripts, but ignore the ones that we can't fix
  32. find "$TOPLEVEL" \
  33. -name "*.sh" \
  34. -path "$TOPLEVEL/contrib/*" \
  35. -path "$TOPLEVEL/doc/*" \
  36. -path "$TOPLEVEL/scripts/*" \
  37. -path "$TOPLEVEL/src/*" \
  38. -not -path "$TOPLEVEL/src/ext/*" \
  39. -not -path "$TOPLEVEL/src/rust/registry/*" \
  40. -exec shellcheck {} +
  41. # Check scripts that aren't named *.sh
  42. if [ -d "$TOPLEVEL/scripts/test" ]; then
  43. shellcheck \
  44. "$TOPLEVEL/scripts/test/cov-diff" \
  45. "$TOPLEVEL/scripts/test/coverage"
  46. fi
  47. if [ -e \
  48. "$TOPLEVEL/contrib/dirauth-tools/nagios-check-tor-authority-cert" \
  49. ]; then
  50. shellcheck \
  51. "$TOPLEVEL/contrib/dirauth-tools/nagios-check-tor-authority-cert"
  52. fi
  53. if [ -e "$TOPLEVEL/contrib/client-tools/torify" ]; then
  54. shellcheck "$TOPLEVEL/contrib/client-tools/torify"
  55. fi
  56. if [ -d "$TOPLEVEL/scripts/git" ]; then
  57. shellcheck "$TOPLEVEL/scripts/git/"*.git-hook
  58. fi