Skip to content

Commit

Permalink
Add shellcheck
Browse files Browse the repository at this point in the history
Copy the `shellcheck.sh` script from the SecureDrop server repository
and add it to the central `make lint` target. I added SC2164 as a global
exclusion since we don't really care about `cd` potentially failing.

The following fixes are being made:
* client/.githooks/pre-commit: Use $() instead of backticks.
* debian/setup-venv.sh: Ignore quoting words, all the variables are a
  single word only.
* proxy/entrypoint.sh: Adjust shebang since we use bashisms.
* scripts/build-debs.sh: Set variable and then export it
* scripts/fixup-changelog.sh: Quote our variables, don't use `! -z`.

Fixes #814.
  • Loading branch information
legoktm authored and rocodes committed Feb 22, 2024
1 parent db77515 commit c48afac
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
container: debian:${{ matrix.debian_version }}
steps:
- run: |
apt-get update && apt-get install --yes git make
apt-get update && apt-get install --yes git make file
- uses: actions/checkout@v4
- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion client/.githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
TOP=`git rev-parse --show-toplevel`
TOP=$(git rev-parse --show-toplevel)

make -C "$TOP" check-strings
1 change: 1 addition & 0 deletions debian/setup-venv.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# shellcheck disable=SC2086
set -euxo pipefail

NAME=$1
Expand Down
15 changes: 14 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proxy/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

cd /home/user/projects/securedrop-proxy
virtualenv .venv
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bandit = "*"
black = "*"
isort = "*"
safety = "*"
shellcheck-py = "*"

[tool.bandit]
exclude_dirs = ["client/tests", "export/tests", "log/tests", "proxy/tests"]
Expand Down
3 changes: 2 additions & 1 deletion scripts/build-debs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ if test -t 0; then
fi

# Look for the builder repo with our local wheels
export BUILDER=$(realpath "${BUILDER:-../securedrop-builder}")
BUILDER=$(realpath "${BUILDER:-../securedrop-builder}")
if [[ ! -d $BUILDER ]]; then
echo "Cannot find securedrop-builder repository, please check it out \
to ${BUILDER} or set the BUILDER variable"
exit 1
fi

export BUILDER
export DEBIAN_VERSION="${DEBIAN_VERSION:-bullseye}"
export OCI_RUN_ARGUMENTS
export OCI_BIN
Expand Down
4 changes: 2 additions & 2 deletions scripts/fixup-changelog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ source /etc/os-release
if [[ "$VERSION_CODENAME" == "" ]]; then
# PRETTY_NAME="Debian GNU/Linux bookworm/sid"
# Use awk to split on spaces and /
VERSION_CODENAME=$(echo $PRETTY_NAME | awk '{split($0, a, "[ /]"); print a[4]}')
VERSION_CODENAME=$(echo "$PRETTY_NAME" | awk '{split($0, a, "[ /]"); print a[4]}')
fi

VERSION=$(dpkg-parsechangelog -S Version)

NIGHTLY="${NIGHTLY:-}"
if [[ ! -z $NIGHTLY ]]; then
if [[ -n $NIGHTLY ]]; then
NEW_VERSION="${VERSION}.dev$(date +%Y%m%d%H%M%S)"
else
NEW_VERSION=$VERSION
Expand Down
39 changes: 39 additions & 0 deletions scripts/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e

EXCLUDE_RULES="SC1090,SC1091,SC2001,SC2064,SC2181,SC1117,SC2164"

# Omitting:
# - the `.git/` directory since its hooks won't pass # validation, and
# we don't maintain those scripts.
# - the `.venv/` dir because we don't control files in there.
# - ossec packages because there are a LOT of violations, and we have
# a separate issue dedicated to cleaning those up.
# - Python, JavaScript, YAML, HTML, SASS, PNG files because they're not shell scripts.
# - Cache directories of mypy, SASS, or Tox.
# - test results
FILES=$(find "." \
\( \
-path '*.mo' \
-o -path '*.po' \
-o -path '*.py' \
-o -path '*.yml' \
-o -path '*/.mypy_cache/*' \
-o -path '*/.tox/*' \
-o -path '*/.venv' \
-o -path './.git' \
-o -path './build/*' \
-o -path './target' \
\) -prune \
-o -type f \
-exec file --mime {} + \
| awk '$2 ~ /x-shellscript/ { print $1 }' \
| sed 's/://')
# Turn the multiline find output into a single space-separated line
FILES=$(echo "$FILES" | tr '\n' ' ')

shellcheck --version
# $FILES intentionally unquoted so each file is passed as its own argument
# shellcheck disable=SC2086
shellcheck -x --exclude="$EXCLUDE_RULES" $FILES

0 comments on commit c48afac

Please sign in to comment.