From fb06d48daa9854ac101683fcb1998c479e659a0c Mon Sep 17 00:00:00 2001 From: wollman Date: Mon, 1 Nov 2010 02:20:18 +0000 Subject: Style cleanup: make this look more like a 21st-century shell script and not something out of the early 1980s. Make sure all error messages go to stderr, not stdout. Since there's error-handling code to handle empty SEARCHPATHS and FILESYSTEMS, use the initialization form that allows this error to be diagnosed. (hat tip: jilles@) --- usr.bin/locate/locate/updatedb.sh | 48 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'usr.bin/locate') diff --git a/usr.bin/locate/locate/updatedb.sh b/usr.bin/locate/locate/updatedb.sh index 77fd24a..37c42e3 100644 --- a/usr.bin/locate/locate/updatedb.sh +++ b/usr.bin/locate/locate/updatedb.sh @@ -50,18 +50,20 @@ PATH=$LIBEXECDIR:/bin:/usr/bin:$PATH; export PATH : ${mklocatedb:=locate.mklocatedb} # make locate database program : ${FCODES:=/var/db/locate.database} # the database -: ${SEARCHPATHS:="/"} # directories to be put in the database -: ${PRUNEPATHS:="/tmp /usr/tmp /var/tmp /var/db/portsnap"} # unwanted directories +: ${SEARCHPATHS="/"} # directories to be put in the database +: ${PRUNEPATHS="/tmp /usr/tmp /var/tmp /var/db/portsnap"} # unwanted directories : ${PRUNEDIRS=".zfs"} # unwanted directories, in any parent -: ${FILESYSTEMS:="$(lsvfs | tail -n +3 | \ +: ${FILESYSTEMS="$(lsvfs | tail -n +3 | \ egrep -vw "loopback|network|synthetic|read-only|0" | \ cut -d " " -f1)"} # allowed filesystems : ${find:=find} -case X"$SEARCHPATHS" in - X) echo "$0: empty variable SEARCHPATHS"; exit 1;; esac -case X"$FILESYSTEMS" in - X) echo "$0: empty variable FILESYSTEMS"; exit 1;; esac +if [ -z "$SEARCHPATHS" ]; then + echo "$0: empty variable SEARCHPATHS" >&2; exit 1 +fi +if [ -z "$FILESYSTEMS" ]; then + echo "$0: empty variable FILESYSTEMS" >&2; exit 1 +fi # Make a list a paths to exclude in the locate run excludes="! (" or="" @@ -72,33 +74,29 @@ do done excludes="$excludes ) -prune" -case X"$PRUNEPATHS" in - X) ;; - *) for path in $PRUNEPATHS - do +if [ -n "$PRUNEPATHS" ]; then + for path in $PRUNEPATHS; do excludes="$excludes -or -path $path -prune" - done;; -esac + done +fi -case X"$PRUNEDIRS" in - X) ;; - *) for dir in $PRUNEDIRS - do +if [ -n "$PRUNEDIRS" ]; then + for dir in $PRUNEDIRS; do excludes="$excludes -or -name $dir -type d -prune" - done;; -esac + done +fi tmp=$TMPDIR/_updatedb$$ trap 'rm -f $tmp; rmdir $TMPDIR' 0 1 2 3 5 10 15 # search locally -# echo $find $SEARCHPATHS $excludes -or -print && exit if $find -s $SEARCHPATHS $excludes -or -print 2>/dev/null | $mklocatedb -presort > $tmp then - case X"`$find $tmp -size -257c -print`" in - X) cat $tmp > $FCODES;; - *) echo "updatedb: locate database $tmp is empty" - exit 1 - esac + if [ -n "$($find $tmp -size -257c -print)" ]; then + echo "updatedb: locate database $tmp is empty" >&2 + exit 1 + else + cat $tmp > $FCODES # should be cp? + fi fi -- cgit v1.1