Index: configure
===================================================================
--- configure	(revision 08964daffb672a224f9f33576e5fcde29136d65f)
+++ configure	(revision 37ef2cbb288e5b8f190166951250ab33703febad)
@@ -8,4 +8,5 @@
 ##############################
 
+# shellcheck disable=SC2016,SC2164,SC2181
 prefix='/usr/local/'
 bindir='$prefix/bin/'
@@ -27,5 +28,5 @@
 sysroot=''
 
-configure_args="$@"
+configure_args="$*"
 
 # Set these to default-on to let it be overriden by either the user or purple
@@ -78,5 +79,5 @@
 
 get_version() {
-	REAL_BITLBEE_VERSION=$(grep '^#define BITLBEE_VERSION ' $srcdir/bitlbee.h | sed 's/.*\"\(.*\)\".*/\1/')
+	REAL_BITLBEE_VERSION=$(grep '^#define BITLBEE_VERSION ' "$srcdir/bitlbee.h" | sed 's/.*\"\(.*\)\".*/\1/')
 
 	if [ -n "$BITLBEE_VERSION" ]; then
@@ -88,17 +89,16 @@
 	BITLBEE_VERSION=$REAL_BITLBEE_VERSION
 
-	if [ -d $srcdir/.git ] && type git > /dev/null 2> /dev/null; then
-		timestamp=$(cd $srcdir; git show -s --format=%ci HEAD | sed 's/ .*$//; s/-//g')
-		branch=$(cd $srcdir; git rev-parse --abbrev-ref HEAD)
+	if [ -d "$srcdir/.git" ] && type git > /dev/null 2> /dev/null; then
+		timestamp=$(cd "$srcdir"; git show -s --format=%ci HEAD | sed 's/ .*$//; s/-//g')
+		branch=$(cd "$srcdir"; git rev-parse --abbrev-ref HEAD)
 
 		search='\(.*\)-\([0-9]*\)-\(g[0-9a-f]*\)'
 		replace="\1+$timestamp+$branch+\2-\3-git"
 
-		describe=$(cd $srcdir; git describe --long --tags 2>/dev/null)
-		if [ $? -ne 0 ]; then
-			describe=${REAL_BITLBEE_VERSION}-0-g$(cd $srcdir; git rev-parse --short HEAD)
+		if ! (cd "$srcdir"; git describe --long --tags 2>/dev/null); then
+			describe=${REAL_BITLBEE_VERSION}-0-g$(cd "$srcdir"; git rev-parse --short HEAD)
 		fi
 
-		BITLBEE_VERSION=$(echo $describe | sed "s#$search#$replace#")
+		BITLBEE_VERSION=$(echo "$describe" | sed "s#$search#$replace#")
 
 		unset timestamp branch search replace describe
@@ -107,7 +107,7 @@
 
 if [ "$1" = "--dump-version" ]; then
-	srcdir=$(cd $(dirname $0);pwd)
+	srcdir=$(cd "$(dirname "$0")"; pwd)
 	get_version
-	echo $BITLBEE_VERSION
+	echo "$BITLBEE_VERSION"
 	exit
 fi
@@ -167,8 +167,8 @@
 --sysroot=...	Cross compilation sysroot 		$sysroot
 EOF
-		exit;
+		exit
 	fi
 	eval "$e"
-	shift;
+	shift
 done
 
@@ -217,17 +217,19 @@
 EOF
 
-srcdir=$(cd $(dirname $0);pwd)
+srcdir=$(cd "$(dirname "$0")"; pwd)
 currdir=$(pwd)
-if [ "$srcdir" != "$currdir" ]; then 
+if [ "$srcdir" != "$currdir" ]; then
 	echo
 	echo "configure script run from a different directory. Will create some symlinks..."
-	if [ ! -e Makefile -o -L Makefile ]; then
+	if [ ! -e Makefile ] || [ -L Makefile ]; then
 		COPYDIRS="doc lib protocols tests utils"
+		# shellcheck disable=SC2046,SC2086
 		mkdir -p $(cd "$srcdir"; find $COPYDIRS -type d)
 		find . -name Makefile -type l -print0 | xargs -0 rm 2> /dev/null
 		dst="$PWD"
 		cd "$srcdir"
+		# shellcheck disable=SC2044
 		for i in $(find . -name Makefile -type f); do
-			ln -s "$PWD${i#.}" "$dst/$i";
+			ln -s "$PWD${i#.}" "$dst/$i"
 		done
 		cd "$dst"
@@ -243,5 +245,5 @@
 cat<<EOF >config.h
 /* BitlBee settings, generated by configure
-   
+
    Do *NOT* use any of these defines in your code without thinking twice, most
    of them can/will be overridden at run-time */
@@ -273,13 +275,13 @@
 
 	if [ -z "$PKG_CONFIG_LIBDIR" ]; then
-		PKG_CONFIG_LIBDIR=/usr/$target/lib/pkgconfig
+		PKG_CONFIG_LIBDIR="/usr/$target/lib/pkgconfig"
 		export PKG_CONFIG_LIBDIR
 	fi
 
-	if [ -d /usr/$target/bin ]; then
-		PATH=/usr/$target/bin:$PATH
-	fi
-
-	if [ -d /usr/$target/lib ]; then
+	if [ -d "/usr/$target/bin" ]; then
+		PATH="/usr/$target/bin:$PATH"
+	fi
+
+	if [ -d "/usr/$target/lib" ]; then
 		systemlibdirs="$systemlibdirs /usr/$target/lib"
 	fi
@@ -327,12 +329,12 @@
 fi
 
-echo LDFLAGS=$LDFLAGS >> Makefile.settings
-
-echo CFLAGS=$CFLAGS $CPPFLAGS >> Makefile.settings
-
-echo CFLAGS+=-DHAVE_CONFIG_H -D_GNU_SOURCE >> Makefile.settings
+cat<<EOF >>Makefile.settings
+LDFLAGS=$LDFLAGS
+CFLAGS=$CFLAGS $CPPFLAGS
+CFLAGS+=-DHAVE_CONFIG_H -D_GNU_SOURCE
+EOF
 
 if [ -n "$CC" ]; then
-	CC=$CC
+	:
 elif type gcc > /dev/null 2> /dev/null; then
 	CC=gcc
@@ -341,11 +343,11 @@
 else
 	echo 'Cannot find a C compiler, aborting.'
-	exit 1;
-fi
-
-echo "CC=$CC" >> Makefile.settings;
-if echo $CC | grep -qw 'gcc\|clang'; then
+	exit 1
+fi
+
+echo "CC=$CC" >> Makefile.settings
+if echo "$CC" | grep -qw 'gcc\|clang'; then
 	# Apparently -Wall is gcc-specific?
-	echo CFLAGS+=-Wall -Wformat -Werror=format-security >> Makefile.settings
+	echo 'CFLAGS+=-Wall -Wformat -Werror=format-security' >> Makefile.settings
 fi
 
@@ -355,5 +357,5 @@
 	else
 		echo 'Cannot find ld, aborting.'
-		exit 1;
+		exit 1
 	fi
 fi
@@ -379,5 +381,5 @@
 	else
 		echo
-		echo 'Found glib2 '$($PKG_CONFIG glib-2.0 --modversion)', but version '$GLIB_MIN_VERSION' or newer is required.'
+		echo "Found glib2 $($PKG_CONFIG glib-2.0 --modversion), but version $GLIB_MIN_VERSION or newer is required."
 		exit 1
 	fi
@@ -420,8 +422,10 @@
 echo "EXTERNAL_JSON_PARSER=$external_json_parser" >> Makefile.settings
 if [ "$external_json_parser" = "1" ]; then
-    echo "CFLAGS+=$(pkg-config --cflags json-parser)" >> Makefile.settings
-    echo "CFLAGS+=-DUSE_EXTERNAL_JSON_PARSER" >> Makefile.settings
-    echo "LDFLAGS_BITLBEE+=$(pkg-config --libs json-parser)" >> Makefile.settings
-    echo "LDFLAGS_TESTS+=$(pkg-config --libs json-parser)" >> Makefile.settings
+	cat <<EOF >>Makefile.settings
+CFLAGS+=$(pkg-config --cflags json-parser)
+CFLAGS+=-DUSE_EXTERNAL_JSON_PARSER
+LDFLAGS_BITLBEE+=$(pkg-config --libs json-parser)
+LDFLAGS_TESTS+=$(pkg-config --libs json-parser)
+EOF
 fi
 
@@ -448,8 +452,8 @@
 		
 		ssl=gnutls
-		ret=1;
+		ret=1
 	else
-		ret=0;
-	fi;
+		ret=0
+	fi
 }
 
