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.

263 lines
12 KiB

  1. #
  2. # Copyright (C) 2014 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:=2.11.3
  12. PKG_MD5SUM:=c3f0f51d8865559b40e9350eb3816011
  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_FILE:=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
  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
  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. ln_suffix=.postfix
  101. ln_old_suffix=.old
  102. define Package/postfix/conffiles
  103. $(config_directory)/main.cf
  104. $(config_directory)/master.cf
  105. $(config_directory)/aliases
  106. endef
  107. define Build/Configure
  108. if [ "$(CONFIG_POSTFIX_DB)" = "" -a "$(CONFIG_POSTFIX_CDB)" = "" ]; then\
  109. echo "Build error: You must select at least one of the DB types";\
  110. exit 1;\
  111. fi
  112. cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
  113. endef
  114. define Build/Compile
  115. # Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC
  116. cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
  117. cp ./files/main.cf.default $(PKG_BUILD_DIR)/conf/main.cf.default
  118. echo "default_database_type = $(default_database_type)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  119. echo "alias_database = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  120. echo "alias_maps = $(default_database_type):$(config_directory)/aliases" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  121. echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  122. echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  123. echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  124. echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  125. echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  126. echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  127. echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  128. echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  129. echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  130. echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  131. echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  132. echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  133. echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  134. endef
  135. define Package/postfix/install
  136. 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
  137. $(INSTALL_DIR) $(1)$(mail_spool_directory)
  138. $(INSTALL_DIR) $(1)/etc/init.d/
  139. $(INSTALL_BIN) ./files/postfix.init $(1)/etc/init.d/postfix
  140. endef
  141. define Package/postfix/postinst
  142. #!/bin/sh
  143. # check if we are on real system
  144. if [ -z "$${IPKG_INSTROOT}" ]; then
  145. if [ -f "$(sendmail_path)" -a "$$(readlink "$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
  146. mv "$(sendmail_path)" "$(sendmail_path)$(ln_old_suffix)"
  147. echo "Warning: $(sendmail_path) saved as $(sendmail_path)$(ln_old_suffix)"
  148. fi
  149. if [ ! -f "$(sendmail_path)" ]; then
  150. ln -s "$(sendmail_path)$(ln_suffix)" "$(sendmail_path)"
  151. fi
  152. if [ -f "$(newaliases_path)" -a "$$(readlink "$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
  153. mv "$(newaliases_path)" "$(newaliases_path)$(ln_old_suffix)"
  154. echo "Warning: $(newaliases_path) saved as $(newaliases_path)$(ln_old_suffix)"
  155. fi
  156. if [ ! -f "$(newaliases_path)" ]; then
  157. ln -s "$(newaliases_path)$(ln_suffix)" "$(newaliases_path)"
  158. fi
  159. if [ -f "$(mailq_path)" -a "$$(readlink "$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
  160. mv "$(mailq_path)" "$(mailq_path)$(ln_old_suffix)"
  161. echo "Warning: $(mailq_path) saved as $(mailq_path)$(ln_old_suffix)"
  162. fi
  163. if [ ! -f "$(mailq_path)" ]; then
  164. ln -s "$(mailq_path)$(ln_suffix)" "$(mailq_path)"
  165. fi
  166. echo "myhostname = $$(uci get system.@system[0].hostname)" >> $(config_directory)/main.cf.default
  167. echo "mydomain = $$(uci get system.@system[0].hostname|sed -e "s/[^\.]*\.\(.*\)/\1/")" >> $(config_directory)/main.cf.default
  168. 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
  169. grep -qc "^sendmail_path" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^sendmail_path =" $(config_directory)/main.cf.default)"
  170. grep -qc "^newaliases_path" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^newaliases_path =" $(config_directory)/main.cf.default)"
  171. grep -qc "^mailq_path" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^mailq_path =" $(config_directory)/main.cf.default)"
  172. grep -qc "^html_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^html_directory =" $(config_directory)/main.cf.default)"
  173. grep -qc "^manpage_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^manpage_directory =" $(config_directory)/main.cf.default)"
  174. grep -qc "^sample_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^sample_directory =" $(config_directory)/main.cf.default)"
  175. grep -qc "^readme_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^readme_directory =" $(config_directory)/main.cf.default)"
  176. grep -qc "^command_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^command_directory =" $(config_directory)/main.cf.default)"
  177. grep -qc "^daemon_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^daemon_directory =" $(config_directory)/main.cf.default)"
  178. grep -qc "^data_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^data_directory =" $(config_directory)/main.cf.default)"
  179. grep -qc "^queue_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^queue_directory =" $(config_directory)/main.cf.default)"
  180. grep -qc "^config_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^config_directory =" $(config_directory)/main.cf.default)"
  181. grep -qc "^mail_spool_directory" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^mail_spool_directory =" $(config_directory)/main.cf.default)"
  182. grep -qc "^mail_owner" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^mail_owner =" $(config_directory)/main.cf.default)"
  183. grep -qc "^setgid_group" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^setgid_group =" $(config_directory)/main.cf.default)"
  184. grep -qc "^myhostname" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^myhostname =" $(config_directory)/main.cf.default)"
  185. grep -qc "^mydomain" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^mydomain =" $(config_directory)/main.cf.default)"
  186. grep -qc "^mynetworks" $(config_directory)/main.cf >/dev/null || postconf -e "$$(grep "^mynetworks =" $(config_directory)/main.cf.default)"
  187. EXTRA_COMMANDS=create_users /etc/init.d/postfix create_users
  188. postfix set-permissions
  189. postfix post-install upgrade-source
  190. postfix upgrade-configuration
  191. newaliases
  192. ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix reload
  193. grep -qc main\.cf /etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/main.cf" >> /etc/sysupgrade.conf
  194. grep -qc master\.cf /etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/master.cf" >> /etc/sysupgrade.conf
  195. grep -qc aliases /etc/sysupgrade.conf >/dev/null || echo "$(config_directory)/aliases" >> /etc/sysupgrade.conf
  196. fi
  197. endef
  198. define Package/postfix/prerm
  199. #!/bin/sh
  200. # check if we are on real system
  201. if [ -z "$${IPKG_INSTROOT}" ]; then
  202. ps | grep "postfix/master" | grep -cvq grep >/dev/null && postfix stop
  203. /etc/init.d/postfix disable
  204. fi
  205. endef
  206. define Package/postfix/postrm
  207. #!/bin/sh
  208. # check if we are on real system
  209. if [ -z "$${IPKG_INSTROOT}" ]; then
  210. rm -f $(config_directory)/aliases.cdb $(config_directory)/aliases.db $(data_directory)/master.lock
  211. rm -f "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"
  212. if [ -f "$(sendmail_path)$(ln_old_suffix)" ]; then
  213. mv "$(sendmail_path)$(ln_old_suffix)" "$(sendmail_path)"
  214. echo "Warning: $(sendmail_path) restored from $(sendmail_path)$(ln_old_suffix)"
  215. fi
  216. if [ -f "$(newaliases_path)$(ln_old_suffix)" ]; then
  217. mv "$(newaliases_path)$(ln_old_suffix)" "$(newaliases_path)"
  218. echo "Warning: $(newaliases_path) restored from $(newaliases_path)$(ln_old_suffix)"
  219. fi
  220. if [ -f "$(mailq_path)$(ln_old_suffix)" ]; then
  221. mv "$(mailq_path)$(ln_old_suffix)" "$(mailq_path)"
  222. echo "Warning: $(mailq_path) restored from $(mailq_path)$(ln_old_suffix)"
  223. fi
  224. fi
  225. endef
  226. $(eval $(call BuildPackage,postfix))