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