@@ -463,8 +467,8 @@
 		
 		ssl=nss
-		ret=1;
+		ret=1
 	else
-		ret=0;
-	fi;
+		ret=0
+	fi
 }
 
@@ -473,5 +477,5 @@
 #include <netinet/in.h>
 #include <arpa/nameser.h>
-#include <resolv.h> 
+#include <resolv.h>
 
 int main()
@@ -487,5 +491,5 @@
 #include <netinet/in.h>
 #include <arpa/nameser.h>
-#include <resolv.h> 
+#include <resolv.h>
 
 int main()
@@ -539,5 +543,5 @@
 	TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
 	ret=1
-	echo "$RESOLV_TESTCODE" | $CC -o $TMPFILE -x c - $LIBRESOLV >/dev/null 2>/dev/null
+	echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null
 	if [ "$?" = "0" ]; then
 		echo "EFLAGS+=$LIBRESOLV" >> Makefile.settings
@@ -545,5 +549,5 @@
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -554,8 +558,8 @@
 	ret=1
 	for i in $systemlibdirs; do
-		if [ -f $i/libresolv.a ]; then
-			echo "$RESOLV_TESTCODE" | $CC -o $TMPFILE -x c - -Wl,$i/libresolv.a >/dev/null 2>/dev/null
+		if [ -f "$i/libresolv.a" ]; then
+			echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i/libresolv.a" >/dev/null 2>/dev/null
 			if [ "$?" = "0" ]; then
