*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / net-dialup / freeradius / freeradius-3.0.18-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python{2_7,3_{6,7}} )
7 inherit autotools pam python-single-r1 systemd user
8
9 MY_P="${PN}-server-${PV}"
10
11 DESCRIPTION="Highly configurable free RADIUS server"
12 SRC_URI="
13         ftp://ftp.freeradius.org/pub/radius/${MY_P}.tar.gz
14         ftp://ftp.freeradius.org/pub/radius/old/${MY_P}.tar.gz
15 "
16 HOMEPAGE="http://www.freeradius.org/"
17
18 KEYWORDS="~amd64 ~arm ~ppc ~ppc64 ~sparc ~x86"
19 LICENSE="GPL-2+"
20 SLOT="0"
21
22 IUSE="
23         debug firebird iodbc kerberos ldap libressl memcached mysql odbc oracle pam
24         pcap postgres python readline rest samba sqlite ssl redis
25 "
26 RESTRICT="test firebird? ( bindist )"
27
28 # NOTE: Temporary freeradius doesn't support linking with mariadb client
29 #       libs also if code is compliant, will be available in the next release.
30 #       (http://lists.freeradius.org/pipermail/freeradius-devel/2018-October/013228.html)
31 RDEPEND="!net-dialup/cistronradius
32         !net-dialup/gnuradius
33         dev-lang/perl:=
34         sys-libs/gdbm:=
35         sys-libs/talloc
36         python? ( ${PYTHON_DEPS} )
37         readline? ( sys-libs/readline:0= )
38         pcap? ( net-libs/libpcap )
39         memcached? ( dev-libs/libmemcached )
40         mysql? ( dev-db/mysql-connector-c )
41         postgres? ( dev-db/postgresql:= )
42         firebird? ( dev-db/firebird )
43         pam? ( sys-libs/pam )
44         rest? ( dev-libs/json-c:= )
45         samba? ( net-fs/samba )
46         redis? ( dev-libs/hiredis:= )
47         ssl? (
48                 !libressl? ( dev-libs/openssl:0=[-bindist] )
49                 libressl? ( dev-libs/libressl:0= )
50         )
51         ldap? ( net-nds/openldap )
52         kerberos? ( virtual/krb5 )
53         sqlite? ( dev-db/sqlite:3 )
54         odbc? ( dev-db/unixODBC )
55         iodbc? ( dev-db/libiodbc )
56         oracle? ( dev-db/oracle-instantclient-basic )"
57 DEPEND="${RDEPEND}"
58
59 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
60
61 S="${WORKDIR}/${MY_P}"
62
63 PATCHES=(
64         "${FILESDIR}"/${P}-libressl.patch
65         "${FILESDIR}"/${P}-systemd-service.patch
66 )
67
68 pkg_setup() {
69         enewgroup radius
70         enewuser radius -1 -1 /var/log/radius radius
71
72         if use python ; then
73                 python-single-r1_pkg_setup
74                 export PYTHONBIN="${EPYTHON}"
75         fi
76 }
77
78 src_prepare() {
79         # most of the configuration options do not appear as ./configure
80         # switches. Instead it identifies the directories that are available
81         # and run through them. These might check for the presence of
82         # various libraries, in which case they are not built.  To avoid
83         # automagic dependencies, we just remove all the modules that we're
84         # not interested in using.
85
86         use ssl || { rm -r src/modules/rlm_eap/types/rlm_eap_{tls,ttls,peap} || die ; }
87         use ldap || { rm -r src/modules/rlm_ldap || die ; }
88         use kerberos || { rm -r src/modules/rlm_krb5 || die ; }
89         use memcached || { rm -r src/modules/rlm_cache/drivers/rlm_cache_memcached || die ; }
90         use pam || { rm -r src/modules/rlm_pam || die ; }
91         use python || { rm -r src/modules/rlm_python || die ; }
92         use rest || { rm -r src/modules/rlm_rest || die ; }
93         use redis || { rm -r src/modules/rlm_redis{,who} || die ; }
94         # can't just nuke rlm_mschap because many modules rely on smbdes.h
95         use samba || { rm -r src/modules/rlm_mschap/{configure,*.mk} || die ; }
96         # Do not install ruby rlm module, bug #483108
97         rm -r src/modules/rlm_ruby || die
98
99         # these are all things we don't have in portage/I don't want to deal
100         # with myself
101         rm -r src/modules/rlm_eap/types/rlm_eap_tnc || die # requires TNCS library
102         rm -r src/modules/rlm_eap/types/rlm_eap_ikev2 || die # requires libeap-ikev2
103         rm -r src/modules/rlm_opendirectory || die # requires some membership.h
104         rm -r src/modules/rlm_sql/drivers/rlm_sql_{db2,freetds} || die
105
106         # sql drivers that are not part of experimental are loaded from a
107         # file, so we have to remove them from the file itself when we
108         # remove them.
109         usesqldriver() {
110                 local flag=$1
111                 local driver=rlm_sql_${2:-${flag}}
112
113                 if ! use ${flag}; then
114                         rm -r src/modules/rlm_sql/drivers/${driver} || die
115                         sed -i -e /${driver}/d src/modules/rlm_sql/stable || die
116                 fi
117         }
118
119         sed -i \
120                 -e 's:^#\tuser = :\tuser = :g' \
121                 -e 's:^#\tgroup = :\tgroup = :g' \
122                 -e 's:/var/run/radiusd:/run/radiusd:g' \
123                 -e '/^run_dir/s:${localstatedir}::g' \
124                 raddb/radiusd.conf.in || die
125
126         # verbosity
127         # build shared libraries using jlibtool --shared
128         sed -i \
129                 -e '/$(LIBTOOL)/s|--quiet ||g' \
130                 -e 's:--mode=\(compile\|link\):& --shared:g' \
131                 Make.inc.in || die
132
133         sed -i \
134                 -e 's|--silent ||g' \
135                 -e 's:--mode=\(compile\|link\):& --shared:g' \
136                 scripts/libtool.mk || die
137
138         # crude measure to stop jlibtool from running ranlib and ar
139         sed -i \
140                 -e '/LIBRARIAN/s|".*"|"true"|g' \
141                 -e '/RANLIB/s|".*"|"true"|g' \
142                 scripts/jlibtool.c || die
143
144         usesqldriver mysql
145         usesqldriver postgres postgresql
146         usesqldriver firebird
147         usesqldriver iodbc
148         usesqldriver odbc unixodbc
149         usesqldriver oracle
150         usesqldriver sqlite
151
152         default
153
154         eautoreconf
155 }
156
157 src_configure() {
158         # do not try to enable static with static-libs; upstream is a
159         # massacre of libtool best practices so you also have to make sure
160         # to --enable-shared explicitly.
161         local myeconfargs=(
162                 --enable-shared
163                 --disable-static
164                 --disable-ltdl-install
165                 --with-system-libtool
166                 --with-system-libltdl
167                 --with-ascend-binary
168                 --with-udpfromto
169                 --with-dhcp
170                 --with-iodbc-include-dir=/usr/include/iodbc
171                 --with-experimental-modules
172                 --with-docdir=/usr/share/doc/${PF}
173                 --with-logdir=/var/log/radius
174                 $(use_enable debug developer)
175                 $(use_with ldap edir)
176                 $(use_with ssl openssl)
177         )
178         # fix bug #77613
179         if has_version app-crypt/heimdal; then
180                 myeconfargs+=( --enable-heimdal-krb5 )
181         fi
182
183         use readline || export ac_cv_lib_readline=no
184         use pcap || export ac_cv_lib_pcap_pcap_open_live=no
185
186         econf "${myeconfargs[@]}"
187 }
188
189 src_compile() {
190         # verbose, do not generate certificates
191         emake \
192                 Q='' ECHO=true \
193                 LOCAL_CERT_PRODUCTS=''
194 }
195
196 src_install() {
197         dodir /etc
198         diropts -m0750 -o root -g radius
199         dodir /etc/raddb
200         diropts -m0750 -o radius -g radius
201         dodir /var/log/radius
202         keepdir /var/log/radius/radacct
203         diropts
204
205         # verbose, do not install certificates
206         # Parallel install fails (#509498)
207         emake -j1 \
208                 Q='' ECHO=true \
209                 LOCAL_CERT_PRODUCTS='' \
210                 R="${D}" \
211                 install
212
213         fowners -R root:radius /etc/raddb
214         fowners -R radius:radius /var/log/radius
215
216         pamd_mimic_system radiusd auth account password session
217
218         dodoc CREDITS
219
220         rm "${ED}/usr/sbin/rc.radiusd" || die
221
222         newinitd "${FILESDIR}/radius.init-r3" radiusd
223         newconfd "${FILESDIR}/radius.conf-r4" radiusd
224
225         systemd_newtmpfilesd "${FILESDIR}"/freeradius.tmpfiles freeradius.conf
226         systemd_dounit "${S}"/debian/freeradius.service
227
228         find "${ED}" \( -name "*.a" -o -name "*.la" \) -delete || die
229 }
230
231 pkg_config() {
232         if use ssl; then
233                 cd "${ROOT}"/etc/raddb/certs || die
234                 ./bootstrap || die "Error while running ./bootstrap script."
235                 fowners -R root:radius "${ROOT}"/etc/raddb/certs
236         fi
237 }
238
239 pkg_preinst() {
240         if ! has_version ${CATEGORY}/${PN} && use ssl; then
241                 elog "You have to run \`emerge --config =${CATEGORY}/${PF}\` to be able"
242                 elog "to start the radiusd service."
243         fi
244 }