shellcheck: make top-level bash scripts warning-free

And run shellcheck in test.bash.
This commit is contained in:
Jakob Unterwurzacher 2020-04-13 13:09:27 +02:00
parent a2ad14b9ac
commit 9a7ceef09e
8 changed files with 44 additions and 37 deletions

View File

@ -30,10 +30,10 @@ gocryptfs -q -init -reverse -extpass="echo test" -scryptn=10 $PLAIN
MNT=$(mktemp -d /tmp/linux-3.0.reverse.mnt.XXX) MNT=$(mktemp -d /tmp/linux-3.0.reverse.mnt.XXX)
# Cleanup trap # Cleanup trap
trap "rm -f $PLAIN/.gocryptfs.reverse.conf ; fuse-unmount -z $MNT ; rmdir $MNT" EXIT trap 'rm -f "$PLAIN/.gocryptfs.reverse.conf" ; fuse-unmount -z "$MNT" ; rmdir "$MNT"' EXIT
# Mount # Mount
gocryptfs -q -reverse -extpass="echo test" $PLAIN $MNT gocryptfs -q -reverse -extpass="echo test" "$PLAIN" "$MNT"
# Execute command, discard all stdout output, print elapsed time # Execute command, discard all stdout output, print elapsed time
# (to stderr, unfortunately). # (to stderr, unfortunately).
@ -45,6 +45,6 @@ function etime {
} }
echo -n "LS: " echo -n "LS: "
etime ls -lR $MNT etime ls -lR "$MNT"
echo -n "CAT: " echo -n "CAT: "
etime find $MNT -type f -exec cat {} + etime find "$MNT" -type f -exec cat {} +

View File

@ -44,7 +44,7 @@ while [[ $# -gt 0 ]] ; do
exit 2 exit 2
;; ;;
*) *)
if [[ ! -z $OPT_DIR ]] ; then if [[ -n $OPT_DIR ]] ; then
echo "Duplicate DIR argument: $1" echo "Duplicate DIR argument: $1"
usage usage
exit 3 exit 3
@ -62,42 +62,42 @@ fi
# Create directories # Create directories
CRYPT=$(mktemp -d "$OPT_DIR/$MYNAME.XXX") CRYPT=$(mktemp -d "$OPT_DIR/$MYNAME.XXX")
MNT=$CRYPT.mnt MNT=$CRYPT.mnt
mkdir $MNT mkdir "$MNT"
# Mount # Mount
if [[ $OPT_ENCFS -eq 1 ]]; then if [[ $OPT_ENCFS -eq 1 ]]; then
if [[ ! -z $OPT_OPENSSL ]] ; then if [[ -n $OPT_OPENSSL ]] ; then
echo "The option $OPT_OPENSSL only works with gocryptfs" echo "The option $OPT_OPENSSL only works with gocryptfs"
exit 1 exit 1
fi fi
echo -n "Testing EncFS at $CRYPT: " echo -n "Testing EncFS at $CRYPT: "
encfs --version encfs --version
encfs --extpass="echo test" --standard $CRYPT $MNT > /dev/null encfs --extpass="echo test" --standard "$CRYPT" "$MNT" > /dev/null
elif [[ $OPT_LOOPBACK -eq 1 ]]; then elif [[ $OPT_LOOPBACK -eq 1 ]]; then
echo "Testing go-fuse loopback" echo "Testing go-fuse loopback"
$HOME/go/src/github.com/hanwen/go-fuse/example/loopback/loopback $MNT $CRYPT & "$HOME/go/src/github.com/hanwen/go-fuse/example/loopback/loopback" "$MNT" "$CRYPT" &
sleep 0.5 sleep 0.5
else else
echo -n "Testing gocryptfs at $CRYPT: " echo -n "Testing gocryptfs at $CRYPT: "
gocryptfs -version gocryptfs -version
gocryptfs -q -init -extpass="echo test" -scryptn=10 $CRYPT gocryptfs -q -init -extpass="echo test" -scryptn=10 "$CRYPT"
gocryptfs -q -extpass="echo test" $OPT_OPENSSL $CRYPT $MNT gocryptfs -q -extpass="echo test" $OPT_OPENSSL "$CRYPT" "$MNT"
fi fi
# Make sure we have actually mounted something # Make sure we have actually mounted something
if ! mountpoint $MNT ; then if ! mountpoint "$MNT" ; then
exit 1 exit 1
fi fi
# Cleanup trap # Cleanup trap
trap "cd /; fuse-unmount -z $MNT; rm -rf $CRYPT $MNT" EXIT trap 'cd /; fuse-unmount -z "$MNT"; rm -rf "$CRYPT" "$MNT"' EXIT
# Benchmarks # Benchmarks
if [[ $DD_ONLY -eq 1 ]]; then if [[ $DD_ONLY -eq 1 ]]; then
echo -n "WRITE: " echo -n "WRITE: "
dd if=/dev/zero of=$MNT/zero bs=131072 count=20000 2>&1 | tail -n 1 dd if=/dev/zero "of=$MNT/zero" bs=131072 count=20000 2>&1 | tail -n 1
rm $MNT/zero rm "$MNT/zero"
else else
./tests/canonical-benchmarks.bash $MNT ./tests/canonical-benchmarks.bash "$MNT"
fi fi

