source: trunk/third/moira/gen/postoffice.sh @ 24319

Revision 24319, 2.2 KB checked in by broder, 14 years ago (diff)
New Moira snapshot from SVN.
Line 
1#!/bin/sh
2# This script performs postoffice updates.
3#
4# $HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/gen/postoffice.sh $ $Id: postoffice.sh 3956 2010-01-05 20:56:56Z zacheiss $
5
6PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin
7export PATH
8
9if [ -d /var/athena ] && [ -w /var/athena ]; then
10    exec >/var/athena/moira_update.log 2>&1
11else
12    exec >/tmp/moira_update.log 2>&1
13fi
14
15# The following exit codes are defined and MUST BE CONSISTENT with the
16# error codes the library uses:
17MR_NOCRED=47836470
18MR_MISSINGFILE=47836473
19MR_MKCRED=47836474
20MR_TARERR=47836476
21
22umask 22
23
24TARFILE=/var/tmp/po.out
25SRC_DIR=/var/tmp/po.dir
26IMAP_ROOT=/usr/local/cyrus
27IMAP_CONFIG=${IMAP_ROOT}/config
28IMAP_CHECK=${IMAP_CONFIG}/ignore_update_checks
29IMAP_MBOXES=${IMAP_CONFIG}/mailboxes.input;
30IMAP_QUOTA=${IMAP_CONFIG}/quota
31IMAP_QINPUT=${IMAP_QUOTA}/input
32IMAP_BIN=${IMAP_ROOT}/bin
33
34
35#
36# handle tar file
37#
38
39if [ ! -r ${TARFILE} ]; then
40        exit ${MR_TARERR}
41fi
42
43rm -rf ${SRC_DIR}
44mkdir ${SRC_DIR}
45chmod 700 ${SRC_DIR}
46
47uchost=`hostname | tr '[a-z]' '[A-Z]'`
48echo $uchost | egrep -e "\." > /dev/null
49if [ $? != 0 ]; then
50        domain=`grep domain /etc/resolv.conf | awk '{print $2}' |tr '[a-z]' '[A-Z]'`
51
52        uchost=$uchost.$domain
53fi
54
55cd ${SRC_DIR}
56tar xvf ${TARFILE}
57if [ $? != 0 ]; then
58        exit ${MR_TARERR}
59fi
60
61if [ ! -d $uchost ]; then
62        echo "no directory for "$uchost
63        exit ${MR_MISSINGFILE}
64fi
65
66cd $uchost
67
68
69#
70# handle mboxes file
71#
72
73cp mailboxes ${IMAP_MBOXES}
74if [ $? != 0 ]; then
75        echo "failed to copy mailboxes"
76        exit ${MR_NOCRED}
77fi
78
79sort -o ${IMAP_MBOXES} ${IMAP_MBOXES}
80
81
82#
83# handle quotas
84#
85
86rm -f ${IMAP_QINPUT}
87cp quota ${IMAP_QINPUT}
88if [ $? != 0 ]; then
89        echo "failed to copy quota"
90        exit ${MR_NOCRED}
91fi
92
93
94#
95# save
96#
97cp ${IMAP_CONFIG}/mailboxes ${IMAP_CONFIG}/mailboxes.save
98
99#
100# synchronize
101#
102LD_LIBRARY_PATH=/usr/local/tcl/lib
103export LD_LIBRARY_PATH
104
105${IMAP_BIN}/sync.pl
106if [ $? != 0 ]; then
107        exit ${MR_MKCRED}
108fi
109
110#
111# backup
112#
113cp ${IMAP_CONFIG}/mailboxes ${IMAP_CONFIG}/mailboxes.backup
114
115#
116# cleanup
117#
118
119if [ -f ${TARFILE} ]; then
120         rm -f ${TARFILE}
121fi
122
123if [ -d ${SRC_DIR} ]; then
124        cd ${SRC_DIR}/..
125        rm -rf ${SRC_DIR}
126fi
127
128if [ -f $0 ]; then
129         rm -f $0
130fi
131
132exit 0
Note: See TracBrowser for help on using the repository browser.