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)
# 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
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
# (to stderr, unfortunately).
@ -45,6 +45,6 @@ function etime {
}
echo -n "LS: "
etime ls -lR $MNT
etime ls -lR "$MNT"
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
;;
*)
if [[ ! -z $OPT_DIR ]] ; then
if [[ -n $OPT_DIR ]] ; then
echo "Duplicate DIR argument: $1"
usage
exit 3
@ -62,42 +62,42 @@ fi
# Create directories
CRYPT=$(mktemp -d "$OPT_DIR/$MYNAME.XXX")
MNT=$CRYPT.mnt
mkdir $MNT
mkdir "$MNT"
# Mount
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"
exit 1
fi
echo -n "Testing EncFS at $CRYPT: "
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
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
else
echo -n "Testing gocryptfs at $CRYPT: "
gocryptfs -version
gocryptfs -q -init -extpass="echo test" -scryptn=10 $CRYPT
gocryptfs -q -extpass="echo test" $OPT_OPENSSL $CRYPT $MNT
gocryptfs -q -init -extpass="echo test" -scryptn=10 "$CRYPT"
gocryptfs -q -extpass="echo test" $OPT_OPENSSL "$CRYPT" "$MNT"
fi
# Make sure we have actually mounted something
if ! mountpoint $MNT ; then
if ! mountpoint "$MNT" ; then
exit 1
fi
# 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
if [[ $DD_ONLY -eq 1 ]]; then
echo -n "WRITE: "
dd if=/dev/zero of=$MNT/zero bs=131072 count=20000 2>&1 | tail -n 1
rm $MNT/zero
dd if=/dev/zero "of=$MNT/zero" bs=131072 count=20000 2>&1 | tail -n 1
rm "$MNT/zero"
else
./tests/canonical-benchmarks.bash $MNT
./tests/canonical-benchmarks.bash "$MNT"
fi

View File

@ -47,7 +47,7 @@ else
# go-fuse version according to git
# Note: git in CentOS 7 does not have "git -C" yet, so we use plain "cd".
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
if [[ $FAIL -eq 0 ]]; then
GITVERSIONFUSE=$OUT
@ -99,5 +99,5 @@ go build "-ldflags=$GO_LDFLAGS" "-gcflags=$TRIM" "-asmflags=$TRIM" "$@"
./gocryptfs -version
mkdir -p $GOPATH1/bin
cp -af gocryptfs $GOPATH1/bin
mkdir -p "$GOPATH1/bin"
cp -af gocryptfs "$GOPATH1/bin"

View File

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

View File

@ -6,17 +6,17 @@ git_archive_extra() {
local PREFIX=$1
shift
# Add files tracked in git
git archive --prefix "$PREFIX/" -o $PREFIX.tar HEAD
git archive --prefix "$PREFIX/" -o "$PREFIX.tar" HEAD
# 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
gzip -f $PREFIX.tar
gzip -f "$PREFIX.tar"
}
cd "$(dirname "$0")"
GITVERSION=$(git describe --tags --dirty)
echo $GITVERSION > VERSION
echo "$GITVERSION" > VERSION
# Render the manpages and include them in the tarball. This
# avoids a build-dependency to pandoc.
@ -24,12 +24,12 @@ echo $GITVERSION > VERSION
# gocryptfs source tarball
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
dep ensure
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

View File

@ -19,7 +19,7 @@ OS=$(go env GOOS)
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 "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
tar --owner=root --group=root -czf $TARGZ gocryptfs gocryptfs.1
tar --owner=root --group=root -czf "$TARGZ" gocryptfs gocryptfs.1
echo "Tar created."
echo "Hint for signing: gpg -u 23A02740 --armor --detach-sig $TARGZ"

View File

@ -12,14 +12,14 @@ set -eu
cd "$(dirname "$0")"
MYNAME=$(basename "$0")
TESTDIR=$TMPDIR/gocryptfs-test-parent-$UID
mkdir -p $TESTDIR
mkdir -p "$TESTDIR"
LOCKFILE=$TESTDIR/$MYNAME.lock
function unmount_leftovers {
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"
tests/fuse-unmount.bash $i
tests/fuse-unmount.bash "$i"
RET=1
done
return $RET
@ -40,7 +40,7 @@ unmount_leftovers || true
./build-without-openssl.bash
# Don't build with openssl if we were passed "-tags without_openssl"
if [[ "$@" != *without_openssl* ]] ; then
if [[ "$*" != *without_openssl* ]] ; then
./build.bash
fi
@ -52,6 +52,13 @@ else
go vet "$@" .
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
# holding the lock file open
# 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.
# Don't descend into possibly still mounted example filesystems.
if [[ $OSTYPE == *linux* ]] ; then
rm -Rf --one-file-system $TESTDIR
rm -Rf --one-file-system "$TESTDIR"
else
# MacOS "rm" does not understand "--one-file-system"
rm -Rf $TESTDIR
rm -Rf "$TESTDIR"
fi
if grep -R "panic(" *.go internal ; then
if grep -R "panic(" ./*.go internal ; then
echo "Please use log.Panic instead of naked panic!"
exit 1
fi
) 200> $LOCKFILE
) 200> "$LOCKFILE"