diff options
author | wollman <wollman@FreeBSD.org> | 2010-11-01 02:20:18 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 2010-11-01 02:20:18 +0000 |
commit | fb06d48daa9854ac101683fcb1998c479e659a0c (patch) | |
tree | 89aabe59582902cd460e3dca8082ef31ec880236 | |
parent | 1c442b66f2df868491972f88a5f919e1a490cd4e (diff) | |
download | FreeBSD-src-fb06d48daa9854ac101683fcb1998c479e659a0c.zip FreeBSD-src-fb06d48daa9854ac101683fcb1998c479e659a0c.tar.gz |
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@)
-rw-r--r-- | usr.bin/locate/locate/updatedb.sh | 48 |
1 files changed, 23 insertions, 25 deletions
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 |