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