/ maint / rust-maint-common / forbid-absolute-shebangs
forbid-absolute-shebangs
 1  #!/usr/bin/env bash
 2  #
 3  # Usage:
 4  #   maint/forbid-absolute-shebangs
 5  #
 6  # Requires that scripts all start with `#! /usr/bin/env`,
 7  # not a path to a specific interpreter.
 8  
 9  set -euo pipefail
10  
11  # this include stanza is automatically maintained by update-shell-includes
12  common_dir=$(realpath "$0")
13  common_dir=$(dirname "$common_dir")
14  # shellcheck source=maint/common/bash-utils.sh
15  . "$common_dir"/bash-utils.sh
16  
17  reject_all_arguments
18  
19  set +e
20  git grep -rnI '^#\!/' :/ ':(exclude)debian/*' | grep -v '#\!/usr/bin/env'
21  st="${PIPESTATUS[*]}"
22  set -e
23  
24  case "$st" in
25      "0 0")
26  	echo "Absolute shebangs found, replace them with \"#!/usr/bin/env\""
27  	exit 1
28  	;;
29      "0 1")
30  	echo "Everything seems ok"
31  	exit 0
32  	;;
33      *)
34  	echo "ERROR - status $st"
35  	exit 16
36  	;;
37  esac