summaryrefslogtreecommitdiff
path: root/localrundig
blob: 0d27c9bf37d28187918f1822d95687b5a6e26f4f (plain)
  1. #!/bin/sh
  2. #
  3. # /usr/local/sbin/localrundig
  4. # Copyright 2001-2002 Jonas Smedegaard <dr@jones.dk>
  5. #
  6. # $Id: localrundig,v 1.4 2002-03-07 16:22:51 jonas Exp $
  7. #
  8. # Create a search database for ht://Dig.
  9. # Based on upstream sample script (but completely rewritten by now)
  10. #
  11. DBDIR=/var/lib/htdig
  12. COMMONDIR=/etc/htdig
  13. BINDIR=/usr/bin
  14. # To help debug problems, try running rundig -vvv
  15. # This will add lots of debugging output to all of the programs
  16. stats= opts= alt= init=
  17. for arg
  18. do
  19. case "$arg" in
  20. -a) alt="$arg" ;;
  21. -s) stats="$arg" ;;
  22. -i) init="$arg" ;;
  23. *) opts="$opts $arg" ;; # e.g. -v or -c config
  24. esac
  25. done
  26. config=`echo "$opts"|sed 's/^.*-c[[:space:]]\+\([[:alnum:]/._-]\+\).*$/\1/'`
  27. test -n "$config" || config=/etc/htdig/htdig.conf
  28. locale=`grep '^locale:' $config | sed -e 's/.*:[[:space:]]*\([[:alnum:]_-]\+\).*/\1/'`
  29. test -n "$locale" || locale=en_US
  30. search_object=`grep '^search_object:' $config | sed -e 's/.*:[[:space:]]*\([[:alnum:]_-]\+\).*/\1/'`
  31. LOCALDBDIR=/var/local/lib/htdig/db/$search_object
  32. LOCALLANGSTATICDIR=/usr/local/lib/htdig/lang/$locale
  33. LOCALLANGDIR=/var/local/lib/htdig/lang/$locale
  34. test -d $LOCALDBDIR || mkdir $LOCALDBDIR
  35. #
  36. # Set the TMPDIR variable if you want htmerge to put files in a location
  37. # other than the default. This is important if you do not have enough
  38. # disk space for the big sort that htmerge runs. Also, be aware that
  39. # on some systems, /tmp is a memory mapped filesystem that takes away
  40. # from virtual memory.
  41. #
  42. TMPDIR=${TMPDIR:-$LOCALDBDIR}
  43. export TMPDIR
  44. $BINDIR/htdig $init $opts $stats $alt
  45. LC_COLLATE=C $BINDIR/htmerge $opts $stats $alt
  46. case "$alt" in
  47. -a)
  48. ( cd $LOCALDBDIR && test -f db.docdb.work &&
  49. for f in *.work
  50. do
  51. mv -f $f `basename $f .work`
  52. done ) ;;
  53. esac
  54. # If you're low on disk space and you don't mind completely reindexing
  55. # every time you run this script, you can always
  56. # rm $DBDIR/db.wordlist
  57. # OR
  58. # If you'd rather run update digs all the time with the minimal databases
  59. # Keep only the following files (and don't call htdig with -i):
  60. # db.docdb, db.docdb.work, db.docs.index, db.wordlist.work, db.words.db
  61. $BINDIR/htnotify $opts
  62. #
  63. # Create the endings and synonym databases if they don't exist
  64. # or if they're older than the files they're generated from.
  65. # These databases are semi-static, so even if pages change,
  66. # these databases will not need to be rebuilt.
  67. case "$locale" in
  68. en_*)
  69. $BINDIR/htfuzzy $opts metaphone ;;
  70. *)
  71. $BINDIR/htfuzzy $opts soundex ;;
  72. esac
  73. if [ "`ls -t $LOCALLANGSTATICDIR/dict.0 $LOCALLANGDIR/word2root.db 2>/dev/null | sed 1q`" = \
  74. "$LOCALLANGSTATICDIR/dict.0" ]
  75. then
  76. $BINDIR/htfuzzy $opts endings
  77. fi
  78. if [ "`ls -t $LOCALLANGSTATICDIR/synonyms $LOCALLANGDIR/synonyms.db 2>/dev/null | sed 1q`" = \
  79. "$LOCALLANGSTATICDIR/synonyms" ]
  80. then
  81. $BINDIR/htfuzzy $opts synonyms
  82. fi