checkShellScripts.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. -exec shellcheck {} +
  39. # Check scripts that aren't named *.sh
  40. if [ -d "$TOPLEVEL/scripts/test" ]; then
  41. shellcheck \
  42. "$TOPLEVEL/scripts/test/cov-diff" \
  43. "$TOPLEVEL/scripts/test/coverage"
  44. fi
  45. if [ -e \
  46. "$TOPLEVEL/contrib/dirauth-tools/nagios-check-tor-authority-cert" \
  47. ]; then
  48. shellcheck \
  49. "$TOPLEVEL/contrib/dirauth-tools/nagios-check-tor-authority-cert"
  50. fi
  51. if [ -e "$TOPLEVEL/contrib/client-tools/torify" ]; then
  52. shellcheck "$TOPLEVEL/contrib/client-tools/torify"
  53. fi
  54. if [ -d "$TOPLEVEL/scripts/git" ]; then
  55. shellcheck "$TOPLEVEL/scripts/git/"*.git-hook
  56. fi