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.

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