File: homer-api.spec.in

package info (click to toggle)
homer-api 5.0.6%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,604 kB
  • ctags: 2,439
  • sloc: php: 8,259; sql: 1,212; perl: 984; sh: 318; makefile: 69
file content (251 lines) | stat: -rw-r--r-- 12,138 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# Global definitions for SELinux
%global selinux_types %(%{__awk} '/^#[[:space:]]*SELINUXTYPE=/,/^[^#]/ { if ($3 == "-") printf "%s ", $2 }' %{_sysconfdir}/selinux/config 2>/dev/null)
%global selinux_variants %([ -z "%{selinux_types}" ] && echo mls targeted || echo %{selinux_types})

# Definitions
%define debug_package %{nil}
%if %{_vendor} == suse
%define webroot %{_prefix}/srv/sipcapture/htdocs
%else # CentOS/Fedora
%define webroot %{_localstatedir}/www/sipcapture/htdocs
%define webuser apache
%define webgroup apache
%endif
%define DBDIR %{_localstatedir}/sipcapture/mysql

Name:           @PACKAGE_NAME@
Version:        @PACKAGE_VERSION@
Release:        %{BUILD_NUMBER}
Summary:        HTTP based API for HOMER

Group:          Telecommunications
License:        GPLv3
URL:            @PACKAGE_URL@
Source0:        %name-%version.tar.gz

%{?el6:Requires:       initscripts}
%{?el7:Requires:       systemd}
Requires:       util-linux
Requires:       kamailio >= 4.3, kamailio-mysql >= 4.3
Requires:       ntp
Requires:       php >= 5
Requires:       php-mysql
Requires:       perl-DBD-MySQL
Requires:       mysql-community-server >= 5.6
Requires:       mysql-community-client >= 5.6
Requires:       selinux-policy

%description
HTTP based API for HOMER is a robust, carrier-grade, scalable SIP Capture system and Monitoring Application with HEP/HEP2, IP Proto4 (IPIP) encapsulation & port mirroring/monitoring support right out of the box, ready to process & store insane amounts of signaling with instant search, end-to-end analysis and drill-down capabilities for ITSPs, VoIP Providers and Trunk Suppliers using SIP signaling

%package httpd
Requires:       %name = %version
Requires:       httpd
Summary:        httpd config for HTTP based API for HOMER

%description httpd
HOMER API httpd configuration

%package nginx
Requires:       %name = %version
Requires:       nginx, php-fpm
BuildRequires:  selinux-policy-devel
Summary:        nginx config for HTTP based API for HOMER

%description nginx
HOMER API nginx configuration

%files
%defattr(0664,%{webuser},%{webgroup},0775)
%dir %{webroot}
%dir %{webroot}/api
%{webroot}/api/*
%{webroot}/apidoc/*
%dir %{DBDIR}
%attr(0664,root,root)%{_datadir}/sipcapture/sql/*
%attr(0664,root,root)%{_sysconfdir}/my.cnf.d/sipcapture.cnf
%attr(0664,root,root)%{_sysconfdir}/kamailio/kamailio-sipcapture.cfg
%attr(0664,root,root)%{_sysconfdir}/sysconfig/sipcapture
%{?el6:%attr(0775,root,root)%{_sysconfdir}/init.d/sipcapture}
%{?el7:%attr(0664,root,root)/usr/lib/systemd/system/sipcapture.service}
%{?el7:%attr(0664,root,root)%{_sysconfdir}/systemd/system/mysqld.service}
%attr(0664,root,root)%{_sysconfdir}/rsyslog.d/sipcapture.conf
%attr(0664,root,root)%{_sysconfdir}/logrotate.d/sipcapture
%attr(0644,root,root)%{_sysconfdir}/cron.d/sipcapture
%attr(0775,root,root)%{_bindir}/homer_rotate
%attr(0775,root,root)%{_bindir}/homer_mysql_new_table.pl
%attr(0775,root,root)%{_bindir}/homer_mysql_partrotate_unixtimestamp.pl

%files httpd
%defattr(0664,root,root,0775)
%attr(0664,%{webuser},%{webuser})%{webroot}/api/.htaccess
%{_sysconfdir}/httpd/conf.d/sipcapture.conf
%{_datadir}/selinux/*/sipcapture-dashboards.pp