-				echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings
+				echo "EFLAGS+=$i/libresolv.a" >> Makefile.settings
 				ret=0
 			fi
@@ -563,5 +567,5 @@
 	done
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -578,10 +582,10 @@
 	TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
 	ret=1
-	echo "$RESOLV_NS_TESTCODE" | $CC -o $TMPFILE -x c - $LIBRESOLV >/dev/null 2>/dev/null
+	echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null
 	if [ "$?" = "0" ]; then
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -592,6 +596,6 @@
 	ret=1
 	for i in $systemlibdirs; do
-		if [ -f $i/libresolv.a ]; then
-			echo "$RESOLV_NS_TESTCODE" | $CC -o $TMPFILE -x c - -Wl,$i/libresolv.a >/dev/null 2>/dev/null
+		if [ -f "$i/libresolv.a" ]; then
+			echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i/libresolv.a" >/dev/null 2>/dev/null
 			if [ "$?" = "0" ]; then
 				ret=0
@@ -600,5 +604,5 @@
 	done
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -610,10 +614,10 @@
 	# since we aren't actually linking with ns_* routines
 	# we can just compile the test code
-	echo "$RESOLV_NS_TYPES_TESTCODE" | $CC -o $TMPFILE -x c -  >/dev/null 2>/dev/null
+	echo "$RESOLV_NS_TYPES_TESTCODE" | $CC -o "$TMPFILE" -x c - >/dev/null 2>/dev/null
 	if [ "$?" = "0" ]; then
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -623,10 +627,10 @@
 	TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
 	ret=1
-	echo "$BACKTRACE_TESTCODE" | $CC -o $TMPFILE -x c -  >/dev/null 2>/dev/null
+	echo "$BACKTRACE_TESTCODE" | $CC -o "$TMPFILE" -x c - >/dev/null 2>/dev/null
 	if [ "$?" = "0" ]; then
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -681,5 +685,5 @@
 	
 	exit 1
-fi;
+fi
 
 echo 'SSL_CLIENT=ssl_'$ssl'.o' >> Makefile.settings
@@ -699,5 +703,5 @@
 if detect_backtrace; then
 	echo '#define HAVE_BACKTRACE' >> config.h
