Enforce /usr/bin/env shebangs in userscripts

See https://github.com/qutebrowser/qutebrowser/discussions/5927#discussioncomment-145322
This commit is contained in:
Florian Bruhin 2020-12-03 11:08:50 +01:00
parent 7ded49d326
commit e07611fc31
3 changed files with 26 additions and 3 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
set -euo pipefail
#
# Behavior:

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
pngfile=$(mktemp --suffix=.png)
trap 'rm -f "$pngfile"' EXIT

View File

@ -274,12 +274,35 @@ def check_userscripts_descriptions(_args: argparse.Namespace = None) -> bool:
return ok
def check_userscript_shebangs(_args: argparse.Namespace) -> bool:
"""Check that we're using /usr/bin/env in shebangs."""
ok = True
folder = pathlib.Path('misc/userscripts')
for sub in folder.iterdir():
if sub.is_dir() or sub.name == 'README.md':
continue
with sub.open('r', encoding='utf-8') as f:
shebang = f.readline()
assert shebang.startswith('#!'), shebang
binary = shebang.split()[0][2:]
if binary not in ['/bin/sh', '/usr/bin/env']:
bin_name = pathlib.Path(binary).name
print(f"In {sub}, use #!/usr/bin/env {bin_name} instead of #!{binary}")
ok = False
return ok
def main() -> int:
checkers = {
'git': check_git,
'vcs': check_vcs_conflict,
'spelling': check_spelling,
'userscripts': check_userscripts_descriptions,
'userscript-descriptions': check_userscripts_descriptions,
'userscript-shebangs': check_userscript_shebangs,
'changelog-urls': check_changelog_urls,
}