~ubuntu-branches/ubuntu/lucid/mew-beta/lucid

« back to all changes in this revision

Viewing changes to bin/mewest

  • Committer: Bazaar Package Importer
  • Author(s): Tatsuya Kinoshita
  • Date: 2006-10-31 22:07:48 UTC
  • mfrom: (1.1.6 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061031220748-iq1bg528g9nt2l57
Tags: 5.1.52~0.20061031-1
New upstream release. (CVS trunk on 2006-10-31)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# mewest: Updating indexes of Hyper Estraier
 
4
#
 
5
# Author:  Mitsuo Kuroishi <kuroishi@iij.ad.jp>
 
6
# Author:  Kazu Yamamoto <Kazu@Mew.org>
 
7
# Created: Jul 20, 2006
 
8
# Revised: Jul 25, 2006
 
9
 
 
10
ESTCMD=estcmd
 
11
FIND=find
 
12
RM=rm
 
13
MKDIR=mkdir
 
14
BASEDIR=${HOME}/Mail
 
15
INDEXDIR=casket
 
16
OUTPUT=${OUTPUT:-/dev/null}
 
17
LOCK=${BASEDIR}/.mewest.lock
 
18
 
 
19
usage () {
 
20
    PROG=`basename $0`
 
21
    cat <<__HDT__
 
22
USAGE: ${PROG} [directory]
 
23
  -h help
 
24
  -v verbose mode
 
25
__HDT__
 
26
    exit 1
 
27
}
 
28
 
 
29
cleanup_lock () {
 
30
    ${RM} -fr ${LOCK}
 
31
    exit 4
 
32
}
 
33
 
 
34
cleanup_lock_exit () {
 
35
    echo $1
 
36
    cleanup_lock
 
37
}
 
38
 
 
39
while getopts "hv" OPTION
 
40
do
 
41
    case ${OPTION} in
 
42
      h)
 
43
        usage
 
44
        ;;
 
45
      v)
 
46
        OUTPUT=/dev/stdout
 
47
        ;;
 
48
      *)
 
49
        usage
 
50
        ;;
 
51
    esac
 
52
done
 
53
shift $(($OPTIND - 1))
 
54
TGTDIR=${1:-${HOME}/Mail}
 
55
 
 
56
trap cleanup_lock 1 2 3 9 15
 
57
 
 
58
# create and check lock
 
59
if ! ${MKDIR} ${LOCK} > /dev/null 2>&1 ; then
 
60
    echo "${LOCK} exists"
 
61
    exit 5
 
62
fi
 
63
 
 
64
# Directory exist?
 
65
if [ ! -d ${TGTDIR} ]; then
 
66
    cleanup_lock_exit "${TGTDIR} not found"
 
67
fi
 
68
 
 
69
if [ -d ${BASEDIR}/${INDEXDIR} ]; then
 
70
    echo "Purging old messages..."
 
71
    ${ESTCMD} purge ${BASEDIR}/${INDEXDIR} ${TGTDIR} > ${OUTPUT} ||\
 
72
      cleanup_lock_exit "Purging old messages...failed"
 
73
    echo "Purging old messages...done"
 
74
fi
 
75
 
 
76
echo "Indexing new messages..."
 
77
# "find"'s regular expression is NOT portable, sigh...
 
78
# "[0-9]*" matches both "123" and "234.mew".
 
79
 
 
80
${FIND} ${TGTDIR} \
 
81
  -type d -name "trash" -prune -o \
 
82
  -type d -name ${INDEXDIR} -prune -o \
 
83
  -type f \( -name "[0-9]" -o -name "[0-9]*[0-9]" -o -name "*.mew" \) -print |\
 
84
  ${ESTCMD} gather -cl -fm -cm -sd -xh ${BASEDIR}/${INDEXDIR} - > ${OUTPUT} ||\
 
85
    cleanup_lock_exit "Indexing new messages...failed"
 
86
 
 
87
echo "Indexing new messages...done"
 
88
 
 
89
# clean up lock
 
90
${RM} -fr ${LOCK}
 
91
 
 
92
exit 0
 
93
 
 
94
# Copyright (C) 2006 Mew developing team.
 
95
# All rights reserved.
 
96
#
 
97
# Redistribution and use in source and binary forms, with or without
 
98
# modification, are permitted provided that the following conditions
 
99
# are met:
 
100
 
101
# 1. Redistributions of source code must retain the above copyright
 
102
#    notice, this list of conditions and the following disclaimer.
 
103
# 2. Redistributions in binary form must reproduce the above copyright
 
104
#    notice, this list of conditions and the following disclaimer in the
 
105
#    documentation and/or other materials provided with the distribution.
 
106
# 3. Neither the name of the team nor the names of its contributors
 
107
#    may be used to endorse or promote products derived from this software
 
108
#    without specific prior written permission.
 
109
 
110
# THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
 
111
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
112
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
113
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
 
114
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
115
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
116
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 
117
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
118
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 
119
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 
120
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.