bashism removal patch

2 posts / 0 new
Last post
Anonymous
bashism removal patch

(I'm following the notes at http://www.tigase.org/content/how-help - although the bug reporter is dead (it looks like it's swapped to http://www.tigase.org/content/tigase-xmpp-server so I've raised two tickets there. It also seems better than a forum for bug reports, but I'll do as I'm told!)

This patch removes a pile of bashisms from shell scripts, it also has a few minor improvements:
- "$@" rather than $* (this copes with whitespace)
- tigase.sh works out TIGASE_HOME better and removes the bashism regexp at the expense of using readlink (which isn't in POSIX)

Cheers,

Adrian Bridgett

Index: scripts/debian/tigase.init.d
===================================================================
--- scripts/debian/tigase.init.d (revision 2103)
+++ scripts/debian/tigase.init.d (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
### BEGIN INIT INFO
# Provides: tigase
# Required-Start: networking
@@ -44,12 +44,17 @@
fi
done

-[[ -z "${TIGASE_RUN}" ]] && \
+if [ -z "${TIGASE_RUN}" ]]; then
TIGASE_RUN="tigase.server.XMPPServer -c ${TIGASE_CONFIG} ${TIGASE_OPTIONS}"
+fi

-[[ -z "${JAVA}" ]] && JAVA="${JAVA_HOME}/bin/java"
+if [ -z "${JAVA}" ]; then
+ JAVA="${JAVA_HOME}/bin/java"
+fi

-[[ -z "${CLASSPATH}" ]] || CLASSPATH="${CLASSPATH}:"
+if [ -z "${CLASSPATH}" ]; then
+ CLASSPATH="${CLASSPATH}:"
+fi

CLASSPATH="${CLASSPATH}${TIGASE_JAR}"

Index: scripts/derby-db-create.sh
===================================================================
--- scripts/derby-db-create.sh (revision 2103)
+++ scripts/derby-db-create.sh (working copy)
@@ -1,8 +1,9 @@
-#!/bin/bash
+#!/bin/sh

-[[ "$1" = "" ]] && \
- echo "Give me a path to the location where you want to have the database created" && \
+if [ "$#" -ne 1 ]; then
+ echo "Usage: $0 database"
exit 1
+fi

java -Dij.protocol=jdbc:derby: -Dij.database="$1;create=true" \
Index: scripts/prepare-installer.sh
===================================================================
--- scripts/prepare-installer.sh (revision 2103)
+++ scripts/prepare-installer.sh (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh

INSTALLER_DIR="installer"
SVN_URL="http://svn.codehaus.org/izpack/izpack-src/trunk/"
Index: scripts/tigase.sh
===================================================================
--- scripts/tigase.sh (revision 2103)
+++ scripts/tigase.sh (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
##
## Tigase Jabber/XMPP Server
## Copyright (C) 2004-2007 "Artur Hefczyc"
@@ -60,7 +60,7 @@
TIGASE_PARAMS=${2}
fi

-[[ -f "${TIGASE_PARAMS}" ]] && . ${TIGASE_PARAMS}
+[ -f "${TIGASE_PARAMS}" ] && . ${TIGASE_PARAMS}

if [ -z "${JAVA_HOME}" ] ; then
echo "JAVA_HOME is not set."
@@ -68,13 +68,10 @@
exit 1
fi
if [ -z "${TIGASE_HOME}" ] ; then
- if [ ${0:0:1} = '/' ] ; then
- TIGASE_HOME=${0}
- else
- TIGASE_HOME=${PWD}/${0}
- fi
+ TIGASE_HOME=`readlink -f $0`
TIGASE_HOME=`dirname ${TIGASE_HOME}`
TIGASE_HOME=`dirname ${TIGASE_HOME}`
+echo $TIGASE_HOME
TIGASE_JAR=""
fi
for j in ${TIGASE_HOME}/jars/tigase-server*.jar ; do
@@ -126,12 +123,17 @@
fi
fi

-[[ -z "${TIGASE_RUN}" ]] && \
+if [ -z "${TIGASE_RUN}" ]; then
TIGASE_RUN="tigase.server.XMPPServer -c ${TIGASE_CONFIG} ${TIGASE_OPTIONS}"
+fi

-[[ -z "${JAVA}" ]] && JAVA="${JAVA_HOME}/bin/java"
+if [ -z "${JAVA}" ]; then
+ JAVA="${JAVA_HOME}/bin/java"
+fi

-[[ -z "${CLASSPATH}" ]] || CLASSPATH="${CLASSPATH}:"
+if [ -z "${CLASSPATH}" ]; then
+ CLASSPATH="${CLASSPATH}:"
+fi

CLASSPATH="${CLASSPATH}${TIGASE_JAR}"

Index: scripts/user_roster.sh
===================================================================
--- scripts/user_roster.sh (revision 2103)
+++ scripts/user_roster.sh (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
##
## Tigase Jabber/XMPP Server
## Copyright (C) 2004-2007 "Artur Hefczyc"
Index: scripts/config.sh
===================================================================
--- scripts/config.sh (revision 2103)
+++ scripts/config.sh (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
##
## Tigase Jabber/XMPP Server
## Copyright (C) 2004-2007 "Artur Hefczyc"
@@ -23,4 +23,4 @@

CP="jars/tigase-server.jar:/usr/share/jdbc-mysql/lib/jdbc-mysql.jar:libs/tigase-xmltools.jar:libs/tigase-utils.jar"

-java -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -cp $CP tigase.conf.Configurator $*
\ No newline at end of file
+java -Dfile.encoding=UTF-8 -Dsun.jnu.encoding=UTF-8 -cp $CP tigase.conf.Configurator "$@"
Index: scripts/generate-installer.sh
===================================================================
--- scripts/generate-installer.sh (revision 2103)
+++ scripts/generate-installer.sh (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh

IZPACK_DIR="installer/izpack.patched"
#IZPACK_DIR="/Applications/IzPack"
Index: scripts/repo.sh
===================================================================
--- scripts/repo.sh (revision 2103)
+++ scripts/repo.sh (working copy)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
##
## Tigase Jabber/XMPP Server
## Copyright (C) 2004-2007 "Artur Hefczyc"
@@ -28,4 +28,4 @@
MYSQL_REP="-sc tigase.db.jdbc.JDBCRepository -su jdbc:mysql://localhost/nk_200k?user=root&password=mypass"
PGSQL_REP="-sc tigase.db.jdbc.JDBCRepository -su jdbc:postgresql://localhost/tigase?user=tigase"

-java $D -cp $CP tigase.util.RepositoryUtils $MYSQL_REP $*
+java $D -cp $CP tigase.util.RepositoryUtils $MYSQL_REP "$@"

Application: 

Thanks a lot for the patches. I am sorry for the broken links and outdated information on some pages. I have already fixed them.
It is indeed a better idea to provide patches within a ticket instead of inside the forums post. I will try to apply your patches before the 5.0.0 final version.