Debian Codegraph @

bin/mewest

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 #
3 # mewest: Updating indexes of Hyper Estraier
4 #
5 # Author: Mitsuo Kuroishi <[email protected]>
6 # Author: Kazu Yamamoto <[email protected]>
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_ORG=casket
16 INDEXDIR_REPLICA=casket_replica
17 INDEXDIR=${INDEXDIR_ORG}
18 OUTPUT=${OUTPUT:-/dev/null}
19 LOCK=${BASEDIR}/.mewest.lock
20 CYGWINENV=no
21 SUFFIX=${SUFFIX:-.mew}
22
23 usagescip-shell shell shell-project 0.0.0 usage(). () {
24 PROG=`basenamescip-shell system . . basename. $0`
25 catscip-shell system . . cat. <<__HDT__
26 USAGE: ${PROG} [directory]
27 -s specify suffix
28 -h help
29 -v verbose mode
30 -b base dir
31 __HDT__
32 exit 1
33 }
34
35 cleanupscip-shell shell shell-project 0.0.0 cleanup(). () {
36 ${RM} -fr "${LOCK}"
37 clean_up_replicascip-shell shell shell-project 0.0.0 clean_up_replica().
38 }
39
40 cleanup_trapscip-shell shell shell-project 0.0.0 cleanup_trap(). () {
41 cleanupscip-shell shell shell-project 0.0.0 cleanup().
42 exit 4
43 }
44
45 cleanup_exitscip-shell shell shell-project 0.0.0 cleanup_exit(). () {
46 echoscip-shell system . . echo. $1
47 cleanupscip-shell shell shell-project 0.0.0 cleanup().
48 exit 4
49 }
50
51 clean_up_replicascip-shell shell shell-project 0.0.0 clean_up_replica(). () {
52 if [scip-shell system . . `[`. -d "${BASEDIR}/${INDEXDIR_REPLICA}" ]; then
53 rmscip-shell system . . rm. -fr "${BASEDIR}/${INDEXDIR_REPLICA}"
54 fi
55 }
56
57 # Check if environment is Cygwin.
58 check_cygwinscip-shell shell shell-project 0.0.0 check_cygwin(). () {
59 if type uname > /dev/nullscip-shell filesystem . . `/dev/null`.
60 then
61 truescip-shell system . . true.
62 else
63 return 255
64 fi
65 case `unamescip-shell system . . uname. -s` in
66 CYGWIN*)
67 if type cygpath > /dev/nullscip-shell filesystem . . `/dev/null`.
68 then
69 return 1
70 else
71 return 255
72 fi
73 ;;
74 *)
75 return 0
76 ;;
77 esac
78 }
79
80 # Convert path style from Unix to Windows if environment is Cygwin.
81 # Otherwise same path is simply echoed.
82 path_convscip-shell shell shell-project 0.0.0 path_conv().() {
83 if [scip-shell system . . `[`. $CYGWINENV = "yes" ];
84 then
85 cygpath -w "$1"
86 else
87 echoscip-shell system . . echo. "$1"
88 fi
89 }
90
91 check_cygwinscip-shell shell shell-project 0.0.0 check_cygwin().
92 case $? in
93 0)
94 CYGWINENV=no
95 ;;
96 1)
97 CYGWINENV=yes
98 # There is native find.exe in Windows but it is incompatible
99 # with Unix's one. So make sure Cygwin's find.exe is used.
100 PATH=/usr/bin:/bin:$PATH
101 ;;
102 *)
103 echoscip-shell system . . echo. Environment check failed
104 exit 255
105 ;;
106 esac
107
108 while getopts "b:hvs:" OPTION
109 do
110 case ${OPTION} in
111 b)
112 BASEDIR=${OPTARG}
113 ;;
114 h)
115 usagescip-shell shell shell-project 0.0.0 usage().
116 ;;
117 v)
118 OUTPUT=/dev/stdoutscip-shell filesystem . . `/dev/stdout`.
119 ;;
120 s)
121 SUFFIX=${OPTARG}
122 ;;
123 *)
124 usagescip-shell shell shell-project 0.0.0 usage().
125 ;;
126 esac
127 done
128 shift `exprscip-shell system . . expr. $OPTIND - 1`
129 TGTDIR=${1:-${BASEDIR}}
130
131 trap cleanup_trap 1 2 3 9 15
132
133 # create and check lock
134 if ${MKDIR} "${LOCK}" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 ; then
135 truescip-shell system . . true.
136 else
137 echoscip-shell system . . echo. "${LOCK} exists"
138 exit 5
139 fi
140
141 # Directory exist?
142 if [scip-shell system . . `[`. ! -d "${TGTDIR}" ]; then
143 cleanup_exitscip-shell shell shell-project 0.0.0 cleanup_exit(). "${TGTDIR} not found"
144 fi
145
146 if [scip-shell system . . `[`. -d "${BASEDIR}/${INDEXDIR}" ]; then
147 echoscip-shell system . . echo. "Replicating index..."
148 clean_up_replicascip-shell shell shell-project 0.0.0 clean_up_replica().
149 cpscip-shell system . . cp. -R "${BASEDIR}/${INDEXDIR}" "${BASEDIR}/${INDEXDIR_REPLICA}"
150 INDEXDIR=${INDEXDIR_REPLICA}
151 echoscip-shell system . . echo. "Replicating index...done"
152 echoscip-shell system . . echo. "Purging old messages..."
153 ${ESTCMD} purge "`path_convscip-shell shell shell-project 0.0.0 path_conv(). \"${BASEDIR}/${INDEXDIR}\"`" "`path_convscip-shell shell shell-project 0.0.0 path_conv(). \"${TGTDIR}\"`" > ${OUTPUT} ||\
154 cleanup_exit "Purging old messages...failed"
155 echoscip-shell system . . echo. "Purging old messages...done"
156 fi
157
158 echoscip-shell system . . echo. "Indexing new messages..."
159 # "find"'s regular expression is NOT portable, sigh...
160 # "[0-9]*" matches both "123" and "234.mew".
161
162 ${FIND} "`path_convscip-shell shell shell-project 0.0.0 path_conv(). \"${TGTDIR}\"`" \
163 -type d -name "trash" -prune -o \
164 -type d -name ${INDEXDIR_ORG} -prune -o \
165 -type d -name ${INDEXDIR_REPLICA} -prune -o \
166 -type f \( -name "[0-9]" -o -name "[0-9]*[0-9]" -o -name "[0-9]*${SUFFIX}" \) -print |\
167 ${ESTCMD} gather -cl -fm -cm -sd -xh "`path_convscip-shell shell shell-project 0.0.0 path_conv(). \"${BASEDIR}/${INDEXDIR}\"`" - > ${OUTPUT} ||\
168 cleanup_exit "Indexing new messages...failed"
169
170 echoscip-shell system . . echo. "Indexing new messages...done"
171 if [scip-shell system . . `[`. "${BASEDIR}/${INDEXDIR}" = "${BASEDIR}/${INDEXDIR_REPLICA}" ]; then
172 echoscip-shell system . . echo. "Replacing old index with new one..."
173 rmscip-shell system . . rm. -fr "${BASEDIR}/${INDEXDIR_ORG}"
174 mvscip-shell system . . mv. "${BASEDIR}/${INDEXDIR_REPLICA}" "${BASEDIR}/${INDEXDIR_ORG}"
175 echoscip-shell system . . echo. "Replacing old index with new one...done"
176 fi
177
178 cleanupscip-shell shell shell-project 0.0.0 cleanup().
179 exit 0
180
181 # Copyright (C) 2006-2007 Mew developing team.
182 # All rights reserved.
183 #
184 # Redistribution and use in source and binary forms, with or without
185 # modification, are permitted provided that the following conditions
186 # are met:
187 #
188 # 1. Redistributions of source code must retain the above copyright
189 # notice, this list of conditions and the following disclaimer.
190 # 2. Redistributions in binary form must reproduce the above copyright
191 # notice, this list of conditions and the following disclaimer in the
192 # documentation and/or other materials provided with the distribution.
193 # 3. Neither the name of the team nor the names of its contributors
194 # may be used to endorse or promote products derived from this software
195 # without specific prior written permission.
196 #
197 # THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
198 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
200 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
201 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
202 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
203 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
204 # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
205 # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
206 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
207 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.