2022-02-13 07:49:52 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
def is_excluded(f):
|
2022-02-13 08:25:40 +00:00
|
|
|
return (re.match(
|
2022-02-13 21:22:35 +01:00
|
|
|
# skip test scripts and the rc.apparmor.slackware initscript
|
2022-08-07 17:06:08 -04:00
|
|
|
r"^([.]git/|parser/tst/|tests/|utils/test/|parser/rc[.]apparmor[.]slackware)"
|
|
|
|
+ "|"
|
2022-02-13 21:22:35 +01:00
|
|
|
# skip several files generated during libapparmor build
|
2022-08-07 17:06:08 -04:00
|
|
|
+ r"^libraries/libapparmor/(compile|config[.]guess|config[.]status|config[.]sub|configure|depcomp|install-sh|libtool|ltmain[.]sh|missing|test-driver|ylwrap|testsuite/test_multi[.]multi)",
|
2022-02-13 08:25:40 +00:00
|
|
|
f,
|
|
|
|
) or Path(f).is_dir())
|
2022-02-13 07:49:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def mimetype(f):
|
|
|
|
return subprocess.run(['file', '--brief', '--mime-type', f],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
universal_newlines=True,
|
|
|
|
check=True).stdout.rstrip()
|
|
|
|
|
|
|
|
|
|
|
|
def is_shell_script(f):
|
|
|
|
return mimetype(f) == "text/x-shellscript"
|
|
|
|
|
|
|
|
|
|
|
|
shell_scripts = [
|
|
|
|
f for f in glob.glob("**/*", recursive=True)
|
|
|
|
if not is_excluded(f) and is_shell_script(f)
|
|
|
|
]
|
|
|
|
|
|
|
|
sys.exit(
|
|
|
|
subprocess.run(['shellcheck'] + sys.argv[1:] + shell_scripts).returncode)
|