-	echo '#define CRASHFILE "'$config'crash.log"' >> config.h
+	echo '#define CRASHFILE "'"$config"'crash.log"' >> config.h
 fi
 
@@ -707,5 +711,5 @@
 	STORAGE_OBJS="$STORAGE_OBJS storage_$i.o"
 done
-echo "STORAGE_OBJS="$STORAGE_OBJS >> Makefile.settings
+echo "STORAGE_OBJS=$STORAGE_OBJS" >> Makefile.settings
 
 authobjs=
@@ -719,6 +723,6 @@
 	fi
 	echo '#define WITH_PAM' >> config.h
-	authobjs=$authobjs'auth_pam.o '
-	authlibs=$authlibs'-lpam '
+	authobjs="${authobjs}auth_pam.o "
+	authlibs="${authlibs}-lpam "
 fi
 if [ "$ldap" = 0 ]; then
@@ -730,12 +734,12 @@
 	fi
 	echo '#define WITH_LDAP' >> config.h
-	authobjs=$authobjs'auth_ldap.o '
-	authlibs=$authlibs'-lldap '
-fi
-echo AUTH_OBJS=$authobjs >> Makefile.settings
-echo EFLAGS+=$authlibs >> Makefile.settings
+	authobjs="${authobjs}auth_ldap.o "
+	authlibs="${authlibs}-lldap "
+fi
+echo "AUTH_OBJS=$authobjs" >> Makefile.settings
+echo "EFLAGS+=$authlibs" >> Makefile.settings
 
 if [ "$strip" = 0 ]; then
-	echo "STRIP=\# skip strip" >> Makefile.settings;
+	echo "STRIP=\# skip strip" >> Makefile.settings
 else
 	if [ "$debug" = 1 ]; then
@@ -743,37 +747,37 @@
 		echo 'Stripping binaries does not make sense when debugging. Stripping disabled.'
 		echo 'STRIP=\# skip strip' >> Makefile.settings
-		strip=0;
+		strip=0
 	elif [ -n "$STRIP" ]; then
-		echo "STRIP=$STRIP" >> Makefile.settings;
+		echo "STRIP=$STRIP" >> Makefile.settings
 	elif type strip > /dev/null 2> /dev/null; then
-		echo "STRIP=strip" >> Makefile.settings;
+		echo "STRIP=strip" >> Makefile.settings
 	else
 		echo
 		echo 'No strip utility found, cannot remove unnecessary parts from executable.'
 		echo 'STRIP=\# skip strip' >> Makefile.settings
-		strip=0;
-	fi;
+		strip=0
+	fi
 fi
 
 if [ ! "$systemd" = "0" ]; then
-    if ! $PKG_CONFIG --exists systemd; then
-        if [ "$systemd" = "1" ]; then
-            echo "systemd requested but not found"
-            exit 1
-        else
-            systemd=0
-        fi
-    elif [ "$systemd" = "auto" ]; then
-	systemd=1
-    fi
+	if ! $PKG_CONFIG --exists systemd; then
+		if [ "$systemd" = "1" ]; then
+			echo "systemd requested but not found"
+			exit 1
+		else
+			systemd=0
+		fi
+	elif [ "$systemd" = "auto" ]; then
+		systemd=1
+	fi
 fi
 
 pkgconf_systemd_var() {
-    # First try deprecated variable, use newer variable if not found
-    if $PKG_CONFIG --print-variables systemd | grep -q "$1"; then
-        $PKG_CONFIG --variable="$1" systemd
-    else
-        $PKG_CONFIG --variable="$2" systemd
-    fi
+	# First try deprecated variable, use newer variable if not found
+	if $PKG_CONFIG --print-variables systemd | grep -q "$1"; then
+		$PKG_CONFIG --variable="$1" systemd
+	else
+		$PKG_CONFIG --variable="$2" systemd
+	fi
 }
 
@@ -806,5 +810,4 @@
 fi
 
-otrprefix=""
 if [ "$otr" = "auto" ]; then
 	! $PKG_CONFIG --exists libotr
