Why does bogofilter need bash?

Clint Adams schizo at debian.org
Fri May 28 20:42:57 CEST 2004


> We need bash for three of the contrib/ stuff scripts, and a cursory
> glance tells me there are bashisms such as substring extraction
> (${Parameter:offset:length}) in randomtrain. Haven't looked at the other
> two.

Other than the following, all instances of echo should be changed to use
either "cat" or "printf".  Then there's a dependency on a "which"
command too.

Index: contrib/trainbogo.sh
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/contrib/trainbogo.sh,v
retrieving revision 1.4
diff -u -r1.4 trainbogo.sh
--- contrib/trainbogo.sh	29 Oct 2003 15:13:14 -0000	1.4
+++ contrib/trainbogo.sh	28 May 2004 18:38:55 -0000
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Train bogofilter from a ham and spam corpus
 #
@@ -11,7 +11,7 @@
 # Note:  this script has not yet had bogofilter maintainer review.
 # Security concerned people should not run it if in doubt about its security.
 
-function usage()
+usage()
 {
     echo "USAGE:"
     echo
@@ -42,7 +42,7 @@
     echo
 }
 
-function help()
+help()
 {
     echo "trainbogo.sh"
     echo
@@ -80,32 +80,32 @@
     usage
 }
 
-function verbose
+verbose()
 {
     [ -n "${verbose}" ] && echo $@
 }
 
-function normal
+normal()
 {
     [ -z "${quiet}" ] && echo $@
 }
 
-function normaln
+normaln()
 {
     [ -z "${quiet}" ] && echo -n $@
 }
 
-function cleanup
+cleanup()
 {
     verbose "Performing cleanup"
 
-    [ -z "${log}" -o -z "${list}" -o "${docleanup}" != "y" ] && return
+    [ -z "${log}" ] || [ -z "${list}" ] || [ "${docleanup}" != "y" ] && return
 
     rm -f	${log}.[01].success ${log}.[01].fail \
 	${log}.[01].train.success ${log}.[01].train.fail \
 	${list}
 
-    [ "${madestatsdir}" == "y" -a -n "${statsdir}" ] && rmdir --ignore-fail-on-non-empty "${statsdir}"
+    [ "${madestatsdir}" = "y" ] && [ -n "${statsdir}" ] && rmdir --ignore-fail-on-non-empty "${statsdir}"
 }
 
 dofilelist=
@@ -139,12 +139,12 @@
 done
 
 # Check for required options
-[ -z "${hamdir}" -o ! -d "${hamdir}" ] && echo "Missing or bad -H option" && usage && exit
-[ -z "${spamdir}" -o ! -d "${spamdir}" ] && echo "Missing or bad -S option" && usage && exit
+[ -z "${hamdir}" ] || [ ! -d "${hamdir}" ] && echo "Missing or bad -H option" && usage && exit
+[ -z "${spamdir}" ] || [ ! -d "${spamdir}" ] && echo "Missing or bad -S option" && usage && exit
 [ -z "${statsdir}" ] && echo "Bad statsdir option" && usage && exit
 
 # make the stats dir if its missing, but only if its the default stats dir and not user specified
-[ "${statsdir}" == "${origstatsdir}" -a ! -d "${statsdir}" ] && mkdir "${statsdir}" && madestatsdir=y
+[ "${statsdir}" = "${origstatsdir}" ] && [ ! -d "${statsdir}" ] && mkdir "${statsdir}" && madestatsdir=y
 [ ! -d "${statsdir}" ] && echo "Missing statsdir (-s option)" && exit
 
 # check for bogofilter
@@ -156,7 +156,7 @@
 log="${statsdir}/trainbogo.log"
 
 # Init log files
-if [ ! -f "${log}.0.success" -o -n "${dotest}" -o -n "${dotrain}" ] ; then
+if [ ! -f "${log}.0.success" ] || [ -n "${dotest}" ] || [ -n "${dotrain}" ] ; then
     verbose "init log files"
     >"${log}.0.success"
     >"${log}.1.success"
@@ -169,7 +169,7 @@
 fi
 
 # First make a randomly sorted list of all the ham and spam files (if needed)
-if [ ! -f "${list}" -o -n "${dofilelist}" ]; then
+if [ ! -f "${list}" ] || [ -n "${dofilelist}" ]; then
     # MD5 all the spam and ham
 
     [ -z "${rndseed}" ] && rndseed="$$.$(date +%s)"
@@ -204,7 +204,7 @@
 fi
 
 # Read each filename from the filelist and test and train bogofilter.
-if [ -n "${dotest}" -o -n "${dotrain}" ]; then
+if [ -n "${dotest}" ] || [ -n "${dotrain}" ]; then
     normal "Training bogofilter"
     (while read spamstatus fname
 	do



More information about the bogofilter-dev mailing list