checkShellScripts.sh 1.8 KB

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