Index: configure
===================================================================
--- configure	(revision 8ca172fcfb1f60f9933a3933fdd809699ce466ce)
+++ configure	(revision 2bd8f392a0d066f8f3c3f937ad2e6c1d90da78b0)
@@ -8,24 +8,24 @@
 ##############################
 
-prefix='/usr/local/'
-bindir='$prefix/bin/'
-sbindir='$prefix/sbin/'
-etcdir='$prefix/etc/bitlbee/'
-mandir='$prefix/share/man/'
-datadir='$prefix/share/bitlbee/'
-config='/var/lib/bitlbee/'
-libdir='$prefix/lib/'
-plugindir='$prefix/lib/bitlbee/'
-includedir='$prefix/include/bitlbee/'
-systemdsystemunitdir=''
-sysusersdir=''
-libevent='/usr/'
-pidfile='/var/run/bitlbee.pid'
-ipcsocket=''
-pcdir='$prefix/lib/pkgconfig'
+prefix="/usr/local/"
+bindir="$prefix/bin/"
+sbindir="$prefix/sbin/"
+etcdir="$prefix/etc/bitlbee/"
+mandir="$prefix/share/man/"
+datadir="$prefix/share/bitlbee/"
+config="/var/lib/bitlbee/"
+libdir="$prefix/lib/"
+plugindir="$prefix/lib/bitlbee/"
+includedir="$prefix/include/bitlbee/"
+systemdsystemunitdir=""
+sysusersdir=""
+libevent="/usr/"
+pidfile="/var/run/bitlbee.pid"
+ipcsocket=""
+pcdir="$prefix/lib/pkgconfig"
 systemlibdirs="/lib64 /usr/lib64 /usr/local/lib64 /lib /usr/lib /usr/local/lib"
-sysroot=''
-
-configure_args="$@"
+sysroot=""
+
+configure_args="$*"
 
 # Set these to default-on to let it be overriden by either the user or purple
