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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#!/bin/sh
#
# $FreeBSD$
#
# If the POSTFIX_DEFAULT_MTA environment variable is set to YES, it
# will make the port/package use defaults which makes postfix replaces
# sendmail as much as possible.
PKG_PREFIX=${PKG_PREFIX:=/usr/local}
BATCH=${BATCH:=no}
POSTFIX_DEFAULT_MTA=${POSTFIX_DEFAULT_MTA:=no}
if [ x${POSTFIX_DEFAULT_MTA} = xno ]; then
DEFAULT_REPLACE_MAILERCONF=n
else
DEFAULT_REPLACE_MAILERCONF=y
fi
if [ -x /usr/sbin/nologin ]; then
NOLOGIN=/usr/sbin/nologin
else
NOLOGIN=/sbin/nologin
fi
ask() {
local question default answer
question=$1
default=$2
if [ -z "${PACKAGE_BUILDING}" -a x${BATCH} = xno ]; then
read -p "${question} [${default}]? " answer
fi
if [ x${answer} = x ]; then
answer=${default}
fi
echo ${answer}
}
yesno() {
local question default answer
question=$1
default=$2
while :; do
answer=$(ask "${question}" "${default}")
case "${answer}" in
[Yy]*) return 0;;
[Nn]*) return 1;;
esac
echo "Please answer yes or no."
done
}
if [ x"$2" = xPRE-INSTALL ]; then
USER=postfix
UID=125
GROUP=postfix
GID=125
GROUP2=maildrop
GID2=126
if /usr/sbin/pw groupshow "${GROUP}" 2>/dev/null; then
echo "You already have a group \"${GROUP}\", so I will use it."
else
if /usr/sbin/pw groupadd ${GROUP} -g ${GID}
then
echo "Added group \"${GROUP}\"."
else
echo "Adding group \"${GROUP}\" failed..."
echo "Please create it, and try again."
exit 1
fi
fi
if /usr/sbin/pw groupshow "${GROUP2}" 2>/dev/null; then
echo "You already have a group \"${GROUP2}\", so I will use it."
else
if /usr/sbin/pw groupadd ${GROUP2} -g ${GID2}
then
echo "Added group \"${GROUP2}\"."
else
echo "Adding group \"${GROUP2}\" failed..."
echo "Please create it, and try again."
exit 1
fi
fi
if /usr/sbin/pw user show "${USER}" 2>/dev/null; then
echo "You already have a user \"${USER}\", so I will use it."
else
if /usr/sbin/pw useradd ${USER} -u ${UID} -g ${GROUP} -h - \
-d /var/spool/postfix \
-s ${NOLOGIN} \
-c "Postfix Mail System"
then
echo "Added user \"${USER}\"."
else
echo "Adding user \"${USER}\" failed..."
echo "Please create it, and try again."
exit 1
fi
fi
if /usr/sbin/pw show group mail | grep -q "${USER}" 2>/dev/null; then
echo "You already have user \"${USER}\" in group \"mail\", so I will use it."
else
echo "You need user \"${USER}\" added to group \"mail\"."
if yesno "Would you like me to add it" y; then
/usr/sbin/pw groupmod mail -m ${USER} || exit
echo "Done."
else
echo "Please create it, and try again."
exit 1
fi
fi
fi
if [ x"$2" = xPOST-INSTALL ]; then
CONF1="main.cf master.cf access aliases canonical \
header_checks relocated transport virtual"
for file in $CONF1
do
if [ ! -f ${PKG_PREFIX}/etc/postfix/$file ]; then
cp ${PKG_PREFIX}/etc/postfix/sample-$file ${PKG_PREFIX}/etc/postfix/$file
fi
done
sh ${PKG_PREFIX}/etc/postfix/post-install tempdir=/tmp \
config_directory=${PKG_PREFIX}/etc/postfix \
daemon_directory=${PKG_PREFIX}/libexec/postfix \
command_directory=${PKG_PREFIX}/sbin \
queue_directory=/var/spool/postfix \
sendmail_path=${PKG_PREFIX}/sbin/sendmail \
newaliases_path=${PKG_PREFIX}/bin/newaliases \
mailq_path=${PKG_PREFIX}/bin/mailq \
mail_owner=postfix \
setgid_group=maildrop \
manpage_directory=${PKG_PREFIX}/man \
sample_directory=${PKG_PREFIX}/etc/postfix \
readme_directory=no \
upgrade-package
# readme_directory is "no" above since the package will have correct perms
# already, and we don't know if they had PORTDOCS.
fi
replace() {
local orig repl
orig=$1
repl=$2
if [ -e ${orig} ]; then
mv -f ${orig} ${orig}.OFF
chmod 0 ${orig}.OFF
fi
if [ -e ${repl} ]; then
ln -s ${repl} ${orig}
fi
}
if [ x"$2" = xPOST-INSTALL -a -z "${PACKAGE_BUILDING}" ]; then
if [ -x /sbin/sysctl ]; then
OSVERSION=`/sbin/sysctl -n kern.osreldate`
else
OSVERSION=`/usr/sbin/sysctl -n kern.osreldate`
fi
if [ ${OSVERSION} -ge 400014 ]; then
if yesno "Would you like to activate Postfix in /etc/mail/mailer.conf" \
${DEFAULT_REPLACE_MAILERCONF}; then
mv -f /etc/mail/mailer.conf /etc/mail/mailer.conf.old
echo "#" > /etc/mail/mailer.conf
echo -n "# Execute the Postfix sendmail program" >> /etc/mail/mailer.conf
echo ", named ${PKG_PREFIX}/sbin/sendmail" >> /etc/mail/mailer.conf
echo "#" >> /etc/mail/mailer.conf
echo "sendmail ${PKG_PREFIX}/sbin/sendmail" >> /etc/mail/mailer.conf
echo "send-mail ${PKG_PREFIX}/sbin/sendmail" >> /etc/mail/mailer.conf
echo "mailq ${PKG_PREFIX}/sbin/sendmail" >> /etc/mail/mailer.conf
echo "newaliases ${PKG_PREFIX}/sbin/sendmail" >> /etc/mail/mailer.conf
fi
else
if yesno "Would you like to replace {sendmail,mailq,newaliases} with Postfix versions" n; then
replace /usr/sbin/sendmail ${PKG_PREFIX}/sbin/sendmail
replace /usr/bin/mailq ${PKG_PREFIX}/sbin/sendmail
replace /usr/bin/newaliases ${PKG_PREFIX}/sbin/sendmail
echo "Done."
fi
fi
fi
|