]> git.plutz.net Git - shellwiki/blob - maintenance.sh
search class for search form
[shellwiki] / maintenance.sh
1 #!/bin/sh
2
3 export _EXEC="${0%/*}/" _DATA=""  # _DATE="$(date +%s)"
4 verb=""
5
6 help() {
7   ex="$1"
8
9   cat >&2 <<-EOF
10         This script should be run regularly via cron to remove outdated
11         records from search the index.
12
13         USAGE:
14
15         INSTALL_DIR/maintenance.sh SITE_DIR
16
17         maintenance.sh --exec "INSTALL_DIR"  --data "SITE_DIR"
18
19         Options:
20
21         --exec INSTALL_DIR
22             Point to the location of your shellwiki installation. This will
23             default to the path at which the script is called, if it can be
24             determined.
25
26         --data SITE_DIR
27             Point to the location of your site installation. I.e. the directory
28             containing your "pages/" and "index/" dir.
29
30         EOF
31
32   exit "${ex:-0}"
33 }
34
35 while [ $# -gt 0 ]; do case $1 in
36   --exec|-e) _EXEC="${2%/}"; shift 2;;
37   --data|-d) _DATA="${2%/}"; shift 2;;
38   --verbose|-v) verb=true; shift 1;;
39   --help) help 0;;
40   *) [ ! "$_DATA" ] \
41      && _DATA="${1%/}" \
42      || help 1
43      ;;
44 esac; done
45
46 if ! [ -d "$_DATA/pages/" -a -d "$_DATA/index/" ]; then
47   printf 'ERROR: %s\n\n' "\"${_DATA}\" does not seem to be valid site directory" >&2
48   help 1
49 fi
50 if ! [ -x "$_EXEC/parsers/40_indexer.sh" -a -x "$_EXEC/cgilite/storage.sh" ]; then
51   printf 'ERROR: %s\n\n' "could not determine shellwiki installation path (tried \"$_EXEC\")" >&2
52   help 1
53 fi
54
55 . "$_EXEC/cgilite/storage.sh"
56
57 for word in "$_DATA/index"/*; do
58   [ "$word" = "$_DATA/index/*" ] && continue
59
60   [ "$verb" ] && printf '\r                                                  \r%s\r' "${word##*/}" >&2
61   mv -- "$word" "${word}.$$"
62
63   while read -r date location freq num total; do
64     l="$_DATA/pages$(UNSTRING "$location")#index.flag"
65     d="$(stat -c %Y "$l")" 2>&-
66
67     if [ "$date" -ge "$d" ] 2>&-; then
68       printf '%i        %s      %f      %i      %i\n' \
69              "$date" "$location" "$freq" "$num" "$total"
70     elif [ "$verb" ]; then
71       printf 'Removing "%s" from "%s"\n' "$location" "$word" >&2
72     fi
73   done <"${word}.$$" >>"${word}"
74   rm -- "${word}.$$"
75 done