Skip to content

Commit

Permalink
many: cover *all* standalone shell scripts with shellcheck
Browse files Browse the repository at this point in the history
This might be getting out of hand. I blame ogra.
  • Loading branch information
chipaca committed May 22, 2017
1 parent 51b0902 commit 5f0aeae
Show file tree
Hide file tree
Showing 52 changed files with 89 additions and 86 deletions.
11 changes: 1 addition & 10 deletions cmd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ subdirs = snap-confine snap-discard-ns system-shutdown libsnap-confine-private

# Run check-syntax when checking
# TODO: conver those to autotools-style tests later
check: check-syntax-c check-syntax-sh check-unit-tests
check: check-syntax-c check-unit-tests

# Force particular coding style on all source and header files.
.PHONY: check-syntax-c
Expand All @@ -25,15 +25,6 @@ check-syntax-c:
diff -Naur "$$f" "$$out" || exit 1; \
done;

# Check for common shell errors
.PHONY: check-syntax-sh
check-syntax-sh: $(filter-out %.log %.trs,$(wildcard $(srcdir)/snap-confine/tests/test_*)) snap-confine/tests/common.sh
if HAVE_SHELLCHECK
$(HAVE_SHELLCHECK) -x --format=gcc $^
else
echo "shellcheck is not installed, skipping (non-critical) syntax test"
endif

.PHONY: check-unit-tests
if WITH_UNIT_TESTS
check-unit-tests: snap-confine/unit-tests system-shutdown/unit-tests libsnap-confine-private/unit-tests
Expand Down
2 changes: 2 additions & 0 deletions cmd/autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ autoreconf -i -f

# Configure the build
extra_opts=
# shellcheck disable=SC1091
. /etc/os-release
case "$ID" in
arch)
Expand Down Expand Up @@ -47,4 +48,5 @@ case "$ID" in
esac

echo "Configuring with: $extra_opts"
# shellcheck disable=SC2086
./configure --enable-maintainer-mode --prefix=/usr $extra_opts
4 changes: 0 additions & 4 deletions cmd/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ AC_PATH_PROGS([HAVE_RST2MAN],[rst2man rst2man.py])
AS_IF([test "x$HAVE_RST2MAN" = "x"], [AC_MSG_WARN(["cannot find the rst2man tool, install python-docutils or similar"])])
AM_CONDITIONAL([HAVE_RST2MAN], [test "x${HAVE_RST2MAN}" != "x"])

AC_PATH_PROG([HAVE_SHELLCHECK],[shellcheck])
AM_CONDITIONAL([HAVE_SHELLCHECK], [test "x${HAVE_SHELLCHECK}" != "x"])
AS_IF([test "x$HAVE_SHELLCHECK" = "x"], [AC_MSG_WARN(["cannot find the shellcheck tool, will not run syntax checks for shell code"])])

AC_PATH_PROG([HAVE_VALGRIND],[valgrind])
AM_CONDITIONAL([HAVE_VALGRIND], [test "x${HAVE_VALGRIND}" != "x"])
AS_IF([test "x$HAVE_VALGRIND" = "x"], [AC_MSG_WARN(["cannot find the valgrind tool, will not run unit tests through valgrind"])])
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/snappy-app-dev
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MAJMIN="$4"
[ -n "$DEVPATH" ] || { echo "no devpath given" >&2; exit 1; }
[ -n "$MAJMIN" ] || { echo "no major/minor given" >&2; exit 0; }

APPNAME=`echo $APPNAME | tr '_' '.'`
APPNAME="$( echo "$APPNAME" | tr '_' '.' )"
app_dev_cgroup="/sys/fs/cgroup/devices/$APPNAME"

# check if it's a block or char dev
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/spread-tests/release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# This script creates a new release tarball
set -xue

Expand Down
18 changes: 12 additions & 6 deletions cmd/snap-confine/spread-tests/spread-prepare.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# This script is started by spread to prepare the execution environment
set -xue

