aboutsummaryrefslogtreecommitdiff
path: root/mail/postfix/Makefile
blob: 213d8d65f1e0ff90e33541cbac4fc08fc72796c5 (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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# 
# Copyright (C) 2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=postfix
PKG_RELEASE:=1
PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
PKG_VERSION:=2.11.1
PKG_MD5SUM:=56ac1f1a79737c4ac1e24535a122a4a6
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_MAINTAINER:=Denis Shulyaka <Shulyaka@gmail.com>
PKG_LICENSE:=IPL-1.0
PKG_LICENSE_FILE:=LICENSE
PKG_BUILD_DEPENDS:=+tinycdb

include $(INCLUDE_DIR)/package.mk

define Package/postfix
  SECTION:=mail
  CATEGORY:=Mail
  TITLE:=Postfix Mail Transmit Agent
  URL:=http://www.postfix.org/
  DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +libpcre
endef

define Package/postfix/description
 Postfix is Wietse Venema's mailer that started life as an alternative to the widely-used Sendmail program. Postfix attempts to be fast, easy to administer, and secure, while at the same time being sendmail compatible enough to not upset existing users. Thus, the outside has a sendmail-ish flavor, but the inside is completely different.
endef

define Package/postfix/config
	menu "Select postfix build options"
		config POSTFIX_TLS
			bool "TLS support"
			default y
			help
			  Implements TLS support in postfix (using OpenSSL).
		config POSTFIX_SASL
			bool "SASL support"
			default y
			help
			  Implements SASL support in postfix (using Cyrus SASL).
		config POSTFIX_LDAP
			bool "LDAP support"
			default y
			help
			  Implements LDAP support in postfix (using OpenLDAP).
	endmenu
endef

define Package/postfix/conffiles
/etc/postfix/main.cf
/etc/postfix/master.cf
/etc/postfix/aliases
endef

CCARGS=-DHAS_CDB -DNO_DB -DNO_EPOLL -DNO_SIGSETJMP -DNO_NIS -DDEF_DB_TYPE=\"cdb\"
AUXLIBS=-L$(STAGING_DIR)/usr/lib -lcdb

ifdef CONFIG_POSTFIX_TLS
  CCARGS+=-DUSE_TLS
  AUXLIBS+=-lssl -lcrypto
endif

ifdef CONFIG_POSTFIX_SASL
  CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
  AUXLIBS+=-lsasl2
endif

ifdef CONFIG_POSTFIX_LDAP
  CCARGS+=-DHAS_LDAP
  AUXLIBS+=-lldap -llber
endif

config_directory=/etc/postfix
sample_directory=/etc/postfix
command_directory=/usr/sbin
daemon_directory=/usr/libexec/postfix
data_directory=/usr/var/lib/postfix
queue_directory=/usr/var/spool/postfix
mail_spool_directory=/usr/var/mail
html_directory=no
manpage_directory=no
readme_directory=no
sendmail_path=/usr/sbin/sendmail
newaliases_path=/usr/bin/newaliases
mailq_path=/usr/bin/mailq

ln_suffix=.postfix
ln_old_suffix=.old

define Build/Configure
	cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
endef

define Build/Compile
	# Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC
	cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
	mv $(PKG_BUILD_DIR)/conf/main.cf.default.openwrt $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
	echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
endef

define Package/postfix/install
	cd $(PKG_BUILD_DIR); $(MAKE) install_root=$(1) command_directory=$(command_directory) daemon_directory=$(daemon_directory) data_directory=$(data_directory) html_directory=$(html_directory) mail_owner=postfix mailq_path=$(mailq_path)$(ln_suffix) manpage_directory=$(manpage_directory) newaliases_path=$(newaliases_path)$(ln_suffix) queue_directory=$(queue_directory) readme_directory=$(readme_directory) sendmail_path=$(sendmail_path)$(ln_suffix) setgid_group=postdrop sample_directory=$(sample_directory) config_directory=$(config_directory) non-interactive-package
	$(INSTALL_DIR) $(1)$(mail_spool_directory)
	$(INSTALL_DIR) $(1)/etc/init.d/
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/postfix_init $(1)/etc/init.d/postfix
endef

define Package/postfix/postinst
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then

 if [ -f "$(sendmail_path)" -a "$$(readlink "$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
  mv "$(sendmail_path)" "$(sendmail_path)$(ln_old_suffix)"
  echo "Warning: $(sendmail_path) saved as $(sendmail_path)$(ln_old_suffix)"
 fi
 if [ ! -f "$(sendmail_path)" ]; then
  ln -s "$(sendmail_path)$(ln_suffix)" "$(sendmail_path)"
 fi

 if [ -f "$(newaliases_path)" -a "$$(readlink "$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
  mv "$(newaliases_path)" "$(newaliases_path)$(ln_old_suffix)"
  echo "Warning: $(newaliases_path) saved as $(newaliases_path)$(ln_old_suffix)"
 fi
 if [ ! -f "$(newaliases_path)" ]; then
  ln -s "$(newaliases_path)$(ln_suffix)" "$(newaliases_path)"
 fi

 if [ -f "$(mailq_path)" -a "$$(readlink "$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
  mv "$(mailq_path)" "$(mailq_path)$(ln_old_suffix)"
  echo "Warning: $(mailq_path) saved as $(mailq_path)$(ln_old_suffix)"
 fi
 if [ ! -f "$(mailq_path)" ]; then
  ln -s "$(mailq_path)$(ln_suffix)" "$(mailq_path)"
 fi

 echo "myhostname = $$(uci get system.@system[0].hostname)" >> $(config_directory)/main.cf.default
 echo "mydomain = $$(uci get system.@system[0].hostname|sed -e "s/[^\.]*\.\(.*\)/\1/")" >> $(config_directory)/main.cf.default
 for net in $$(uci show network|grep ipaddr|sed -e "s/network\.\([^\.]*\).*/\1/"); do eval "$$(ipcalc.sh $$(uci get network.$$net.ipaddr) $$(uci get network.$$net.netmask))"; echo "$$IP/$$PREFIX"; done | xargs echo "mynetworks =" >> $(config_directory)/main.cf.default

 grep -qc "^sendmail_path" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^sendmail_path =" /etc/postfix/main.cf.default)"
 grep -qc "^newaliases_path" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^newaliases_path =" /etc/postfix/main.cf.default)"
 grep -qc "^mailq_path" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mailq_path =" /etc/postfix/main.cf.default)"
 grep -qc "^html_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^html_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^manpage_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^manpage_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^sample_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^sample_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^readme_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^readme_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^command_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^command_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^daemon_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^daemon_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^data_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^data_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^queue_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^queue_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^config_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^config_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^mail_spool_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mail_spool_directory =" /etc/postfix/main.cf.default)"
 grep -qc "^mail_owner" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mail_owner =" /etc/postfix/main.cf.default)"
 grep -qc "^setgid_group" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^setgid_group =" /etc/postfix/main.cf.default)"
 grep -qc "^myhostname" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^myhostname =" /etc/postfix/main.cf.default)"
 grep -qc "^mydomain" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mydomain =" /etc/postfix/main.cf.default)"
 grep -qc "^mynetworks" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mynetworks =" /etc/postfix/main.cf.default)"

 EXTRA_COMMANDS=create_users /etc/init.d/postfix create_users

 postfix set-permissions
 postfix post-install upgrade-source
 postfix upgrade-configuration
 newaliases
 if [ `ps | grep "postfix/master" | grep -cv grep` -gt 0 ]
 then
  postfix reload
 fi
 if [ `grep -c aliases /etc/sysupgrade.conf` -eq 0 ]
 then
  echo "$(config_directory)/main.cf" >> /etc/sysupgrade.conf
  echo "$(config_directory)/aliases" >> /etc/sysupgrade.conf
 fi

fi
endef

define Package/postfix/prerm
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then

 if [ `ps | grep "postfix/master" | grep -cv grep` -gt 0 ]
 then
  postfix stop
 fi

 /etc/init.d/postfix disable

fi
endef

define Package/postfix/postrm
#!/bin/sh
# check if we are on real system
if [ -z "$${IPKG_INSTROOT}" ]; then
 rm -f $(config_directory)/aliases.cdb $(data_directory)/master.lock

 rm -f "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"

 if [ -f "$(sendmail_path)$(ln_old_suffix)" ]; then
  mv "$(sendmail_path)$(ln_old_suffix)" "$(sendmail_path)"
  echo "Warning: $(sendmail_path) restored from $(sendmail_path)$(ln_old_suffix)"
 fi
 if [ -f "$(newaliases_path)$(ln_old_suffix)" ]; then
  mv "$(newaliases_path)$(ln_old_suffix)" "$(newaliases_path)"
  echo "Warning: $(newaliases_path) restored from $(newaliases_path)$(ln_old_suffix)"
 fi
 if [ -f "$(mailq_path)$(ln_old_suffix)" ]; then
  mv "$(mailq_path)$(ln_old_suffix)" "$(mailq_path)"
  echo "Warning: $(mailq_path) restored from $(mailq_path)$(ln_old_suffix)"
 fi

fi
endef

$(eval $(call BuildPackage,postfix))