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