tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

checkShellScripts.sh (1887B)


      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 
     10 set -e
     11 
     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
     17 fi
     18 
     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")
     26    fi
     27 fi
     28 TOPLEVEL=$(dirname "$(dirname "$HERE")")
     29 
     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
     35 fi
     36 
     37 # Remove obsolete scripts generated from older versions of Tor
     38 rm -f "$TOPLEVEL/contrib/dist/suse/tor.sh" "$TOPLEVEL/contrib/dist/tor.sh"
     39 
     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 {} +
     45 
     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"
     51 fi
     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"
     57 fi
     58 if [ -e "$TOPLEVEL/contrib/client-tools/torify" ]; then
     59    shellcheck "$TOPLEVEL/contrib/client-tools/torify"
     60 fi
     61 if [ -d "$TOPLEVEL/scripts/git" ]; then
     62    shellcheck "$TOPLEVEL/scripts/git/"*.git-hook
     63 fi