You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

309 lines
13 KiB

  1. #
  2. # Copyright (C) 2014-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. PKG_NAME:=postfix
  9. PKG_RELEASE:=3
  10. PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
  11. PKG_VERSION:=3.2.2
  12. PKG_HASH:=d06849418d119d09366997b2b481bb23f737629769b4e4a52da42fb3ad8b0576
  13. PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
  14. PKG_MAINTAINER:=Denis Shulyaka <Shulyaka@gmail.com>
  15. PKG_LICENSE:=IPL-1.0
  16. PKG_LICENSE_FILES:=LICENSE
  17. PKG_BUILD_DEPENDS:=+POSTFIX_CDB:tinycdb
  18. PKG_CONFIG_DEPENDS:= \
  19. CONFIG_POSTFIX_TLS \
  20. CONFIG_POSTFIX_SASL \
  21. CONFIG_POSTFIX_LDAP \
  22. CONFIG_POSTFIX_CDB \
  23. CONFIG_POSTFIX_DB \
  24. CONFIG_POSTFIX_SQLITE \
  25. CONFIG_POSTFIX_PGSQL \
  26. CONFIG_POSTFIX_PCRE \
  27. CONFIG_POSTFIX_EAI \
  28. include $(INCLUDE_DIR)/package.mk
  29. define Package/postfix
  30. SECTION:=mail
  31. CATEGORY:=Mail
  32. TITLE:=Postfix Mail Transmit Agent
  33. URL:=http://www.postfix.org/
  34. DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +POSTFIX_SQLITE:libsqlite3 +POSTFIX_PGSQL:libpq +POSTFIX_EAI:icu +POSTFIX_PCRE:libpcre
  35. endef
  36. define Package/postfix/description
  37. 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.
  38. endef
  39. define Package/postfix/config
  40. menu "Select postfix build options"
  41. config POSTFIX_TLS
  42. bool "TLS support"
  43. default y
  44. help
  45. Implements TLS support in postfix (using OpenSSL).
  46. config POSTFIX_SASL
  47. bool "SASL support"
  48. default y
  49. help
  50. Implements SASL support in postfix (using Cyrus SASL).
  51. config POSTFIX_LDAP
  52. bool "LDAP support"
  53. default y
  54. help
  55. Implements LDAP support in postfix (using OpenLDAP).
  56. config POSTFIX_DB
  57. bool "BerkeleyDB support"
  58. default n
  59. help
  60. Implements support for btree files using Berkeley DB. Note that hash files support is not compiled into Berkeley DB OpenWRT distribution
  61. config POSTFIX_CDB
  62. bool "CDB support"
  63. default y
  64. help
  65. Implements support for cdb files using tinycdb
  66. config POSTFIX_SQLITE
  67. bool "SQLITE support"
  68. default y
  69. help
  70. Implements support for SQLite3 DB
  71. config POSTFIX_PGSQL
  72. bool "PostgreSQL support"
  73. default n
  74. help
  75. Implement support for PostgreSQL
  76. config POSTFIX_PCRE
  77. bool "PCRE support"
  78. default n
  79. help
  80. Implement support for Perl Compatible Regular Expressions
  81. config POSTFIX_EAI
  82. bool "SMTPUTF8 support"
  83. default n
  84. help
  85. Enable Postfix support for Email Address Internationalization
  86. (EAI) as defined in RFC 6531 (SMTPUTF8 extension), RFC 6532
  87. (Internationalized email headers) and RFC 6533
  88. (Internationalized delivery status notifications).
  89. Since version 3.0, Postfix fully supports UTF-8 email
  90. addresses and UTF-8 message header values.
  91. endmenu
  92. endef
  93. CCARGS=-DNO_NIS
  94. AUXLIBS=-L$(STAGING_DIR)/usr/lib
  95. default_database_type=cdb
  96. ifdef CONFIG_POSTFIX_TLS
  97. CCARGS+=-DUSE_TLS
  98. AUXLIBS+=-lssl -lcrypto
  99. endif
  100. ifdef CONFIG_POSTFIX_SASL
  101. CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
  102. AUXLIBS+=-lsasl2
  103. endif
  104. ifdef CONFIG_POSTFIX_LDAP
  105. CCARGS+=-DHAS_LDAP
  106. AUXLIBS+=-lldap -llber
  107. endif
  108. ifdef CONFIG_POSTFIX_CDB
  109. CCARGS+=-DHAS_CDB
  110. AUXLIBS+=-lcdb
  111. endif
  112. ifdef CONFIG_POSTFIX_DB
  113. AUXLIBS+=-ldb
  114. CCARGS+=-DHAS_DB
  115. ifndef CONFIG_POSTFIX_CDB
  116. default_database_type=btree
  117. endif
  118. else
  119. CCARGS+=-DNO_DB
  120. endif
  121. ifdef CONFIG_POSTFIX_SQLITE
  122. CCARGS+=-DHAS_SQLITE -I$(STAGING_DIR)/usr/include/
  123. AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lsqlite3 -lpthread
  124. endif
  125. ifdef CONFIG_POSTFIX_PGSQL
  126. CCARGS+=-DHAS_PGSQL -I$(STAGING_DIR)/usr/include/
  127. AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lpq
  128. endif
  129. ifdef CONFIG_POSTFIX_PCRE
  130. CCARGS+=-DHAS_PCRE -I$(STAGING_DIR)/usr/include/
  131. AUXLIBS+=-L$(STAGING_DIR)/usr/lib -lpcre
  132. else
  133. CCARGS+=-DNO_PCRE
  134. endif
  135. ifdef CONFIG_POSTFIX_EAI
  136. AUXLIBS+=-licuuc
  137. CCARGS+=-DHAS_EAI
  138. smtputf8_conf = yes
  139. else
  140. CCARGS+=-DNO_EAI
  141. smtputf8_conf = no
  142. endif
  143. CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
  144. config_directory=/etc/postfix# also add this to postfix init file
  145. sample_directory=/etc/postfix
  146. command_directory=/usr/sbin
  147. daemon_directory=/usr/libexec/postfix
  148. data_directory=/usr/var/lib/postfix
  149. queue_directory=/usr/var/spool/postfix
  150. mail_spool_directory=/usr/var/mail
  151. html_directory=no
  152. manpage_directory=no
  153. readme_directory=no
  154. sendmail_path=/usr/sbin/sendmail
  155. newaliases_path=/usr/bin/newaliases
  156. mailq_path=/usr/bin/mailq
  157. shlib_directory=/usr/lib/postfix
  158. meta_directory=/etc/postfix
  159. ln_suffix=.postfix
  160. ln_old_suffix=.old
  161. define Package/postfix/conffiles
  162. $(config_directory)/main.cf
  163. $(config_directory)/master.cf
  164. $(config_directory)/aliases
  165. $(config_directory)/virtual
  166. endef
  167. define Build/Configure
  168. if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
  169. echo "Build error: You must select at least one of the DB types";\
  170. exit 1;\
  171. fi
  172. cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
  173. endef
  174. # Steps to regenerate files/main.cf.default:
  175. #
  176. # 1. Compile the package with current file
  177. # 2. Execute the following command on target device:
  178. # postconf -d > /tmp/main.cf.new
  179. # 3. Transfer /tmp/main.cf.new file to the build system
  180. # 4. Execute the following command:
  181. # cat /tmp/main.cf.new | ( echo '# DO NOT EDIT THIS FILE. EDIT THE MAIN.CF FILE INSTEAD. THE'; echo '# TEXT HERE JUST SHOWS DEFAULT SETTINGS BUILT INTO POSTFIX.'; echo '#'; grep -v ^alias_maps\ = |grep -v ^alias_database\ = |grep -v ^command_directory\ = |grep -v ^config_directory\ = |grep -v ^daemon_directory\ = |grep -v ^data_directory\ = |grep -v ^default_database_type\ = |grep -v ^html_directory\ = |grep -v ^mail_spool_directory\ = |grep -v ^mailq_path\ = |grep -v ^manpage_directory\ = |grep -v ^meta_directory\ = |grep -v ^mydomain\ = |grep -v ^myhostname\ = |grep -v ^mynetworks\ = |grep -v ^mynetworks_style\ = |grep -v ^newaliases_path\ = |grep -v ^queue_directory\ = |grep -v ^readme_directory\ = |grep -v ^sample_directory\ = |grep -v ^sendmail_path\ = |grep -v ^shlib_directory\ = |grep -v ^smtputf8_enable\ = |grep -v ^virtual_maps\ = |grep -v ^process_id\ = ) > files/main.cf.default
  182. # 5. Done. Now you can rebuild the package with new main.cf.default.
  183. #
  184. define Build/Compile
  185. # Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC as a workaround
  186. cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
  187. cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
  188. echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  189. echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  190. echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  191. echo "virtual_maps = $(default_database_type):$(config_directory)/virtual" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  192. echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  193. echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  194. echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  195. echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  196. echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  197. echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  198. echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  199. echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  200. echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  201. echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  202. echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  203. echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  204. echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  205. echo "shlib_directory = $(shlib_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  206. echo "meta_directory = $(meta_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  207. echo "smtputf8_enable = $(smtputf8_conf)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  208. endef
  209. define Package/postfix/install
  210. 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) shlib_directory=$(shlib_directory) meta_directory=$(meta_directory) mail_version=$(PKG_VERSION) non-interactive-package
  211. $(INSTALL_DIR) $(1)$(mail_spool_directory)
  212. $(INSTALL_DIR) $(1)/etc/init.d/
  213. $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
  214. endef
  215. define Package/postfix/postinst
  216. #!/bin/sh
  217. if [ -f "$${IPKG_INSTROOT}$(sendmail_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
  218. mv "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
  219. echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) saved as $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
  220. fi
  221. if [ ! -f "$${IPKG_INSTROOT}$(sendmail_path)" ]; then
  222. ln -s "$(sendmail_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
  223. fi
  224. if [ -f "$${IPKG_INSTROOT}$(newaliases_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
  225. mv "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
  226. echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) saved as $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
  227. fi
  228. if [ ! -f "$${IPKG_INSTROOT}$(newaliases_path)" ]; then
  229. ln -s "$(newaliases_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
  230. fi
  231. if [ -f "$${IPKG_INSTROOT}$(mailq_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
  232. mv "$${IPKG_INSTROOT}$(mailq_path)" "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
  233. echo "Warning: $${IPKG_INSTROOT}$(mailq_path) saved as $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
  234. fi
  235. if [ ! -f "$(mailq_path)" ]; then
  236. ln -s "$(mailq_path)$(ln_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
  237. fi
  238. grep -qc main\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  239. grep -qc master\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  240. grep -qc aliases "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  241. grep -qc virtual "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/virtual" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  242. touch "$${IPKG_INSTROOT}$(config_directory)"/opkg_postinst
  243. if [ -z "$${IPKG_INSTROOT}" ]; then
  244. ps | grep "postfix/master" | grep -cvq grep >/dev/null && /etc/init.d/postfix restart
  245. fi
  246. endef
  247. define Package/postfix/prerm
  248. #!/bin/sh
  249. ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
  250. /etc/init.d/postfix disable
  251. endef
  252. define Package/postfix/postrm
  253. #!/bin/sh
  254. rm -f $${IPKG_INSTROOT}$(config_directory)/aliases.cdb $${IPKG_INSTROOT}$(config_directory)/aliases.db $${IPKG_INSTROOT}$(data_directory)/master.lock
  255. rm -f $${IPKG_INSTROOT}$(config_directory)/virtual.cdb $${IPKG_INSTROOT}$(config_directory)/virtual.db
  256. rm -f "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(mailq_path)"
  257. if [ -f "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" ]; then
  258. mv "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
  259. echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) restored from $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
  260. fi
  261. if [ -f "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" ]; then
  262. mv "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
  263. echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) restored from $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
  264. fi
  265. if [ -f "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" ]; then
  266. mv "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
  267. echo "Warning: $${IPKG_INSTROOT}$(mailq_path) restored from $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
  268. fi
  269. endef
  270. $(eval $(call BuildPackage,postfix))