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 | |
---|
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 | sort -o ${IMAP_MBOXES} ${IMAP_MBOXES} |
---|
80 | |
---|
81 | |
---|
82 | # |
---|
83 | # handle quotas |
---|
84 | # |
---|
85 | |
---|
86 | rm -f ${IMAP_QINPUT} |
---|
87 | cp quota ${IMAP_QINPUT} |
---|
88 | if [ $? != 0 ]; then |
---|
89 | echo "failed to copy quota" |
---|
90 | exit ${MR_NOCRED} |
---|
91 | fi |
---|
92 | |
---|
93 | |
---|
94 | # |
---|
95 | # save |
---|
96 | # |
---|
97 | cp ${IMAP_CONFIG}/mailboxes ${IMAP_CONFIG}/mailboxes.save |
---|
98 | |
---|
99 | # |
---|
100 | # synchronize |
---|
101 | # |
---|
102 | LD_LIBRARY_PATH=/usr/local/tcl/lib |
---|
103 | export LD_LIBRARY_PATH |
---|
104 | |
---|
105 | ${IMAP_BIN}/sync.pl |
---|
106 | if [ $? != 0 ]; then |
---|
107 | exit ${MR_MKCRED} |
---|
108 | fi |
---|
109 | |
---|
110 | # |
---|
111 | # backup |
---|
112 | # |
---|
113 | cp ${IMAP_CONFIG}/mailboxes ${IMAP_CONFIG}/mailboxes.backup |
---|
114 | |
---|
115 | # |
---|
116 | # cleanup |
---|
117 | # |
---|
118 | |
---|
119 | if [ -f ${TARFILE} ]; then |
---|
120 | rm -f ${TARFILE} |
---|
121 | fi |
---|
122 | |
---|
123 | if [ -d ${SRC_DIR} ]; then |
---|
124 | cd ${SRC_DIR}/.. |
---|
125 | rm -rf ${SRC_DIR} |
---|
126 | fi |
---|
127 | |
---|
128 | if [ -f $0 ]; then |
---|
129 | rm -f $0 |
---|
130 | fi |
---|
131 | |
---|
132 | exit 0 |
---|