View File

@ -47,7 +47,7 @@ else
# go-fuse version according to git # go-fuse version according to git
# Note: git in CentOS 7 does not have "git -C" yet, so we use plain "cd". # Note: git in CentOS 7 does not have "git -C" yet, so we use plain "cd".
FAIL=0 FAIL=0
cd $GOPATH1/src/github.com/hanwen/go-fuse cd "$GOPATH1/src/github.com/hanwen/go-fuse"
OUT=$(git describe --tags --dirty 2>&1) || FAIL=1 OUT=$(git describe --tags --dirty 2>&1) || FAIL=1
if [[ $FAIL -eq 0 ]]; then if [[ $FAIL -eq 0 ]]; then
GITVERSIONFUSE=$OUT GITVERSIONFUSE=$OUT
@ -99,5 +99,5 @@ go build "-ldflags=$GO_LDFLAGS" "-gcflags=$TRIM" "-asmflags=$TRIM" "$@"
./gocryptfs -version ./gocryptfs -version
mkdir -p $GOPATH1/bin mkdir -p "$GOPATH1/bin"
cp -af gocryptfs $GOPATH1/bin cp -af gocryptfs "$GOPATH1/bin"

View File

@ -8,10 +8,10 @@ OUTPUT=$(
) )
# No output --> all good # No output --> all good
if [[ -z "$OUTPUT" ]] ; then if [[ -z $OUTPUT ]] ; then
exit 0 exit 0
fi fi
echo "golint.bash:" echo "golint.bash:"
echo $OUTPUT echo "$OUTPUT"
exit 1 exit 1

View File

