net-misc/asterisk: Bugfix releases on both 11 & 13 branches.
[gentoo.git] / net-misc / asterisk / asterisk-13.4.0.ebuild
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 EAPI=5
6 inherit autotools base eutils linux-info multilib user systemd
7
8 MY_P="${PN}-${PV/_/-}"
9
10 DESCRIPTION="Asterisk: A Modular Open Source PBX System"
11 HOMEPAGE="http://www.asterisk.org/"
12 SRC_URI="http://downloads.asterisk.org/pub/telephony/asterisk/releases/${MY_P}.tar.gz
13          mirror://gentoo/gentoo-asterisk-patchset-4.02.tar.bz2"
14 LICENSE="GPL-2"
15 SLOT="0"
16 KEYWORDS="~amd64 ~x86"
17
18 IUSE_VOICEMAIL_STORAGE="
19         +voicemail_storage_file
20         voicemail_storage_odbc
21         voicemail_storage_imap
22 "
23 IUSE="${IUSE_VOICEMAIL_STORAGE} alsa bluetooth calendar +caps cluster curl dahdi debug doc freetds gtalk http iconv ilbc xmpp ldap libedit lua mysql newt +samples odbc osplookup oss portaudio postgres radius selinux snmp span speex srtp static syslog vorbis"
24 IUSE_EXPAND="VOICEMAIL_STORAGE"
25 REQUIRED_USE="gtalk? ( xmpp )
26         ^^ ( ${IUSE_VOICEMAIL_STORAGE/+/} )
27         voicemail_storage_odbc? ( odbc )
28 "
29
30 EPATCH_SUFFIX="patch"
31 PATCHES=( "${WORKDIR}/asterisk-patchset" )
32
33 CDEPEND="dev-db/sqlite:3
34         dev-libs/popt
35         dev-libs/jansson
36         dev-libs/libxml2
37         dev-libs/openssl:*
38         sys-libs/ncurses
39         sys-libs/zlib
40         alsa? ( media-libs/alsa-lib )
41         bluetooth? ( net-wireless/bluez )
42         calendar? ( net-libs/neon
43                  dev-libs/libical
44                  dev-libs/iksemel )
45         caps? ( sys-libs/libcap )
46         cluster? ( sys-cluster/corosync )
47         curl? ( net-misc/curl )
48         dahdi? ( >=net-libs/libpri-1.4.12_beta2
49                 net-misc/dahdi-tools )
50         freetds? ( dev-db/freetds )
51         gtalk? ( dev-libs/iksemel )
52         http? ( dev-libs/gmime:2.6 )
53         iconv? ( virtual/libiconv )
54         ilbc? ( dev-libs/ilbc-rfc3951 )
55         xmpp? ( dev-libs/iksemel )
56         ldap? ( net-nds/openldap )
57         libedit? ( dev-libs/libedit )
58         lua? ( dev-lang/lua:* )
59         mysql? ( virtual/mysql )
60         newt? ( dev-libs/newt )
61         odbc? ( dev-db/unixODBC )
62         osplookup? ( net-libs/osptoolkit )
63         portaudio? ( media-libs/portaudio )
64         postgres? ( dev-db/postgresql:* )
65         radius? ( net-dialup/radiusclient-ng )
66         snmp? ( net-analyzer/net-snmp )
67         span? ( media-libs/spandsp )
68         speex? ( media-libs/speex )
69         srtp? ( net-libs/libsrtp )
70         vorbis? ( media-libs/libvorbis )"
71
72 DEPEND="${CDEPEND}
73         !net-libs/openh323
74         !net-libs/pjsip
75         voicemail_storage_imap? ( virtual/imap-c-client )
76         virtual/pkgconfig
77 "
78
79 RDEPEND="${CDEPEND}
80         selinux? ( sec-policy/selinux-asterisk )
81         syslog? ( virtual/logger )"
82
83 PDEPEND="net-misc/asterisk-core-sounds
84         net-misc/asterisk-extra-sounds
85         net-misc/asterisk-moh-opsound"
86
87 S="${WORKDIR}/${MY_P}"
88
89 pkg_setup() {
90         CONFIG_CHECK="~!NF_CONNTRACK_SIP"
91         local WARNING_NF_CONNTRACK_SIP="SIP (NAT) connection tracking is enabled. Some users
92         have reported that this module dropped critical SIP packets in their deployments. You
93         may want to disable it if you see such problems."
94         check_extra_config
95
96         enewgroup asterisk
97         enewgroup dialout 20
98         enewuser asterisk -1 -1 /var/lib/asterisk "asterisk,dialout"
99 }
100
101 src_prepare() {
102         base_src_prepare
103         AT_M4DIR=autoconf eautoreconf
104 }
105
106 src_configure() {
107         local vmst
108
109         econf \
110                 --libdir="/usr/$(get_libdir)" \
111                 --localstatedir="/var" \
112                 --with-crypto \
113                 --with-gsm=internal \
114                 --with-popt \
115                 --with-ssl \
116                 --with-z \
117                 --without-pwlib \
118                 $(use_with caps cap) \
119                 $(use_with http gmime) \
120                 $(use_with newt) \
121                 $(use_with portaudio)
122
123         # Blank out sounds/sounds.xml file to prevent
124         # asterisk from installing sounds files (we pull them in via
125         # asterisk-{core,extra}-sounds and asterisk-moh-opsound.
126         >"${S}"/sounds/sounds.xml
127
128         # That NATIVE_ARCH chatter really is quite bothersome
129         sed -i 's/NATIVE_ARCH=/NATIVE_ARCH=0/' build_tools/menuselect-deps || die "Unable to squelch noisy build system"
130
131         # Compile menuselect binary for optional components
132         emake menuselect.makeopts
133
134         # Broken functionality is forcibly disabled (bug #360143)
135         menuselect/menuselect --disable chan_misdn menuselect.makeopts
136         menuselect/menuselect --disable chan_ooh323 menuselect.makeopts
137
138         # Utility set is forcibly enabled (bug #358001)
139         menuselect/menuselect --enable smsq menuselect.makeopts
140         menuselect/menuselect --enable streamplayer menuselect.makeopts
141         menuselect/menuselect --enable aelparse menuselect.makeopts
142         menuselect/menuselect --enable astman menuselect.makeopts
143
144         # this is connected, otherwise it would not find
145         # ast_pktccops_gate_alloc symbol
146         menuselect/menuselect --enable chan_mgcp menuselect.makeopts
147         menuselect/menuselect --enable res_pktccops menuselect.makeopts
148
149         # SSL is forcibly enabled, IAX2 & DUNDI are expected to be available
150         menuselect/menuselect --enable pbx_dundi menuselect.makeopts
151         menuselect/menuselect --enable func_aes menuselect.makeopts
152         menuselect/menuselect --enable chan_iax2 menuselect.makeopts
153
154         # SQlite3 is now the main database backend, enable related features
155         menuselect/menuselect --enable cdr_sqlite3_custom menuselect.makeopts
156         menuselect/menuselect --enable cel_sqlite3_custom menuselect.makeopts
157
158         # The others are based on USE-flag settings
159         use_select() {
160                 local state=$(use "$1" && echo enable || echo disable)
161                 shift # remove use from parameters
162
163                 while [[ -n $1 ]]; do
164                         menuselect/menuselect --${state} "$1" menuselect.makeopts
165                         shift
166                 done
167         }
168
169         use_select alsa                 chan_alsa
170         use_select bluetooth            chan_mobile
171         use_select calendar             res_calendar res_calendar_{caldav,ews,exchange,icalendar}
172         use_select cluster              res_corosync
173         use_select curl                 func_curl res_config_curl res_curl
174         use_select dahdi                app_dahdibarge app_dahdiras app_meetme chan_dahdi codec_dahdi res_timing_dahdi
175         use_select freetds              {cdr,cel}_tds
176         use_select gtalk                chan_motif
177         use_select http                 res_http_post
178         use_select iconv                func_iconv
179         use_select xmpp                 res_xmpp
180         use_select ilbc                 codec_ilbc format_ilbc
181         use_select ldap                 res_config_ldap
182         use_select lua                  pbx_lua
183         use_select mysql                app_mysql cdr_mysql res_config_mysql
184         use_select odbc                 cdr_adaptive_odbc res_config_odbc {cdr,cel,res,func}_odbc
185         use_select osplookup            app_osplookup
186         use_select oss                  chan_oss
187         use_select postgres             {cdr,cel}_pgsql res_config_pgsql
188         use_select radius               {cdr,cel}_radius
189         use_select snmp                 res_snmp
190         use_select span                 res_fax_spandsp
191         use_select speex                {codec,func}_speex
192         use_select srtp                 res_srtp
193         use_select syslog               cdr_syslog
194         use_select vorbis               format_ogg_vorbis
195
196         # Voicemail storage ...
197         for vmst in ${IUSE_VOICEMAIL_STORAGE/+/}; do
198                 if use ${vmst}; then
199                         menuselect/menuselect --enable $(echo ${vmst##*_} | tr '[:lower:]' '[:upper:]')_STORAGE menuselect.makeopts
200                 fi
201         done
202
203         if use debug; then
204                 for o in DONT_OPTIMIZE DEBUG_THREADS BETTER_BACKTRACES; do
205                         menuselect/menuselect --enable $o menuselect.makeopts
206                 done
207         fi
208 }
209
210 src_compile() {
211         ASTLDFLAGS="${LDFLAGS}" emake
212 }
213
214 src_install() {
215         mkdir -p "${D}"usr/$(get_libdir)/pkgconfig || die
216         emake DESTDIR="${D}" installdirs
217         emake DESTDIR="${D}" install
218
219         if use radius; then
220                 insinto /etc/radiusclient-ng/
221                 doins contrib/dictionary.digium
222         fi
223         diropts -m 0750 -o root -g asterisk
224         keepdir /etc/asterisk
225         if use samples; then
226                 emake DESTDIR="${D}" samples
227                 for conffile in "${D}"etc/asterisk/*.*
228                 do
229                         chown root:root $conffile
230                         chmod 0644 $conffile
231                 done
232                 einfo "Sample files have been installed"
233         else
234                 einfo "Skipping installation of sample files..."
235                 rm -f  "${D}"var/lib/asterisk/mohmp3/* || die
236                 rm -f  "${D}"var/lib/asterisk/sounds/demo-* || die
237                 rm -f  "${D}"var/lib/asterisk/agi-bin/* || die
238                 rm -f  "${D}"etc/asterisk/* || die
239         fi
240         rm -rf "${D}"var/spool/asterisk/voicemail/default || die
241
242         # keep directories
243         diropts -m 0770 -o asterisk asterisk
244         keepdir /var/lib/asterisk
245         keepdir /var/spool/asterisk
246         keepdir /var/spool/asterisk/{system,tmp,meetme,monitor,dictate,voicemail}
247         diropts -m 0750 -o asterisk -g asterisk
248         keepdir /var/log/asterisk/{cdr-csv,cdr-custom}
249
250         newinitd "${FILESDIR}"/1.8.0/asterisk.initd7 asterisk
251         newconfd "${FILESDIR}"/1.8.0/asterisk.confd asterisk
252
253         systemd_dounit "${FILESDIR}"/asterisk.service
254         systemd_newtmpfilesd "${FILESDIR}"/asterisk.tmpfiles.conf asterisk.conf
255         systemd_install_serviced "${FILESDIR}"/asterisk.service.conf
256
257         # install the upgrade documentation
258         #
259         dodoc README UPGRADE* BUGS CREDITS
260
261         # install extra documentation
262         #
263         if use doc
264         then
265                 dodoc doc/*.txt
266                 dodoc doc/*.pdf
267         fi
268
269         # install SIP scripts; bug #300832
270         #
271         dodoc "${FILESDIR}/1.6.2/sip_calc_auth"
272         dodoc "${FILESDIR}/1.8.0/find_call_sip_trace.sh"
273         dodoc "${FILESDIR}/1.8.0/find_call_ids.sh"
274         dodoc "${FILESDIR}/1.6.2/call_data.txt"
275
276         # install logrotate snippet; bug #329281
277         #
278         insinto /etc/logrotate.d
279         newins "${FILESDIR}/1.6.2/asterisk.logrotate4" asterisk
280 }
281
282 pkg_postinst() {
283         #
284         # Announcements, warnings, reminders...
285         #
286         einfo "Asterisk has been installed"
287         echo
288         elog "If you want to know more about asterisk, visit these sites:"
289         elog "http://www.asteriskdocs.org/"
290         elog "http://www.voip-info.org/wiki-Asterisk"
291         echo
292         elog "http://www.automated.it/guidetoasterisk.htm"
293         echo
294         elog "Gentoo VoIP IRC Channel:"
295         elog "#gentoo-voip @ irc.freenode.net"
296         echo
297         echo
298         elog "Please read the Asterisk 13 upgrade document:"
299         elog "https://wiki.asterisk.org/wiki/display/AST/Upgrading+to+Asterisk+13"
300 }
301
302 pkg_config() {
303         einfo "Do you want to reset file permissions and ownerships (y/N)?"
304
305         read tmp
306         tmp="$(echo $tmp | tr '[:upper:]' '[:lower:]')"
307
308         if [[ "$tmp" = "y" ]] ||\
309                 [[ "$tmp" = "yes" ]]
310         then
311                 einfo "Resetting permissions to defaults..."
312
313                 for x in spool run lib log; do
314                         chown -R asterisk:asterisk "${ROOT}"var/${x}/asterisk
315                         chmod -R u=rwX,g=rwX,o=    "${ROOT}"var/${x}/asterisk
316                 done
317
318                 chown -R root:asterisk  "${ROOT}"etc/asterisk
319                 chmod -R u=rwX,g=rwX,o= "${ROOT}"etc/asterisk
320
321                 einfo "done"
322         else
323                 einfo "skipping"
324         fi
325 }