summaryrefslogtreecommitdiff
path: root/package/qmq
blob: 26672805201b71c19d39ca5fb47fb22a261ac611 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/sh -e

action=$1

shout() { echo "$0: $@" >&2; }
barf() { shout "fatal: $@"; exit 111; }
safe() { "$@" || barf "cannot $@"; }

here=`env - PATH=$PATH pwd`
mypwd=${here%package}
mypwd=${mypwd%/}
home=`head -1 ${mypwd}/conf-home`
qmaill=`grep Log ${mypwd}/conf-ids | awk -F: '{print $2}'`

QMQ_HOME=""
if [ -f ${mypwd}/conf-home ]
then
  export QMQ_HOME=`head -1 ${mypwd}/conf-home`
fi
[ -d "${QMQ_HOME}" ] || barf "s/qmail home dir '${QMQ_HOME}' not available."

QMQ_LOGS=""
if [ -f ${mypwd}/conf-log ]
then
  export QMQ_LOGS=`head -1 ${mypwd}/conf-log`
fi
[ -d "${QMQ_LOGS}" ] || barf "s/qmail log dir '${QMQ_LOGS}' not available."

SVC_DIR=""
if [ -f ${mypwd}/conf-svcdir ]
then
  export SVC_DIR=`head -1 ${mypwd}/conf-svcdir`
fi
[ -d "${SVC_DIR}" ] || barf "supervise dir '${SVC_DIR}' not available."

export QMQ_ME=`hostname`

instances=""
if [ -f ${mypwd}/conf-instances ]
then
  myinstances=`grep -v "^#" ${mypwd}/conf-instances | cut -d'#' -f1`
  shout "Setting s/qmail QMQ instances:"
  shout "-------------------------------------------------------------------"
  echo "${myinstances}"
  shout "-------------------------------------------------------------------"
else
  barf "No QMQ instances defined."
fi

if [ -f ${mypwd}/conf-qmq ]
then
  . ${mypwd}/conf-qmq 
  shout "Setting s/qmail QMQ skeleton environment:"
  safe env | grep SKELETON
else 
  barf "No QMQ environment available."
fi


if [ "X${myinstances}" != "X" ] 
then
  shout "--> Use '$0 build' to setup the instances."
  shout "--> Use '$0 conf' to deploy the instances."
  shout "--> Use '$0 all' to setup and deploy the instances."
  shout "-------------------------------------------------------------------"
  shout "Note (1): s/qmail will be installed at '${QMQ_HOME}'." 
  shout "Note (2): s/qmail-logs will be installed at '${QMQ_LOGS}/[qmail|qmtp]-INSTANCEID' ...."
  shout "Note (3): 'service' base directory is '${SVC_DIR}'."
  shout "Note (4): 'qmail-send' will be initially touched 'down' at every instance."
  shout "Note (5): Initial configuration is: 'queuelifetime=${SKELETON_QUEUELIFETIME}', concurrencyremote=${SKELETON_CONCURRENCYREMOTE}'."
  shout "Note (6): Communication from the primary qmail instance to the secondaries is based on 'QMTP'."
  shout "-------------------------------------------------------------------"
  shout "Enter 'ctl-c' to abort; otherwise '$0 $action' will continue in 10 secs."
  sleep 10
fi

if [ "X$action" = "Xbuild" -o "X$action" = "Xall" ] 
then
  safe cp ${mypwd}/conf-home ${mypwd}/conf-home.org

  for mapping in ${myinstances}
  do
     instance=${mapping%%:*}
     ipaddress=$(echo ${mapping} | cut -d':' -f3)
     [ "X${ipaddress}" = "X" ] && ipaddress=0

     QMQ_INST="${QMQ_HOME%/*}/qmail-${instance}"
     shout "Setting up QMQ instance: ${QMQ_INST} (IP: $ipaddress)"

     safe mkdir -p ${QMQ_INST}
     safe mkdir -p ${QMQ_LOGS}/qmail-${instance} 
     safe chown $qmaill ${QMQ_LOGS}/qmail-${instance} 
     safe mkdir -p ${QMQ_LOGS}/qmtp-${instance} 
     safe chown $qmaill ${QMQ_LOGS}/qmtp-${instance} 

     safe cd ${mypwd}/compile
     safe echo "${QMQ_INST}" > ${mypwd}/conf-home
     safe make
     safe ./install
     safe echo "${SKELETON_ME}" > ${QMQ_INST}/control/me
     safe echo "${SKELETON_CONCURRENCYREMOTE}" > ${QMQ_INST}/control/concurrencyremote
     safe echo "#!@:localhost;bounceport -- typically 1090" > ${QMQ_INST}/control/qmtproutes
     [ "${ipaddress}" != "0" ]  && safe echo "*:${ipaddress}" > ${QMQ_INST}/control/domainips
  done

  safe mv ${mypwd}/conf-home.org ${mypwd}/conf-home

  shout "All s/qmail QMQ instances build."
fi

if [ "X$action" = "Xconf" -o "X$action" = "Xall" ] 
then
  for mapping in ${myinstances}
  do
     instance=${mapping%%:*}
     ipaddress=$(echo ${mapping} | cut -d':' -f3)
     [ "X${ipaddress}" = "X" ] && ipaddress=0

     QMQ_INST="${QMQ_HOME%/*}/qmail-${instance}"
     shout "Configurating initially QMQ instance: ${QMQ_INST} (IP address: $ipaddress)"

     port=$((${SKELETON_PORT}+${instance}))
     shout "Selecting port ${port} for instance ${instance} ..."
#
## qmail-send/qmail-start
#
     safe mkdir -p ${QMQ_INST}/svc/qmail-${instance}/log
     safe cp ${mypwd}/service/run_log ${QMQ_INST}/svc/qmail-${instance}/log/run 
     safe chmod +x ${QMQ_INST}/svc/qmail-${instance}/log/run

     safe eval sed -e 's!/var/qmail!${QMQ_INST}!g' \
                    ${mypwd}/service/run_send \
                    > ${QMQ_INST}/svc/qmail-${instance}/run
     safe chmod +x ${QMQ_INST}/svc/qmail-${instance}/run
     safe touch ${QMQ_INST}/svc/qmail-${instance}/down
#
## qmail-qmtpd
#
     safe mkdir -p ${QMQ_INST}/svc/qmtp-${instance}/log
     safe cp ${mypwd}/service/run_log ${QMQ_INST}/svc/qmtp-${instance}/log/run 
     safe chmod +x ${QMQ_INST}/svc/qmtp-${instance}/log/run

     safe eval sed -e 's!/var/qmail!${QMQ_INST}!g' \
                   -e 's!0\ qmtp!$ipaddress\ $port!g' \
                    ${mypwd}/service/run_qmtpd \
                    > ${QMQ_INST}/svc/qmtp-${instance}/run
     safe chmod +x ${QMQ_INST}/svc/qmtp-${instance}/run
     safe touch ${QMQ_INST}/svc/qmtp-${instance}/down

#
## link to /svc
# 
#     safe ln -s ${QMQ_INST}/svc/qmtp-${instance} ${SVC_DIR}/qmail-${instance}-qmtpd
#     safe ln -s ${QMQ_INST}/svc/qmail-${instance} ${SVC_DIR}/qmail-${instance}-send
  done

  shout "All QMQ instances configured, available unter ${SVC_DIR} but toched 'down'."
else
  barf "Please provide either 'build' and 'conf' for individual actions; or 'all' for all-inclusive."
fi

exit 0