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