From 688f665a5e526fda0fb797bf617412fe9cbe64fd Mon Sep 17 00:00:00 2001 From: vim88 Date: Wed, 28 Nov 2018 22:43:18 +0200 Subject: Scripts and tools & Docs: Used #!/usr/bin/env bash instead of obsolete #!/bin/bash, added linting for .sh files shebang and updated the Developer Notes. --- contrib/qos/tc.sh | 2 ++ doc/developer-notes.md | 27 +++++++++++++++++++++++++++ src/qt/res/movies/makespinner.sh | 2 ++ test/lint/lint-python-dead-code.sh | 2 +- test/lint/lint-python-shebang.sh | 13 ------------- test/lint/lint-shebang.sh | 20 ++++++++++++++++++++ 6 files changed, 52 insertions(+), 14 deletions(-) delete mode 100755 test/lint/lint-python-shebang.sh create mode 100755 test/lint/lint-shebang.sh diff --git a/contrib/qos/tc.sh b/contrib/qos/tc.sh index 738ea70dbe..5f9b87d9b2 100644 --- a/contrib/qos/tc.sh +++ b/contrib/qos/tc.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash +# # Copyright (c) 2017 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/doc/developer-notes.md b/doc/developer-notes.md index bb477d4be0..42885ac1d4 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -28,6 +28,8 @@ Developer Notes - [Strings and formatting](#strings-and-formatting) - [Variable names](#variable-names) - [Threads and synchronization](#threads-and-synchronization) + - [Scripts](#scripts) + - [Shebang](#shebang) - [Source code organization](#source-code-organization) - [GUI](#gui) - [Subtrees](#subtrees) @@ -602,6 +604,31 @@ TRY_LOCK(cs_vNodes, lockNodes); } ``` +Scripts +-------------------------- + +### Shebang + +- Use `#!/usr/bin/env bash` instead of obsolete `#!/bin/bash`. + + - [*Rationale*](https://github.com/dylanaraps/pure-bash-bible#shebang): + + `#!/bin/bash` assumes it is always installed to /bin/ which can cause issues; + + `#!/usr/bin/env bash` searches the user's PATH to find the bash binary. + + OK: + +```bash +#!/usr/bin/env bash +``` + + Wrong: + +```bash +#!/bin/bash +``` + Source code organization -------------------------- diff --git a/src/qt/res/movies/makespinner.sh b/src/qt/res/movies/makespinner.sh index 76e36e4f31..f47c66e02c 100755 --- a/src/qt/res/movies/makespinner.sh +++ b/src/qt/res/movies/makespinner.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash +# # Copyright (c) 2014-2015 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/test/lint/lint-python-dead-code.sh b/test/lint/lint-python-dead-code.sh index 3341f794f9..4561b0db30 100755 --- a/test/lint/lint-python-dead-code.sh +++ b/test/lint/lint-python-dead-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright (c) 2018 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying diff --git a/test/lint/lint-python-shebang.sh b/test/lint/lint-python-shebang.sh deleted file mode 100755 index 4ff87f0bf7..0000000000 --- a/test/lint/lint-python-shebang.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -# Shebang must use python3 (not python or python2) - -export LC_ALL=C -EXIT_CODE=0 -for PYTHON_FILE in $(git ls-files -- "*.py"); do - if [[ $(head -c 2 "${PYTHON_FILE}") == "#!" && - $(head -n 1 "${PYTHON_FILE}") != "#!/usr/bin/env python3" ]]; then - echo "Missing shebang \"#!/usr/bin/env python3\" in ${PYTHON_FILE} (do not use python or python2)" - EXIT_CODE=1 - fi -done -exit ${EXIT_CODE} diff --git a/test/lint/lint-shebang.sh b/test/lint/lint-shebang.sh new file mode 100755 index 0000000000..fda22592d3 --- /dev/null +++ b/test/lint/lint-shebang.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Assert expected shebang lines + +export LC_ALL=C +EXIT_CODE=0 +for PYTHON_FILE in $(git ls-files -- "*.py"); do + if [[ $(head -c 2 "${PYTHON_FILE}") == "#!" && + $(head -n 1 "${PYTHON_FILE}") != "#!/usr/bin/env python3" ]]; then + echo "Missing shebang \"#!/usr/bin/env python3\" in ${PYTHON_FILE} (do not use python or python2)" + EXIT_CODE=1 + fi +done +for SHELL_FILE in $(git ls-files -- "*.sh"); do + if [[ $(head -n 1 "${SHELL_FILE}") != "#!/usr/bin/env bash" && + $(head -n 1 "${SHELL_FILE}") != "#!/bin/sh" ]]; then + echo "Missing expected shebang \"#!/usr/bin/env bash\" or \"#!/bin/sh\" in ${SHELL_FILE}" + EXIT_CODE=1 + fi +done +exit ${EXIT_CODE} -- cgit v1.2.3