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.

243 lines
11 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:=2
  10. PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
  11. PKG_VERSION:=3.0.1
  12. PKG_MD5SUM:=3ec1416e7d4fba9566297c8fcf7a348c
  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. include $(INCLUDE_DIR)/package.mk
  19. define Package/postfix
  20. SECTION:=mail
  21. CATEGORY:=Mail
  22. TITLE:=Postfix Mail Transmit Agent
  23. URL:=http://www.postfix.org/
  24. DEPENDS:=+POSTFIX_TLS:libopenssl +POSTFIX_SASL:libsasl2 +POSTFIX_LDAP:libopenldap +POSTFIX_DB:libdb47 +libpcre
  25. endef
  26. define Package/postfix/description
  27. 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.
  28. endef
  29. define Package/postfix/config
  30. menu "Select postfix build options"
  31. config POSTFIX_TLS
  32. bool "TLS support"
  33. default y
  34. help
  35. Implements TLS support in postfix (using OpenSSL).
  36. config POSTFIX_SASL
  37. bool "SASL support"
  38. default y
  39. help
  40. Implements SASL support in postfix (using Cyrus SASL).
  41. config POSTFIX_LDAP
  42. bool "LDAP support"
  43. default y
  44. help
  45. Implements LDAP support in postfix (using OpenLDAP).
  46. config POSTFIX_DB
  47. bool "BerkeleyDB support"
  48. default n
  49. help
  50. Implements support for btree files using Berkeley DB. Note that hash files support is not compiled into Berkeley DB OpenWRT distribution
  51. config POSTFIX_CDB
  52. bool "CDB support"
  53. default y
  54. help
  55. Implements support for cdb files using tinycdb
  56. endmenu
  57. endef
  58. CCARGS=-DNO_EPOLL -DNO_SIGSETJMP -DNO_NIS -DNO_EAI
  59. AUXLIBS=-L$(STAGING_DIR)/usr/lib
  60. default_database_type=cdb
  61. ifdef CONFIG_POSTFIX_TLS
  62. CCARGS+=-DUSE_TLS
  63. AUXLIBS+=-lssl -lcrypto
  64. endif
  65. ifdef CONFIG_POSTFIX_SASL
  66. CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
  67. AUXLIBS+=-lsasl2
  68. endif
  69. ifdef CONFIG_POSTFIX_LDAP
  70. CCARGS+=-DHAS_LDAP
  71. AUXLIBS+=-lldap -llber
  72. endif
  73. ifdef CONFIG_POSTFIX_CDB
  74. CCARGS+=-DHAS_CDB
  75. AUXLIBS+=-lcdb
  76. endif
  77. ifdef CONFIG_POSTFIX_DB
  78. AUXLIBS+=-ldb
  79. CCARGS+=-DHAS_DB
  80. ifndef CONFIG_POSTFIX_CDB
  81. default_database_type=btree
  82. endif
  83. else
  84. CCARGS+=-DNO_DB
  85. endif
  86. CCARGS+=-DDEF_DB_TYPE=\"$(default_database_type)\"
  87. config_directory=/etc/postfix# also add this to postfix init file
  88. sample_directory=/etc/postfix
  89. command_directory=/usr/sbin
  90. daemon_directory=/usr/libexec/postfix
  91. data_directory=/usr/var/lib/postfix
  92. queue_directory=/usr/var/spool/postfix
  93. mail_spool_directory=/usr/var/mail
  94. html_directory=no
  95. manpage_directory=no
  96. readme_directory=no
  97. sendmail_path=/usr/sbin/sendmail
  98. newaliases_path=/usr/bin/newaliases
  99. mailq_path=/usr/bin/mailq
  100. shlib_directory=/usr/lib/postfix
  101. meta_directory=/etc/postfix
  102. ln_suffix=.postfix
  103. ln_old_suffix=.old
  104. define Package/postfix/conffiles
  105. $(config_directory)/main.cf
  106. $(config_directory)/master.cf
  107. $(config_directory)/aliases
  108. endef
  109. define Build/Configure
  110. if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
  111. echo "Build error: You must select at least one of the DB types";\
  112. exit 1;\
  113. fi
  114. cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
  115. endef
  116. # Steps to regenerate files/main.cf.default:
  117. #
  118. # 1. Compile the package with current file
  119. # 2. Execute the following command on target device:
  120. # postconf -d > /tmp/main.cf.new
  121. # 3. Transfer /tmp/main.cf.new file to the build system
  122. # 4. Execute the following command:
  123. # 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\ = ) > files/main.cf.default
  124. # 5. Done. Now you can rebuild the package with new main.cf.default.
  125. #
  126. define Build/Compile
  127. # Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC
  128. cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
  129. cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
  130. echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  131. echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  132. echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  133. echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  134. echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  135. echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  136. echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  137. echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  138. echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  139. echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  140. echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  141. echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  142. echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  143. echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  144. echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  145. echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  146. echo "shlib_directory = $(shlib_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  147. echo "meta_directory = $(meta_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  148. echo "smtputf8_enable = no" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  149. endef
  150. define Package/postfix/install
  151. 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
  152. $(INSTALL_DIR) $(1)$(mail_spool_directory)
  153. $(INSTALL_DIR) $(1)/etc/init.d/
  154. $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
  155. endef
  156. define Package/postfix/postinst
  157. #!/bin/sh
  158. if [ -f "$${IPKG_INSTROOT}$(sendmail_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
  159. mv "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
  160. echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) saved as $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
  161. fi
  162. if [ ! -f "$${IPKG_INSTROOT}$(sendmail_path)" ]; then
  163. ln -s "$${IPKG_INSTROOT}$(sendmail_path)$(ln_suffix)" "$(sendmail_path)"
  164. fi
  165. if [ -f "$${IPKG_INSTROOT}$(newaliases_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
  166. mv "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
  167. echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) saved as $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
  168. fi
  169. if [ ! -f "$${IPKG_INSTROOT}$(newaliases_path)" ]; then
  170. ln -s "$${IPKG_INSTROOT}$(newaliases_path)$(ln_suffix)" "$(newaliases_path)"
  171. fi
  172. if [ -f "$${IPKG_INSTROOT}$(mailq_path)" -a "$$(readlink "$${IPKG_INSTROOT}$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
  173. mv "$${IPKG_INSTROOT}$(mailq_path)" "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
  174. echo "Warning: $${IPKG_INSTROOT}$(mailq_path) saved as $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
  175. fi
  176. if [ ! -f "$(mailq_path)" ]; then
  177. ln -s "$${IPKG_INSTROOT}$(mailq_path)$(ln_suffix)" "$(mailq_path)"
  178. fi
  179. grep -qc main\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  180. grep -qc master\.cf "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  181. grep -qc aliases "$${IPKG_INSTROOT}"/etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> "$${IPKG_INSTROOT}"/etc/sysupgrade.conf
  182. touch "$${IPKG_INSTROOT}$(config_directory)"/opkg_postinst
  183. if [ -z "$${IPKG_INSTROOT}" ]; then
  184. ps | grep "postfix/master" | grep -cvq grep >/dev/null && /etc/init.d/postfix reload
  185. fi
  186. endef
  187. define Package/postfix/prerm
  188. #!/bin/sh
  189. ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
  190. /etc/init.d/postfix disable
  191. endef
  192. define Package/postfix/postrm
  193. #!/bin/sh
  194. rm -f $${IPKG_INSTROOT}$(config_directory)/aliases.cdb $${IPKG_INSTROOT}$(config_directory)/aliases.db $${IPKG_INSTROOT}$(data_directory)/master.lock
  195. rm -f "$${IPKG_INSTROOT}$(sendmail_path)" "$${IPKG_INSTROOT}$(newaliases_path)" "$${IPKG_INSTROOT}$(mailq_path)"
  196. if [ -f "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" ]; then
  197. mv "$${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(sendmail_path)"
  198. echo "Warning: $${IPKG_INSTROOT}$(sendmail_path) restored from $${IPKG_INSTROOT}$(sendmail_path)$(ln_old_suffix)"
  199. fi
  200. if [ -f "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" ]; then
  201. mv "$${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(newaliases_path)"
  202. echo "Warning: $${IPKG_INSTROOT}$(newaliases_path) restored from $${IPKG_INSTROOT}$(newaliases_path)$(ln_old_suffix)"
  203. fi
  204. if [ -f "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" ]; then
  205. mv "$${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)" "$${IPKG_INSTROOT}$(mailq_path)"
  206. echo "Warning: $${IPKG_INSTROOT}$(mailq_path) restored from $${IPKG_INSTROOT}$(mailq_path)$(ln_old_suffix)"
  207. fi
  208. endef
  209. $(eval $(call BuildPackage,postfix))