@@ -78,5 +78,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 +88,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" || exit 1; git show -s --format=%ci HEAD | sed 's/ .*$//; s/-//g')
+		branch=$(cd "$srcdir" || exit 1; 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 ! describe=$(cd "$srcdir" || exit 1; git describe --long --tags 2>/dev/null) ; then
+			describe=${REAL_BITLBEE_VERSION}-0-g$(cd "$srcdir" || exit; 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 +106,7 @@
 
 if [ "$1" = "--dump-version" ]; then
-	srcdir=$(cd $(dirname $0);pwd)
+	srcdir=$(cd "$(dirname "$0")" || exit;pwd)
 	get_version
-	echo $BITLBEE_VERSION
+	echo "$BITLBEE_VERSION"
 	exit
 fi
@@ -217,19 +216,19 @@
 EOF
 
-srcdir=$(cd $(dirname $0);pwd)
+srcdir=$(cd "$(dirname "$0")" || exit;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"
-		mkdir -p $(cd "$srcdir"; find $COPYDIRS -type d)
+		mkdir -p "$(cd "$srcdir" || exit 1; find "$COPYDIRS" -type d)"
 		find . -name Makefile -type l -print0 | xargs -0 rm 2> /dev/null
 		dst="$PWD"
-		cd "$srcdir"
-		for i in $(find . -name Makefile -type f); do
+		cd "$srcdir" || exit 1
+		find . -type f -name Makefile -print | while read -r i ; do
 			ln -s "$PWD${i#.}" "$dst/$i";
 		done
-		cd "$dst"
+		cd "$dst" || exit 1
 		rm -rf .bzr
 	fi
@@ -273,13 +272,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,14 +326,13 @@
 fi
 
-echo LDFLAGS=$LDFLAGS >> Makefile.settings
-
-echo CFLAGS=$CFLAGS $CPPFLAGS >> Makefile.settings
-echo CFLAGS+=-I${srcdir} -I${srcdir}/lib -I${srcdir}/protocols -I. >> Makefile.settings
+# shellcheck disable=SC2129
+echo "LDFLAGS=$LDFLAGS" >> Makefile.settings
+
+echo "CFLAGS=$CFLAGS $CPPFLAGS" >> Makefile.settings
+echo CFLAGS+=-I"${srcdir}" -I"${srcdir}"/lib -I"${srcdir}"/protocols -I. >> Makefile.settings
 
 echo CFLAGS+=-DHAVE_CONFIG_H -D_GNU_SOURCE >> Makefile.settings
 
-if [ -n "$CC" ]; then
-	CC=$CC
-elif type gcc > /dev/null 2> /dev/null; then
+if type gcc > /dev/null 2> /dev/null; then
 	CC=gcc
 elif type cc > /dev/null 2> /dev/null; then
@@ -380,5 +378,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
@@ -421,4 +419,5 @@
 echo "EXTERNAL_JSON_PARSER=$external_json_parser" >> Makefile.settings
 if [ "$external_json_parser" = "1" ]; then
+    # shellcheck disable=SC2129
     echo "CFLAGS+=$(pkg-config --cflags json-parser)" >> Makefile.settings
     echo "LDFLAGS_BITLBEE+=$(pkg-config --libs json-parser)" >> Makefile.settings
@@ -538,11 +537,10 @@
 	TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
 	ret=1
-	echo "$RESOLV_TESTCODE" | $CC -o $TMPFILE -x c - $LIBRESOLV >/dev/null 2>/dev/null
-	if [ "$?" = "0" ]; then
+	if echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null ; then
 		echo "EFLAGS+=$LIBRESOLV" >> Makefile.settings
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -553,8 +551,7 @@
 	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 [ "$?" = "0" ]; then
-				echo 'EFLAGS+='$i'/libresolv.a' >> Makefile.settings
+		if [ -f "$i"/libresolv.a ]; then
+			if echo "$RESOLV_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i"/libresolv.a >/dev/null 2>/dev/null ; then
+				echo "EFLAGS+=$i/libresolv.a" >> Makefile.settings
 				ret=0
 			fi
@@ -562,5 +559,5 @@
 	done
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -577,10 +574,9 @@
 	TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
 	ret=1
-	echo "$RESOLV_NS_TESTCODE" | $CC -o $TMPFILE -x c - $LIBRESOLV >/dev/null 2>/dev/null
-	if [ "$?" = "0" ]; then
+	if echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - $LIBRESOLV >/dev/null 2>/dev/null ; then
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -591,7 +587,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 [ "$?" = "0" ]; then
+		if [ -f "$i"/libresolv.a ]; then
+			if echo "$RESOLV_NS_TESTCODE" | $CC -o "$TMPFILE" -x c - -Wl,"$i"/libresolv.a >/dev/null 2>/dev/null ; then
 				ret=0
 			fi
@@ -599,5 +594,5 @@
 	done
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -609,10 +604,9 @@
 	# 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
-	if [ "$?" = "0" ]; then
+	if echo "$RESOLV_NS_TYPES_TESTCODE" | $CC -o "$TMPFILE" -x c -  >/dev/null 2>/dev/null ; then
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -622,10 +616,9 @@
 	TMPFILE=$(mktemp /tmp/bitlbee-configure.XXXXXX)
 	ret=1
-	echo "$BACKTRACE_TESTCODE" | $CC -o $TMPFILE -x c -  >/dev/null 2>/dev/null
-	if [ "$?" = "0" ]; then
+	if echo "$BACKTRACE_TESTCODE" | $CC -o "$TMPFILE" -x c -  >/dev/null 2>/dev/null ; then
 		ret=0
 	fi
 
-	rm -f $TMPFILE
+	rm -f "$TMPFILE"
 	return $ret
 }
@@ -698,5 +691,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
 
@@ -706,9 +699,9 @@
 	STORAGE_OBJS="$STORAGE_OBJS storage_$i.o"
 done
-echo "STORAGE_OBJS="$STORAGE_OBJS >> Makefile.settings
+echo "STORAGE_OBJS=$STORAGE_OBJS" >> Makefile.settings
 
 authobjs=
 authlibs=
-if [ "$pam" = 0 ]; then
+if [ "$pam" = "0" ]; then
 	echo '#undef WITH_PAM' >> config.h
 else
@@ -721,5 +714,5 @@
 	authlibs=$authlibs'-lpam '
 fi
-if [ "$ldap" = 0 ]; then
+if [ "$ldap" = "0" ]; then
 	echo '#undef WITH_LDAP' >> config.h
 else
@@ -732,11 +725,11 @@
 	authlibs=$authlibs'-lldap '
 fi
-echo AUTH_OBJS=$authobjs >> Makefile.settings
-echo EFLAGS+=$authlibs >> Makefile.settings
-
-if [ "$strip" = 0 ]; then
+echo AUTH_OBJS="$authobjs" >> Makefile.settings
+echo EFLAGS+="$authlibs" >> Makefile.settings
+
+if [ "$strip" = "0" ]; then
 	echo "STRIP=\# skip strip" >> Makefile.settings;
 else
-	if [ "$debug" = 1 ]; then
+	if [ "$debug" = "1" ]; then
 		echo
 		echo 'Stripping binaries does not make sense when debugging. Stripping disabled.'
@@ -755,7 +748,7 @@
 fi
 
-if [ ! "$systemd" = 0 ]; then
+if [ ! "$systemd" = "0" ]; then
     if ! $PKG_CONFIG --exists systemd ; then
-        if [ -n "$systemdsystemunitdir" ] || [ "$systemd" -eq 1 ]; then
+        if [ -n "$systemdsystemunitdir" ] || [ $systemd -eq 1 ]; then
             echo "systemd requested but not found"
             exit 1
@@ -768,18 +761,15 @@
 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
+    if $PKG_CONFIG --print-variables systemd | grep -q "$1" ; then
+        $PKG_CONFIG --variable="$1" systemd
     else
-        $PKG_CONFIG --variable=$2 systemd
+        $PKG_CONFIG --variable="$2" systemd
     fi
 }
 
-if [ "$systemd" -eq 1 ]; then
+if [ "$systemd" = "1" ]; then
 	if [ -z "$systemdsystemunitdir" ]; then
 		systemdsystemunitdir=$(pkgconf_systemd_var systemdsystemunitdir systemd_system_unit_dir)
 	fi
-    if [ -z "$tmpfiles_dir" ] ; then
-        tmpfilesdir=$(pkgconf_systemd_var tmpfilesdir tmpfiles_dir)
-    fi
     if [ -z "$sysusersdir" ] ; then
         sysusersdir=$(pkgconf_systemd_var sysusersdir sysusers_dir)
@@ -795,5 +785,5 @@
 fi
 
-if [ "$plugins" = 0 ]; then
+if [ "$plugins" = "0" ]; then
 	plugindir=""
 	echo '#undef WITH_PLUGINS' >> config.h
@@ -802,5 +792,4 @@
 fi
 
-otrprefix=""
 if [ "$otr" = "auto" ]; then
 	! $PKG_CONFIG --exists libotr
@@ -808,11 +797,12 @@
 fi
 
-if [ "$otr" != 0 ] && ! $PKG_CONFIG --atleast-version=4.0 --print-errors libotr; then
+if [ "$otr" != "0" ] && ! $PKG_CONFIG --atleast-version=4.0 --print-errors libotr; then
 	exit 1
 fi
 
-if [ "$otr" = 1 ]; then
+if [ "$otr" = "1" ]; then
 	# BI == built-in
 	echo '#define OTR_BI' >> config.h
+	# shellcheck disable=SC2129
 	echo "EFLAGS+=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
 	echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
@@ -822,4 +812,5 @@
 	# the libgcrypt flags aren't needed when building as plugin. add them anyway.
 	echo '#define OTR_PI' >> config.h
+	# shellcheck disable=SC2129
 	echo "OTRFLAGS=$($PKG_CONFIG --libs libotr) $(libgcrypt-config --libs)" >> Makefile.settings
 	echo "CFLAGS+=$($PKG_CONFIG --cflags libotr) $(libgcrypt-config --cflags)" >> Makefile.settings
@@ -838,5 +829,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'
@@ -850,8 +841,8 @@
 get_version
 
-if [ "$BITLBEE_VERSION" != "$REAL_BITLBEE_VERSION" ]; then
-	echo 'Spoofing version number: '$BITLBEE_VERSION
-	echo '#undef BITLBEE_VERSION' >> config.h
-	echo '#define BITLBEE_VERSION "'$BITLBEE_VERSION'"' >> config.h
+if [ ! "$BITLBEE_VERSION" = "$REAL_BITLBEE_VERSION" ]; then
+	echo "Spoofing version number: $BITLBEE_VERSION"
+	echo "#undef BITLBEE_VERSION" >> config.h
+	echo "#define BITLBEE_VERSION '$BITLBEE_VERSION'" >> config.h
 	echo
 fi
@@ -874,5 +865,5 @@
 case "$arch" in
 CYGWIN* )