@ -6,17 +6,17 @@ git_archive_extra() {
local PREFIX=$1 local PREFIX=$1
shift shift
# Add files tracked in git # Add files tracked in git
git archive --prefix "$PREFIX/" -o $PREFIX.tar HEAD git archive --prefix "$PREFIX/" -o "$PREFIX.tar" HEAD
# Add "extra" files # Add "extra" files
tar --owner=root --group=root --transform "s!^!$PREFIX/!" --append -f $PREFIX.tar "$@" tar --owner=root --group=root --transform "s!^!$PREFIX/!" --append -f "$PREFIX.tar" "$@"
# Compress # Compress
gzip -f $PREFIX.tar gzip -f "$PREFIX.tar"
} }
cd "$(dirname "$0")" cd "$(dirname "$0")"
GITVERSION=$(git describe --tags --dirty) GITVERSION=$(git describe --tags --dirty)
echo $GITVERSION > VERSION echo "$GITVERSION" > VERSION
# Render the manpages and include them in the tarball. This # Render the manpages and include them in the tarball. This
# avoids a build-dependency to pandoc. # avoids a build-dependency to pandoc.
@ -24,12 +24,12 @@ echo $GITVERSION > VERSION
# gocryptfs source tarball # gocryptfs source tarball
PREFIX_SRC_ONLY=gocryptfs_${GITVERSION}_src PREFIX_SRC_ONLY=gocryptfs_${GITVERSION}_src
git_archive_extra $PREFIX_SRC_ONLY VERSION Documentation/*.1 git_archive_extra "$PREFIX_SRC_ONLY" VERSION Documentation/*.1
# gocryptfs source + dependencies tarball # gocryptfs source + dependencies tarball
dep ensure dep ensure
PREFIX_SRC_DEPS=gocryptfs_${GITVERSION}_src-deps PREFIX_SRC_DEPS=gocryptfs_${GITVERSION}_src-deps
git_archive_extra $PREFIX_SRC_DEPS VERSION Documentation/*.1 vendor git_archive_extra "$PREFIX_SRC_DEPS" VERSION Documentation/*.1 vendor
rm VERSION rm VERSION

View File

@ -19,7 +19,7 @@ OS=$(go env GOOS)
TARGZ=gocryptfs_${GITVERSION}_${OS}-static_${ARCH}.tar.gz TARGZ=gocryptfs_${GITVERSION}_${OS}-static_${ARCH}.tar.gz
tar --owner=root --group=root -czf $TARGZ gocryptfs gocryptfs.1 tar --owner=root --group=root -czf "$TARGZ" gocryptfs gocryptfs.1
echo "Tar created." echo "Tar created."
echo "Hint for signing: gpg -u 23A02740 --armor --detach-sig $TARGZ" echo "Hint for signing: gpg -u 23A02740 --armor --detach-sig $TARGZ"

View File

@ -27,7 +27,7 @@ cp -a ./Documentation/gocryptfs.1 .
TARGZ=gocryptfs_${GITVERSION}_${ID}${VERSION_ID}_${ARCH}.tar.gz TARGZ=gocryptfs_${GITVERSION}_${ID}${VERSION_ID}_${ARCH}.tar.gz
tar --owner=root --group=root -czf $TARGZ gocryptfs gocryptfs.1 tar --owner=root --group=root -czf "$TARGZ" gocryptfs gocryptfs.1
echo "Tar created." echo "Tar created."
echo "Hint for signing: gpg -u 23A02740 --armor --detach-sig $TARGZ" echo "Hint for signing: gpg -u 23A02740 --armor --detach-sig $TARGZ"

View File

@ -12,14 +12,14 @@ set -eu
cd "$(dirname "$0")" cd "$(dirname "$0")"
MYNAME=$(basename "$0") MYNAME=$(basename "$0")
TESTDIR=$TMPDIR/gocryptfs-test-parent-$UID TESTDIR=$TMPDIR/gocryptfs-test-parent-$UID
mkdir -p $TESTDIR mkdir -p "$TESTDIR"
LOCKFILE=$TESTDIR/$MYNAME.lock LOCKFILE=$TESTDIR/$MYNAME.lock
function unmount_leftovers { function unmount_leftovers {
RET=0 RET=0
for i in $(mount | grep $TESTDIR | cut -f3 -d" "); do for i in $(mount | grep "$TESTDIR" | cut -f3 -d" "); do
echo "Warning: unmounting leftover filesystem: $i" echo "Warning: unmounting leftover filesystem: $i"
tests/fuse-unmount.bash $i tests/fuse-unmount.bash "$i"
RET=1 RET=1
done done
return $RET return $RET
@ -40,7 +40,7 @@ unmount_leftovers || true
./build-without-openssl.bash ./build-without-openssl.bash
# Don't build with openssl if we were passed "-tags without_openssl" # Don't build with openssl if we were passed "-tags without_openssl"
if [[ "$@" != *without_openssl* ]] ; then if [[ "$*" != *without_openssl* ]] ; then
./build.bash ./build.bash
fi fi
@ -52,6 +52,13 @@ else
go vet "$@" . go vet "$@" .
fi fi
if command -v shellcheck > /dev/null ; then
# SC2002 = useless cat. Does no harm, disable the check.
shellcheck -x -e SC2002 ./*.bash
else
echo "shellcheck not installed - skipping"
fi
# We don't want all the subprocesses # We don't want all the subprocesses
# holding the lock file open # holding the lock file open
# vvvvv # vvvvv
@ -65,15 +72,15 @@ unmount_leftovers || { echo "Error: the tests left mounted filesystems behind" ;
# The tests cannot to this themselves as they are run in parallel. # The tests cannot to this themselves as they are run in parallel.
# Don't descend into possibly still mounted example filesystems. # Don't descend into possibly still mounted example filesystems.
if [[ $OSTYPE == *linux* ]] ; then if [[ $OSTYPE == *linux* ]] ; then
rm -Rf --one-file-system $TESTDIR rm -Rf --one-file-system "$TESTDIR"
else else
# MacOS "rm" does not understand "--one-file-system" # MacOS "rm" does not understand "--one-file-system"
rm -Rf $TESTDIR rm -Rf "$TESTDIR"
fi fi
if grep -R "panic(" *.go internal ; then if grep -R "panic(" ./*.go internal ; then
echo "Please use log.Panic instead of naked panic!" echo "Please use log.Panic instead of naked panic!"
exit 1 exit 1
fi fi
) 200> $LOCKFILE ) 200> "$LOCKFILE"