Make it easier to reason about state transitions
[tails.git] / bin / shellcheck-tree
bloba4fbf5c3d22e95ff82a4d25129f2c2bdbdfbb592
1 #!/usr/bin/python3
3 import glob
4 import re
5 import subprocess
6 import sys
7 from pathlib import Path
10 def is_excluded(f: str) -> bool:
11     return re.match(r"^([.]git|config/chroot_local-includes/usr/share/doc/tails/website|submodules|tmp|wiki/src)/",
12                     f) is not None or Path(f).is_dir()
15 def mimetype(f: str) -> str:
16     return subprocess.run(['file', '--brief', '--mime-type', f],
17                           stdout=subprocess.PIPE,
18                           universal_newlines=True,
19                           check=True).stdout.rstrip()
22 def is_shell_script(f: str) -> bool:
23     return f.endswith('.sh') or mimetype(f) == "text/x-shellscript"
26 shell_scripts = [
27     f for f in glob.glob("**/*", recursive=True)
28     if not is_excluded(f) and is_shell_script(f)
31 sys.exit(
32     subprocess.run(['shellcheck'] + sys.argv[1:] + shell_scripts).returncode)