-	pkgconfiglibs='-L${libdir} -lbitlbee -no-undefined'
+	pkgconfiglibs="-L${libdir} -lbitlbee -no-undefined"
 esac
 
@@ -896,5 +887,5 @@
 protoobjs=''
 
-if [ "$purple" = 0 ]; then
+if [ "$purple" = "0" ]; then
 	echo '#undef WITH_PURPLE' >> config.h
 else
@@ -930,9 +921,9 @@
 	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
 
-if [ "$jabber" = 0 ]; then
+if [ "$jabber" = "0" ]; then
 	echo '#undef WITH_JABBER' >> config.h
 else
@@ -942,5 +933,5 @@
 fi
 
-if [ "$twitter" = 0 ]; then
+if [ "$twitter" = "0" ]; then
 	echo '#undef WITH_TWITTER' >> config.h
 else
@@ -958,5 +949,5 @@
 echo "PROTOOBJS = $protoobjs" >> Makefile.settings
 
-echo Architecture: $arch
+echo Architecture: "$arch"
 case "$arch" in
 Linux )
@@ -1034,5 +1025,5 @@
 fi
 
-if [ "$systemd" -eq 1 ]; then
+if [ "$systemd" = "1" ]; then
 	echo '  systemd enabled.'
 else
@@ -1053,5 +1044,5 @@
 
 if [ -n "$protocols" ]; then
-	echo '  Building with these protocols:' $protocols$protocols_mods
+	echo '  Building with these protocols:' "$protocols""$protocols_mods"
 	case "$protocols" in
 	*purple*)