Expand All @@ -9,8 +9,11 @@ test -f configure.ac || ( echo 'this script must be executed from the top-level
top_dir=$(pwd)

# Record the current distribution release data to know what to do
release_ID="$( . /etc/os-release && echo "${ID:-linux}" )"
release_VERSION_ID="$( . /etc/os-release && echo "${VERSION_ID:-}" )"
# shellcheck disable=SC1091
{
release_ID="$( . /etc/os-release && echo "${ID:-linux}" )"
release_VERSION_ID="$( . /etc/os-release && echo "${VERSION_ID:-}" )"
}


build_debian_or_ubuntu_package() {
Expand All @@ -30,8 +33,11 @@ build_debian_or_ubuntu_package() {
fi

# source the distro specific vars
. "$top_dir/spread-tests/distros/$release_ID.$release_VERSION_ID"
. "$top_dir/spread-tests/distros/$release_ID.common"
# shellcheck disable=SC1090
{
. "$top_dir/spread-tests/distros/$release_ID.$release_VERSION_ID"
. "$top_dir/spread-tests/distros/$release_ID.common"
}

# sanity check, ensure that essential variables were defined
test -n "$distro_packaging_git_branch"
Expand All @@ -51,7 +57,7 @@ build_debian_or_ubuntu_package() {

# Install all the build dependencies declared by the package.
apt-get install --quiet -y gdebi-core
apt-get install --quiet -y $(gdebi --quiet --apt-line ./distro-packaging/debian/control)
gdebi --quiet --apt-line ./distro-packaging/debian/control | xargs -r apt-get install --quiet -y

# Generate a new upstream tarball from the current state of the tree
( cd "$top_dir" && spread-tests/release.sh )
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args_clone
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args_mknod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args_null
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args_prctl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args_prio
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_args_socket
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_bad_seccomp_filter_length
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

printf "Test seccomp filter (bad - too long)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

printf "Test seccomp filter (bad - no trailing newline)"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_complain
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

cat >"$TMP/snap.name.app" <<EOF
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_complain_missed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

cat >"$TMP/snap.name.app" <<EOF
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_noprofile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

printf "Test that a non-existing profile causes the launcher to not start"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_restrictions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

cat >"$TMP/snap.name.app" <<EOF
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_restrictions_working
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP/snap.name.app"
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_restrictions_working_args
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_restrictions_working_args_prio
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

get_common_syscalls >"$TMP"/tmpl
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_unrestricted
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

cat >"$TMP/snap.name.app" <<EOF
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_unrestricted_missed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

cat >"$TMP/snap.name.app" <<EOF
Expand Down
2 changes: 1 addition & 1 deletion cmd/snap-confine/tests/test_whitelist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# shellcheck source=snap-confine/tests/common.sh
# shellcheck source=cmd/snap-confine/tests/common.sh
. "${srcdir:-.}/snap-confine/tests/common.sh"

printf "Test appname whitelist"
Expand Down
2 changes: 2 additions & 0 deletions data/completion/etelpmoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ if [[ ! -f "$_compscript" ]]; then
fi

# Source the bash-completion library functions and common completion setup
# shellcheck disable=SC1091
. /usr/share/bash-completion/bash_completion
# Now source the snap's 'completer' script itself
# shellcheck disable=SC1090
. "$_compscript"

# _compopts is an associative array, which keys are options. The options are
Expand Down
3 changes: 2 additions & 1 deletion generate-packaging-dir
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
set -eu

# shellcheck disable=SC1091
. /etc/os-release

# FIXME:
Expand All @@ -12,5 +13,5 @@ set -eu

# update symlink
rm -f debian
ln -s packaging/${ID}-${VERSION_ID} debian
ln -s "packaging/${ID}-${VERSION_ID}" debian

Loading

0 comments on commit 5f0aeae

Please sign in to comment.