net-firewall/nftables: Move skel files
[gentoo.git] / net-firewall / nftables / nftables-0.9.0-r6.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 inherit autotools linux-info systemd
7
8 DESCRIPTION="Linux kernel (3.13+) firewall, NAT and packet mangling tools"
9 HOMEPAGE="https://netfilter.org/projects/nftables/"
10 SRC_URI="https://git.netfilter.org/nftables/snapshot/v${PV}.tar.gz -> ${P}.tar.gz"
11
12 LICENSE="GPL-2"
13 SLOT="0"
14 KEYWORDS="~amd64 ~arm ~arm64 ~ia64 ~x86"
15 IUSE="debug doc +gmp json +modern-kernel +readline"
16
17 RDEPEND=">=net-libs/libmnl-1.0.3:0=
18         gmp? ( dev-libs/gmp:0= )
19         json? ( dev-libs/jansson )
20         readline? ( sys-libs/readline:0= )
21         >=net-libs/libnftnl-1.1.1:0="
22
23 DEPEND="${RDEPEND}
24         >=app-text/docbook2X-0.8.8-r4
25         doc? ( >=app-text/dblatex-0.3.7 )
26         sys-devel/bison
27         sys-devel/flex
28         virtual/pkgconfig"
29
30 S="${WORKDIR}/v${PV}"
31
32 pkg_setup() {
33         if kernel_is ge 3 13; then
34                 if use modern-kernel && kernel_is lt 3 18; then
35                         eerror "The modern-kernel USE flag requires kernel version 3.18 or newer to work properly."
36                 fi
37                 CONFIG_CHECK="~NF_TABLES"
38                 linux-info_pkg_setup
39         else
40                 eerror "This package requires kernel version 3.13 or newer to work properly."
41         fi
42 }
43
44 src_prepare() {
45         default
46         eautoreconf
47 }
48
49 src_configure() {
50         local myeconfargs=(
51                 --sbindir="${EPREFIX}"/sbin
52                 $(use_enable debug)
53                 $(use_enable doc pdf-doc)
54                 $(use_with !gmp mini_gmp)
55                 $(use_with json)
56                 $(use_with readline cli)
57         )
58         econf "${myeconfargs[@]}"
59 }
60
61 src_install() {
62         default
63
64         local mksuffix=""
65         use modern-kernel && mksuffix="-mk"
66
67         exeinto /usr/libexec/${PN}
68         newexe "${FILESDIR}"/libexec/${PN}${mksuffix}.sh ${PN}.sh
69         newconfd "${FILESDIR}"/${PN}${mksuffix}.confd ${PN}
70         newinitd "${FILESDIR}"/${PN}${mksuffix}.init ${PN}
71         keepdir /var/lib/nftables
72
73         systemd_dounit "${FILESDIR}"/systemd/${PN}-restore.service
74
75         docinto skels
76         dodoc "${D}"/etc/nftables/*
77         rm -R "${D}"/etc/nftables
78 }
79
80 pkg_postinst() {
81         local save_file
82         save_file="${EROOT%/}/var/lib/nftables/rules-save"
83
84         # In order for the nftables-restore systemd service to start
85         # the save_file must exist.
86         if [[ ! -f "${save_file}" ]]; then
87                 ( umask 177; touch "${save_file}" )
88         elif [[ $(( "$( stat --printf '%05a' "${save_file}" )" & 07177 )) -ne 0 ]]; then
89                 ewarn "Your system has dangerous permissions for ${save_file}"
90                 ewarn "It is probably affected by bug #691326."
91                 ewarn "You may need to fix the permissions of the file. To do so,"
92                 ewarn "you can run the command in the line below as root."
93                 ewarn "    'chmod 600 \"${save_file}\"'"
94         fi
95
96         elog "If you wish to enable the firewall rules on boot (on systemd) you"
97         elog "will need to enable the nftables-restore service."
98         elog "    'systemd_enable_service basic.target ${PN}-restore.service'"
99         elog
100         elog "If you are creating firewall rules before the next system restart "
101         elog "the nftables-restore service must be manually started in order to "
102         elog "save those rules on shutdown."
103 }