ufw-0.35.ebuild 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. # Copyright 1999-2017 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI=6
  4. PYTHON_COMPAT=( python{2_7,3_4,3_5} )
  5. DISTUTILS_IN_SOURCE_BUILD=1
  6. inherit bash-completion-r1 eutils linux-info distutils-r1 systemd
  7. DESCRIPTION="A program used to manage a netfilter firewall"
  8. HOMEPAGE="https://launchpad.net/ufw"
  9. SRC_URI="https://launchpad.net/ufw/${PV}/${PV}/+download/${P}.tar.gz"
  10. LICENSE="GPL-3"
  11. SLOT="0"
  12. KEYWORDS="~amd64 ~ia64 ~ppc ~ppc64 ~sparc ~x86"
  13. IUSE="examples ipv6"
  14. DEPEND="sys-devel/gettext"
  15. RDEPEND=">=net-firewall/iptables-1.4[ipv6?]
  16. !<kde-misc/kcm-ufw-0.4.2
  17. !<net-firewall/ufw-frontends-0.3.2
  18. "
  19. # tests fail; upstream bug: https://bugs.launchpad.net/ufw/+bug/815982
  20. RESTRICT="test"
  21. PATCHES=(
  22. # Remove unnecessary build time dependency on net-firewall/iptables.
  23. "${FILESDIR}"/${PN}-0.33-dont-check-iptables.patch
  24. # Move files away from /lib/ufw.
  25. "${FILESDIR}"/${PN}-0.35-move-path.patch
  26. # Remove shebang modification.
  27. "${FILESDIR}"/${PN}-0.34_pre805-shebang.patch
  28. # Fix bash completions, bug #526300
  29. "${FILESDIR}"/${P}-bash-completion.patch
  30. )
  31. pkg_pretend() {
  32. local CONFIG_CHECK="~PROC_FS
  33. ~NETFILTER_XT_MATCH_COMMENT ~NETFILTER_XT_MATCH_HL
  34. ~NETFILTER_XT_MATCH_LIMIT ~NETFILTER_XT_MATCH_MULTIPORT
  35. ~NETFILTER_XT_MATCH_RECENT ~NETFILTER_XT_MATCH_STATE"
  36. if kernel_is -ge 2 6 39; then
  37. CONFIG_CHECK+=" ~NETFILTER_XT_MATCH_ADDRTYPE"
  38. else
  39. CONFIG_CHECK+=" ~IP_NF_MATCH_ADDRTYPE"
  40. fi
  41. # https://bugs.launchpad.net/ufw/+bug/1076050
  42. if kernel_is -ge 3 4; then
  43. CONFIG_CHECK+=" ~NETFILTER_XT_TARGET_LOG"
  44. else
  45. CONFIG_CHECK+=" ~IP_NF_TARGET_LOG"
  46. use ipv6 && CONFIG_CHECK+=" ~IP6_NF_TARGET_LOG"
  47. fi
  48. CONFIG_CHECK+=" ~IP_NF_TARGET_REJECT"
  49. use ipv6 && CONFIG_CHECK+=" ~IP6_NF_TARGET_REJECT"
  50. check_extra_config
  51. # Check for default, useful optional features.
  52. if ! linux_config_exists; then
  53. ewarn "Cannot determine configuration of your kernel."
  54. return
  55. fi
  56. local nf_nat_ftp_ok="yes"
  57. local nf_conntrack_ftp_ok="yes"
  58. local nf_conntrack_netbios_ns_ok="yes"
  59. linux_chkconfig_present \
  60. NF_NAT_FTP || nf_nat_ftp_ok="no"
  61. linux_chkconfig_present \
  62. NF_CONNTRACK_FTP || nf_conntrack_ftp_ok="no"
  63. linux_chkconfig_present \
  64. NF_CONNTRACK_NETBIOS_NS || nf_conntrack_netbios_ns_ok="no"
  65. # This is better than an essay for each unset option...
  66. if [[ ${nf_nat_ftp_ok} = no ]] || [[ ${nf_conntrack_ftp_ok} = no ]] \
  67. || [[ ${nf_conntrack_netbios_ns_ok} = no ]]
  68. then
  69. echo
  70. local mod_msg="Kernel options listed below are not set. They are not"
  71. mod_msg+=" mandatory, but they are often useful."
  72. mod_msg+=" If you don't need some of them, please remove relevant"
  73. mod_msg+=" module name(s) from IPT_MODULES in"
  74. mod_msg+=" '${EROOT}etc/default/ufw' before (re)starting ufw."
  75. mod_msg+=" Otherwise ufw may fail to start!"
  76. ewarn "${mod_msg}"
  77. if [[ ${nf_nat_ftp_ok} = no ]]; then
  78. ewarn "NF_NAT_FTP: for better support for active mode FTP."
  79. fi
  80. if [[ ${nf_conntrack_ftp_ok} = no ]]; then
  81. ewarn "NF_CONNTRACK_FTP: for better support for active mode FTP."
  82. fi
  83. if [[ ${nf_conntrack_netbios_ns_ok} = no ]]; then
  84. ewarn "NF_CONNTRACK_NETBIOS_NS: for better Samba support."
  85. fi
  86. fi
  87. }
  88. python_prepare_all() {
  89. # Set as enabled by default. User can enable or disable
  90. # the service by adding or removing it to/from a runlevel.
  91. sed -i 's/^ENABLED=no/ENABLED=yes/' conf/ufw.conf \
  92. || die "sed failed (ufw.conf)"
  93. sed -i "s/^IPV6=yes/IPV6=$(usex ipv6)/" conf/ufw.defaults || die
  94. # If LINGUAS is set install selected translations only.
  95. if [[ -n ${LINGUAS+set} ]]; then
  96. _EMPTY_LOCALE_LIST="yes"
  97. pushd locales/po > /dev/null || die
  98. local lang
  99. for lang in *.po; do
  100. if ! has "${lang%.po}" ${LINGUAS}; then
  101. rm "${lang}" || die
  102. else
  103. _EMPTY_LOCALE_LIST="no"
  104. fi
  105. done
  106. popd > /dev/null || die
  107. else
  108. _EMPTY_LOCALE_LIST="no"
  109. fi
  110. distutils-r1_python_prepare_all
  111. }
  112. python_install_all() {
  113. newconfd "${FILESDIR}"/ufw.confd ufw
  114. newinitd "${FILESDIR}"/ufw-2.initd ufw
  115. systemd_dounit "${FILESDIR}/ufw.service"
  116. exeinto /usr/share/${PN}
  117. doexe tests/check-requirements
  118. # users normally would want it
  119. insinto /usr/share/doc/${PF}/logging/syslog-ng
  120. doins "${FILESDIR}"/syslog-ng/*
  121. insinto /usr/share/doc/${PF}/logging/rsyslog
  122. doins "${FILESDIR}"/rsyslog/*
  123. doins doc/rsyslog.example
  124. if use examples; then
  125. insinto /usr/share/doc/${PF}/examples
  126. doins examples/*
  127. fi
  128. newbashcomp shell-completion/bash ${PN}
  129. [[ $_EMPTY_LOCALE_LIST != yes ]] && domo locales/mo/*.mo
  130. distutils-r1_python_install_all
  131. python_replicate_script "${D}usr/sbin/ufw"
  132. }
  133. pkg_postinst() {
  134. local print_check_req_warn
  135. print_check_req_warn=false
  136. if [[ -z ${REPLACING_VERSIONS} ]]; then
  137. echo
  138. elog "To enable ufw, add it to boot sequence and activate it:"
  139. elog "-- # rc-update add ufw boot"
  140. elog "-- # /etc/init.d/ufw start"
  141. echo
  142. elog "If you want to keep ufw logs in a separate file, take a look at"
  143. elog "/usr/share/doc/${PF}/logging."
  144. print_check_req_warn=true
  145. else
  146. for rv in ${REPLACING_VERSIONS}; do
  147. local major=${rv%%.*}
  148. local minor=${rv#${major}.}
  149. if [[ ${major} -eq 0 && ${minor} -lt 34 ]]; then
  150. print_check_req_warn=true
  151. fi
  152. done
  153. fi
  154. if $print_check_req_warn; then
  155. echo
  156. elog "/usr/share/ufw/check-requirements script is installed."
  157. elog "It is useful for debugging problems with ufw. However one"
  158. elog "should keep in mind that the script assumes IPv6 is enabled"
  159. elog "on kernel and net-firewall/iptables, and fails when it's not."
  160. fi
  161. echo
  162. ewarn "Note: once enabled, ufw blocks also incoming SSH connections by"
  163. ewarn "default. See README, Remote Management section for more information."
  164. }