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.

236 lines
10 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:=1
  10. PKG_SOURCE_URL:=ftp://ftp.porcupine.org/mirrors/postfix-release/official/
  11. PKG_VERSION:=2.11.1
  12. PKG_MD5SUM:=56ac1f1a79737c4ac1e24535a122a4a6
  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:=+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 +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. endmenu
  47. endef
  48. define Package/postfix/conffiles
  49. /etc/postfix/main.cf
  50. /etc/postfix/master.cf
  51. /etc/postfix/aliases
  52. endef
  53. CCARGS=-DHAS_CDB -DNO_DB -DNO_EPOLL -DNO_SIGSETJMP -DNO_NIS -DDEF_DB_TYPE=\"cdb\"
  54. AUXLIBS=-L$(STAGING_DIR)/usr/lib -lcdb
  55. ifdef CONFIG_POSTFIX_TLS
  56. CCARGS+=-DUSE_TLS
  57. AUXLIBS+=-lssl -lcrypto
  58. endif
  59. ifdef CONFIG_POSTFIX_SASL
  60. CCARGS+=-DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I$(STAGING_DIR)/usr/include/sasl
  61. AUXLIBS+=-lsasl2
  62. endif
  63. ifdef CONFIG_POSTFIX_LDAP
  64. CCARGS+=-DHAS_LDAP
  65. AUXLIBS+=-lldap -llber
  66. endif
  67. config_directory=/etc/postfix
  68. sample_directory=/etc/postfix
  69. command_directory=/usr/sbin
  70. daemon_directory=/usr/libexec/postfix
  71. data_directory=/usr/var/lib/postfix
  72. queue_directory=/usr/var/spool/postfix
  73. mail_spool_directory=/usr/var/mail
  74. html_directory=no
  75. manpage_directory=no
  76. readme_directory=no
  77. sendmail_path=/usr/sbin/sendmail
  78. newaliases_path=/usr/bin/newaliases
  79. mailq_path=/usr/bin/mailq
  80. ln_suffix=.postfix
  81. ln_old_suffix=.old
  82. define Build/Configure
  83. cd $(PKG_BUILD_DIR); $(MAKE) makefiles CCARGS='$(CCARGS)' $(TARGET_CONFIGURE_OPTS) AUXLIBS="$(AUXLIBS)"
  84. endef
  85. define Build/Compile
  86. # Currently postfix has a bug with Makefiles that CCARGS are not passed to the compiler, so we are copying them to CC
  87. cd $(PKG_BUILD_DIR); $(MAKE) $(TARGET_CONFIGURE_OPTS) CC='$(TARGET_CC) $(CCARGS)'
  88. mv $(PKG_BUILD_DIR)/conf/main.cf.default.openwrt $(PKG_BUILD_DIR)/conf/main.cf.default
  89. echo "sendmail_path = $(sendmail_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  90. echo "newaliases_path = $(newaliases_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  91. echo "mailq_path = $(mailq_path)$(ln_suffix)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  92. echo "html_directory = $(html_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  93. echo "manpage_directory = $(manpage_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  94. echo "sample_directory = $(sample_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  95. echo "readme_directory = $(readme_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  96. echo "command_directory = $(command_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  97. echo "daemon_directory = $(daemon_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  98. echo "data_directory = $(data_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  99. echo "queue_directory = $(queue_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  100. echo "config_directory = $(config_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  101. echo "mail_spool_directory = $(mail_spool_directory)" >> $(PKG_BUILD_DIR)/conf/main.cf.default
  102. endef
  103. define Package/postfix/install
  104. 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
  105. $(INSTALL_DIR) $(1)$(mail_spool_directory)
  106. $(INSTALL_DIR) $(1)/etc/init.d/
  107. $(INSTALL_BIN) $(PKG_BUILD_DIR)/postfix_init $(1)/etc/init.d/postfix
  108. endef
  109. define Package/postfix/postinst
  110. #!/bin/sh
  111. # check if we are on real system
  112. if [ -z "$${IPKG_INSTROOT}" ]; then
  113. if [ -f "$(sendmail_path)" -a "$$(readlink "$(sendmail_path)")" != "$(sendmail_path)$(ln_suffix)" ]; then
  114. mv "$(sendmail_path)" "$(sendmail_path)$(ln_old_suffix)"
  115. echo "Warning: $(sendmail_path) saved as $(sendmail_path)$(ln_old_suffix)"
  116. fi
  117. if [ ! -f "$(sendmail_path)" ]; then
  118. ln -s "$(sendmail_path)$(ln_suffix)" "$(sendmail_path)"
  119. fi
  120. if [ -f "$(newaliases_path)" -a "$$(readlink "$(newaliases_path)")" != "$(newaliases_path)$(ln_suffix)" ]; then
  121. mv "$(newaliases_path)" "$(newaliases_path)$(ln_old_suffix)"
  122. echo "Warning: $(newaliases_path) saved as $(newaliases_path)$(ln_old_suffix)"
  123. fi
  124. if [ ! -f "$(newaliases_path)" ]; then
  125. ln -s "$(newaliases_path)$(ln_suffix)" "$(newaliases_path)"
  126. fi
  127. if [ -f "$(mailq_path)" -a "$$(readlink "$(mailq_path)")" != "$(mailq_path)$(ln_suffix)" ]; then
  128. mv "$(mailq_path)" "$(mailq_path)$(ln_old_suffix)"
  129. echo "Warning: $(mailq_path) saved as $(mailq_path)$(ln_old_suffix)"
  130. fi
  131. if [ ! -f "$(mailq_path)" ]; then
  132. ln -s "$(mailq_path)$(ln_suffix)" "$(mailq_path)"
  133. fi
  134. echo "myhostname = $$(uci get system.@system[0].hostname)" >> $(config_directory)/main.cf.default
  135. echo "mydomain = $$(uci get system.@system[0].hostname|sed -e "s/[^\.]*\.\(.*\)/\1/")" >> $(config_directory)/main.cf.default
  136. 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
  137. grep -qc "^sendmail_path" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^sendmail_path =" /etc/postfix/main.cf.default)"
  138. grep -qc "^newaliases_path" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^newaliases_path =" /etc/postfix/main.cf.default)"
  139. grep -qc "^mailq_path" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mailq_path =" /etc/postfix/main.cf.default)"
  140. grep -qc "^html_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^html_directory =" /etc/postfix/main.cf.default)"
  141. grep -qc "^manpage_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^manpage_directory =" /etc/postfix/main.cf.default)"
  142. grep -qc "^sample_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^sample_directory =" /etc/postfix/main.cf.default)"
  143. grep -qc "^readme_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^readme_directory =" /etc/postfix/main.cf.default)"
  144. grep -qc "^command_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^command_directory =" /etc/postfix/main.cf.default)"
  145. grep -qc "^daemon_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^daemon_directory =" /etc/postfix/main.cf.default)"
  146. grep -qc "^data_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^data_directory =" /etc/postfix/main.cf.default)"
  147. grep -qc "^queue_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^queue_directory =" /etc/postfix/main.cf.default)"
  148. grep -qc "^config_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^config_directory =" /etc/postfix/main.cf.default)"
  149. grep -qc "^mail_spool_directory" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mail_spool_directory =" /etc/postfix/main.cf.default)"
  150. grep -qc "^mail_owner" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mail_owner =" /etc/postfix/main.cf.default)"
  151. grep -qc "^setgid_group" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^setgid_group =" /etc/postfix/main.cf.default)"
  152. grep -qc "^myhostname" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^myhostname =" /etc/postfix/main.cf.default)"
  153. grep -qc "^mydomain" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mydomain =" /etc/postfix/main.cf.default)"
  154. grep -qc "^mynetworks" /etc/postfix/main.cf >/dev/null || postconf -e "$$(grep "^mynetworks =" /etc/postfix/main.cf.default)"
  155. EXTRA_COMMANDS=create_users /etc/init.d/postfix create_users
  156. postfix set-permissions
  157. postfix post-install upgrade-source
  158. postfix upgrade-configuration
  159. newaliases
  160. if [ `ps | grep "postfix/master" | grep -cv grep` -gt 0 ]
  161. then
  162. postfix reload
  163. fi
  164. if [ `grep -c aliases /etc/sysupgrade.conf` -eq 0 ]
  165. then
  166. echo "$(config_directory)/main.cf" >> /etc/sysupgrade.conf
  167. echo "$(config_directory)/aliases" >> /etc/sysupgrade.conf
  168. fi
  169. fi
  170. endef
  171. define Package/postfix/prerm
  172. #!/bin/sh
  173. # check if we are on real system
  174. if [ -z "$${IPKG_INSTROOT}" ]; then
  175. if [ `ps | grep "postfix/master" | grep -cv grep` -gt 0 ]
  176. then
  177. postfix stop
  178. fi
  179. /etc/init.d/postfix disable
  180. fi
  181. endef
  182. define Package/postfix/postrm
  183. #!/bin/sh
  184. # check if we are on real system
  185. if [ -z "$${IPKG_INSTROOT}" ]; then
  186. rm -f $(config_directory)/aliases.cdb $(data_directory)/master.lock
  187. rm -f "$(sendmail_path)" "$(newaliases_path)" "$(mailq_path)"
  188. if [ -f "$(sendmail_path)$(ln_old_suffix)" ]; then
  189. mv "$(sendmail_path)$(ln_old_suffix)" "$(sendmail_path)"
  190. echo "Warning: $(sendmail_path) restored from $(sendmail_path)$(ln_old_suffix)"
  191. fi
  192. if [ -f "$(newaliases_path)$(ln_old_suffix)" ]; then
  193. mv "$(newaliases_path)$(ln_old_suffix)" "$(newaliases_path)"
  194. echo "Warning: $(newaliases_path) restored from $(newaliases_path)$(ln_old_suffix)"
  195. fi
  196. if [ -f "$(mailq_path)$(ln_old_suffix)" ]; then
  197. mv "$(mailq_path)$(ln_old_suffix)" "$(mailq_path)"
  198. echo "Warning: $(mailq_path) restored from $(mailq_path)$(ln_old_suffix)"
  199. fi
  200. fi
  201. endef
  202. $(eval $(call BuildPackage,postfix))