@@ -819,14 +822,18 @@
 	# BI == built-in
 	echo '#define OTR_BI' >> config.h
-	echo "EFLAGS+=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
-	echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
-	echo 'OTR_BI=otr.o' >> Makefile.settings
+	cat <<EOF >>Makefile.settings
+EFLAGS+=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)
+CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)
+OTR_BI=otr.o
+EOF
 elif [ "$otr" = "plugin" ]; then
 	# for some mysterious reason beyond the comprehension of my mortal mind,
 	# the libgcrypt flags aren't needed when building as plugin. add them anyway.
 	echo '#define OTR_PI' >> config.h
-	echo "OTRFLAGS=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
-	echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
-	echo 'OTR_PI=otr.so' >> Makefile.settings
+	cat <<EOF >>Makefile.settings
+OTRFLAGS=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)
+CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)
+OTR_PI=otr.so
+EOF
 fi
 
@@ -842,5 +849,5 @@
 if [ "$doc" = "1" ]; then
 	# check this here just in case someone tries to install it in python2.4...
-	if [ ! -e $srcdir/doc/user-guide/help.txt ] && ! $PYTHON -m xml.etree.ElementTree > /dev/null 2>&1; then
+	if [ ! -e "$srcdir/doc/user-guide/help.txt" ] && ! $PYTHON -m xml.etree.ElementTree > /dev/null 2>&1; then
 		echo
 		echo 'ERROR: Python (>=2.5 or 3.x) is required to generate docs'
@@ -857,5 +864,5 @@
 	echo "Spoofing version number: $BITLBEE_VERSION"
 	echo "#undef BITLBEE_VERSION" >> config.h
-	echo '#define BITLBEE_VERSION "'$BITLBEE_VERSION'"' >> config.h
+	echo '#define BITLBEE_VERSION "'"$BITLBEE_VERSION"'"' >> config.h
 	echo
 fi
@@ -878,4 +885,5 @@
 case "$arch" in
 CYGWIN* )
+	# shellcheck disable=SC2016
 	pkgconfiglibs='-L${libdir} -lbitlbee -no-undefined'
 esac
@@ -915,6 +923,6 @@
 	echo '#define WITH_PURPLE' >> config.h
 	cat<<EOF >>Makefile.settings
-EFLAGS += $($PKG_CONFIG purple --libs)
-PURPLE_CFLAGS += $($PKG_CONFIG purple --cflags)
+EFLAGS+=$($PKG_CONFIG purple --libs)
+PURPLE_CFLAGS+=$($PKG_CONFIG purple --cflags)
 EOF
 	protocols=$protocols'purple '
@@ -937,7 +945,7 @@
 case "$CC" in
 *gcc* )
-	echo CFLAGS+=-MMD -MF .depend/\$@.d >> Makefile.settings
+	echo "CFLAGS+=-MMD -MF .depend/\$@.d" >> Makefile.settings
 	for i in . lib tests protocols protocols/*/; do
-		mkdir -p $i/.depend
+		mkdir -p "$i/.depend"
 	done
 esac
@@ -967,5 +975,5 @@
 echo "PROTOOBJS = $protoobjs" >> Makefile.settings
 
-echo Architecture: $arch
+echo "Architecture: $arch"
 case "$arch" in
 Linux )
@@ -1049,18 +1057,18 @@
 fi
 
-echo '  Using python: '$PYTHON
+echo "  Using python: $PYTHON"
 
 if [ "$external_json_parser" = "1" ]; then
-    echo '  Using system JSON parser.'
-else
-    echo '  Using bundled JSON parser.'
-fi
-
-echo '  Using event handler: '$events
-echo '  Using SSL library: '$ssl
+	echo '  Using system JSON parser.'
+else
+	echo '  Using bundled JSON parser.'
+fi
+
+echo "  Using event handler: $events"
+echo "  Using SSL library: $ssl"
 #echo '  Building with these storage backends: '$STORAGES
 
 if [ -n "$protocols" ]; then
-	echo '  Building with these protocols:' $protocols$protocols_mods
+	echo "  Building with these protocols: $protocols$protocols_mods"
 	case "$protocols" in
 	*purple*)