%files nginx
%defattr(0664,root,root,0775)
%{_sysconfdir}/nginx/conf.d/sipcapture.conf
%{_sysconfdir}/php-fpm.d/sipcapture.conf
%{_datadir}/selinux/*/nginx.pp
%{_datadir}/selinux/*/php-fpm.pp
%{_datadir}/selinux/*/sipcapture-dashboards.pp

%prep
%setup -b0 -q

%build
%configure --enable-rpmbuilb
make
for p in nginx php-fpm sipcapture-dashboards; do
    if [ -f examples/web/$p.te ]; then
	(cd examples/web ; make -f /usr/share/selinux/devel/Makefile $p.pp && mv $p.pp $p.pp.targeted;);
    fi;
done

%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install
# SELinux
for selinuxvariant in %{selinux_variants}
do
	install -d %{buildroot}%{_datadir}/selinux/${selinuxvariant}
	if [ -f examples/web/nginx.pp.${selinuxvariant} ]; then install -p -m 644 examples/web/nginx.pp.${selinuxvariant} %{buildroot}%{_datadir}/selinux/${selinuxvariant}/nginx.pp; fi;
	if [ -f examples/web/php-fpm.pp.${selinuxvariant} ]; then install -p -m 644 examples/web/php-fpm.pp.${selinuxvariant} %{buildroot}%{_datadir}/selinux/${selinuxvariant}/php-fpm.pp; fi;
	if [ -f examples/web/sipcapture-dashboards.pp.${selinuxvariant} ]; then install -p -m 644 examples/web/sipcapture-dashboards.pp.${selinuxvariant} %{buildroot}%{_datadir}/selinux/${selinuxvariant}/sipcapture-dashboards.pp; fi;
done
# Configuration templates
# kamailio configuration
install -d %{buildroot}%{_sysconfdir}/sysconfig
%{?el6:install -d %{buildroot}%{_sysconfdir}/init.d}
%{?el7:install -d %{buildroot}/usr/lib/systemd/system}
install -p -m 644 examples/sipcapture/el%{rhel}/sipcapture.sysconfig %{buildroot}%{_sysconfdir}/sysconfig/sipcapture
%{?el6:install -p -m 644 examples/sipcapture/el%{rhel}/sipcapture.init %{buildroot}%{_sysconfdir}/init.d/sipcapture}
%{?el7:install -p -m 644 examples/sipcapture/el%{rhel}/sipcapture.service %{buildroot}/usr/lib/systemd/system/sipcapture.service}
# HTTP servers confgiuration
install -d %{buildroot}%{_sysconfdir}/httpd/conf.d
install -d %{buildroot}%{_sysconfdir}/nginx/conf.d
install -d %{buildroot}%{_sysconfdir}/php-fpm.d
install -p -m 644 examples/web/homer5.apache %{buildroot}%{_sysconfdir}/httpd/conf.d/sipcapture.conf
install -p -m 644 examples/web/homer5.nginx %{buildroot}%{_sysconfdir}/nginx/conf.d/sipcapture.conf
install -p -m 644 examples/web/homer5.php-fpm %{buildroot}%{_sysconfdir}/php-fpm.d/sipcapture.conf
# MySQL configuration
install -d %{buildroot}%{DBDIR}
install -d %{buildroot}%{_datadir}/sipcapture/sql/
install -p -m 644 sql/* %{buildroot}%{_datadir}/sipcapture/sql/
install -d %{buildroot}%{_sysconfdir}/my.cnf.d
install -d %{buildroot}%{_sysconfdir}/systemd/system
install -p -m 644 examples/mysql/sipcapture.cnf %{buildroot}%{_sysconfdir}/my.cnf.d/sipcapture.cnf
install -p -m 644 examples/mysql/mysqld.service %{buildroot}%{_sysconfdir}/systemd/system/mysqld.service
# UI and API directories and files
install -d %{buildroot}%{webroot}
install -d %{buildroot}%{webroot}/api
%{__cp} -r api/Authentication %{buildroot}%{webroot}/api
%{__cp} -r api/Database %{buildroot}%{webroot}/api
%{__cp} -r api/RestApi %{buildroot}%{webroot}/api
%{__cp} -r api/RestService %{buildroot}%{webroot}/api
%{__cp} -r api/Statistic %{buildroot}%{webroot}/api
%{__cp} -r api/*.php %{buildroot}%{webroot}/api
install -p -m 644 api/.htaccess %{buildroot}%{webroot}/api
install -d %{buildroot}%{_sysconfdir}/cron.d
install -d %{buildroot}%{_sysconfdir}/sysconfig
install -d %{buildroot}%{_bindir}
install -p -m 644 scripts/sipcapture.crontab %{buildroot}%{_sysconfdir}/cron.d/sipcapture
install -p -m 644 scripts/homer_rotate %{buildroot}%{_bindir}/homer_rotate
install -p -m 644 scripts/homer_mysql_new_table.pl %{buildroot}%{_bindir}/homer_mysql_new_table.pl
install -p -m 644 scripts/homer_mysql_partrotate_unixtimestamp.pl %{buildroot}%{_bindir}/homer_mysql_partrotate_unixtimestamp.pl

%post
# MySQL stuff
/usr/bin/logger -t "INSTALLER" "=========== Initializing local MySQL server data directory in %{DBDIR}"
#/bin/echo "MYSQLD_OPTS=\"--explicit_defaults_for_timestamp\"" > %{_sysconfdir}/sysconfig/mysql | /usr/bin/logger -t "INSTALLER"
/usr/bin/mysql_install_db --user=mysql --datadir=%{DBDIR} | /usr/bin/logger -t "INSTALLER"
#if [ -e /bin/systemctl ]; then /usr/bin/logger -t "INSTALLER" "=========== Reloading systemd"; /bin/systemctl daemon-reload; fi | /usr/bin/logger -t "INSTALLER"
/usr/bin/logger -t "INSTALLER" "=========== Installing HOMER DB: users and permissions";
(cat %{_datadir}/sipcapture/sql/homer_user_bootstrap.sql | %{?el7:/usr}/sbin/mysqld --user=mysql --datadir=%{DBDIR} --bootstrap) 2>&1 | /usr/bin/logger -t "INSTALLER";
/usr/bin/logger -t "INSTALLER" "=========== Enable MySQL server";
if [ -e /bin/systemctl ]; then /bin/systemctl enable mysqld; else /sbin/chkconfig mysqld on; fi | /usr/bin/logger -t "INSTALLER"
/usr/bin/logger -t "INSTALLER" "=========== Installing HOMER DB: databases";
(cat %{_datadir}/sipcapture/sql/homer_databases.sql | %{?el7:/usr}/sbin/mysqld --user=mysql --datadir=%{DBDIR} --bootstrap) 2>&1 | /usr/bin/logger -t "INSTALLER";
for s in configuration data statistic; do ((echo "use homer_$s;" ; cat %{_datadir}/sipcapture/sql/schema_$s.sql) | %{?el7:/usr}/sbin/mysqld --user=mysql --datadir=%{DBDIR} --bootstrap) 2>&1 | /usr/bin/logger -t "INSTALLER"; done;
if [ "$(stat -c %d:%i /)" == "$(stat -c %d:%i /proc/1/root/.)" ]; then
    /usr/bin/logger -t "INSTALLER" "=========== Starting local MySQL server"
    %{?el6:/sbin/service mysqld start}%{?el7:/bin/systemctl start mysqld} | /usr/bin/logger -t "INSTALLER"
fi
# Kamailio stuff
/usr/bin/logger -t "INSTALLER" "=========== Disable native Kamailio server";
if [ -e /sbin/chkconfig ]; then /sbin/chkconfig kamailio off; else /usr/bin/logger -t "INSTALLER" "WARNING: Please, manually diable kamailio service!!!"; fi 2>&1 | /usr/bin/logger -t "INSTALLER"
/usr/bin/logger -t "INSTALLER" "=========== Enable SIPCAPTURE Kamailio server";
if [ -e /bin/systemctl ]; then /bin/systemctl enable sipcapture; else /sbin/chkconfig sipcapture on; fi 2>&1 | /usr/bin/logger -t "INSTALLER"
if [ "$(stat -c %d:%i /)" == "$(stat -c %d:%i /proc/1/root/.)" ]; then
    /usr/bin/logger -t "INSTALLER" "=========== Start SIPCAPTURE Kamailio server";
    %{?el6:/sbin/service sipcapture start}%{?el7:/bin/systemctl start sipcapture} | /usr/bin/logger -t "INSTALLER"
fi

%post httpd
/usr/bin/logger -t "INSTALLER" "=========== Installing SELinux policies"
for selinuxvariant in %{selinux_variants}
do
	/usr/sbin/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/sipcapture-dashboards.pp &> /dev/null || :
done
/sbin/fixfiles -R sipcapture restore || :
/sbin/restorecon -R %{_localstatedir}/cache/sipcapture || :


/usr/bin/logger -t "INSTALLER" "=========== Enable HTTP server";
if [ -e /bin/systemctl ]; then /bin/systemctl enable httpd; else /sbin/chkconfig httpd on; fi
/usr/bin/logger -t "INSTALLER" "Starting local HTTP server"
%{?el6:/sbin/service httpd start}
%{?el7:/bin/systemctl start httpd}

%post nginx
/usr/bin/logger -t "INSTALLER" "=========== Installing SELinux policies"
for selinuxvariant in %{selinux_variants}
do
	/usr/sbin/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/sipcapture-dashboards.pp &> /dev/null || :
	/usr/sbin/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/nginx.pp &> /dev/null || :
	/usr/sbin/semodule -s ${selinuxvariant} -i %{_datadir}/selinux/${selinuxvariant}/php-fpm.pp &> /dev/null || :
done
/sbin/fixfiles -R sipcapture restore || :
/sbin/restorecon -R %{_localstatedir}/cache/sipcapture || :

HOSTNAME=`/bin/hostname`
/usr/bin/logger -t "INSTALLER" "=========== Virtual HTTP host set to : $HOSTNAME"
/bin/sed -i "s/<HOSTNAME>/$HOSTNAME/g" %{_sysconfdir}/nginx/conf.d/sipcapture.conf 
/bin/chown -R nginx:nginx %{webroot}
/usr/bin/logger -t "INSTALLER" "=========== Enable HTTP server";
if [ -e /bin/systemctl ]; then /bin/systemctl enable nginx; else /sbin/chkconfig nginx on; fi
if [ -e /bin/systemctl ]; then /bin/systemctl enable php-fpm; else /sbin/chkconfig php-fpm on; fi
/usr/bin/logger -t "INSTALLER" "=========== Starting local HTTP server"
/sbin/service nginx start
/sbin/service php-fpm start

%postun nginx
if [ $1 -eq 0 ] ; then
  /usr/bin/logger -t "INSTALLER" "=========== Installing SELinux policies"
  for selinuxvariant in %{selinux_variants}
  do
    /usr/sbin/semodule -s ${selinuxvariant} -r mymodule &> /dev/null || :
  done
  /sbin/fixfiles -R sipcapture| :
  [ -d %{_localstatedir}/cache/sipcapture ]
    /sbin/restorecon -R %{_localstatedir}/cache/sipcapture &> /dev/null || :
fi

%postun httpd
if [ $1 -eq 0 ] ; then
  /usr/bin/logger -t "INSTALLER" "=========== Installing SELinux policies"
  for selinuxvariant in %{selinux_variants}
  do
    /usr/sbin/semodule -s ${selinuxvariant} -r mymodule &> /dev/null || :
  done
  /sbin/fixfiles -R sipcapture| :
  [ -d %{_localstatedir}/cache/sipcapture ]
    /sbin/restorecon -R %{_localstatedir}/cache/sipcapture &> /dev/null || :
fi

%preun

%postun

%clean
rm -rf $RPM_BUILD_ROOT