]> andersk Git - moira.git/blame - gen/postoffice.sh
syslog instead of spewing to stdout.
[moira.git] / gen / postoffice.sh
CommitLineData
6b3a8ea3 1#!/bin/sh
2# This script performs postoffice updates.
3#
4# $Header$
5
6PATH=/sbin:/bin:/usr/sbin:/usr/bin:/etc:/usr/etc:/usr/athena/bin:/usr/local/bin
7export PATH
8
9# The following exit codes are defined and MUST BE CONSISTENT with the
10# error codes the library uses:
11MR_NOCRED=47836470
12MR_MISSINGFILE=47836473
13MR_MKCRED=47836474
14MR_TARERR=47836476
15
16umask 22
17
18TARFILE=/var/tmp/po.out
19SRC_DIR=/var/tmp/po.dir
20IMAP_ROOT=/usr/local/cyrus
21IMAP_CONFIG=${IMAP_ROOT}/config
22IMAP_CHECK=${IMAP_CONFIG}/ignore_update_checks
23IMAP_MBOXES=${IMAP_CONFIG}/mailboxes.input;
24IMAP_QUOTA=${IMAP_CONFIG}/quota
25IMAP_QINPUT=${IMAP_QUOTA}/input
26IMAP_BIN=${IMAP_ROOT}/bin
27
28
29#
30# handle tar file
31#
32
33if [ ! -r ${TARFILE} ]; then
34 exit ${MR_TARERR}
35fi
36
37rm -rf ${SRC_DIR}
38mkdir ${SRC_DIR}
39chmod 700 ${SRC_DIR}
40
41uchost=`hostname | tr '[a-z]' '[A-Z]'`
42echo $uchost | egrep -e "." > /dev/null
43if [ $? != 0 ]; then
44 domain=`grep domain /etc/resolv.conf | awk '{print $2}' |tr '[a-z]' '[A-Z]'`
45
46 uchost=$uchost.$domain
47fi
48
49cd ${SRC_DIR}
50tar xvf ${TARFILE}
51if [ $? != 0 ]; then
52 exit ${MR_TARERR}
53fi
54
55if [ ! -d $uchost ]; then
56 echo "no directory for "$uchost
57 exit ${MR_MISSINGFILE}
58fi
59
60cd $uchost
61
62
63#
64# handle mboxes file
65#
66
67cp mailboxes ${IMAP_MBOXES}
68if [ $? != 0 ]; then
69 echo "failed to copy mailboxes"
70 exit ${MR_NOCRED}
71fi
72
73if [ -r {$IMAP_MBOXES} ]; then
74 egrep "\..*\." ${IMAP_CONFIG}/mailboxes >> ${IMAP_MBOXES}
75fi
76
77sort -o ${IMAP_MBOXES} ${IMAP_MBOXES}
78
79
80#
81# handle quotas
82#
83
84rm -f ${IMAP_QINPUT}
85cp quota ${IMAP_QINPUT}
86if [ $? != 0 ]; then
87 echo "failed to copy quota"
88 exit ${MR_NOCRED}
89fi
90
91
92#
93# save
94#
95cp ${IMAP_CONFIG}/mailboxes ${IMAP_CONFIG}/mailboxes.save
96
97#
98# synchronize
99#
100LD_LIBRARY_PATH=/usr/local/tcl/lib
101export LD_LIBRARY_PATH
999b5f22 102
103${IMAP_BIN}/cyradm -file ${IMAP_BIN}/sync.cyradm sync -d
6b3a8ea3 104if [ $? != 0 ]; then
105 exit ${MR_MKCRED}
106fi
107
108#
109# backup
110#
111cp ${IMAP_CONFIG}/mailboxes ${IMAP_CONFIG}/mailboxes.backup
112
113#
114# cleanup
115#
116
117if [ -f ${TARFILE} ]; then
118 rm -f ${TARFILE}
119fi
120
121if [ -d ${SRC_DIR} ]; then
122 cd ${SRC_DIR}/..
123 rm -rf ${SRC_DIR}
124fi
125
126if [ -f $0 ]; then
127 rm -f $0
128fi
129
130exit 0
This page took 0.067829 seconds and 5 git commands to generate.