File ZoneMinder.spec of Package ZoneMinder

#
# spec file for package ZoneMinder
#
# package are under the same license as the package itself.
#
# Please submit bugfixes or comments to monex@liquid-co.de
#

# norootforbuild

%bcond_with mp_package
%bcond_without debug

%if %{with mp_package}
Name:           ZoneMinder-MP
%else
Name:           ZoneMinder
%endif
BuildRequires:  update-desktop-files apache2 pcre-devel libjpeg-devel gcc gcc-c++ perl perl-Archive-Zip perl-DBI perl-DBD-mysql perl-Crypt-SSLeay perl-XML-Parser perl-libwww-perl perl-Date-Manip perl-MIME-Lite perl-MIME-tools perl-Sys-Mmap vorbis-tools unzip libmysqlclient-devel libgcrypt-devel libgnutls-devel perl-macros fdupes cmake libcurl-devel polkit-devel systemd ffmpeg-4-libavcodec-devel ffmpeg-4-libswscale-devel ffmpeg-4-libswresample-devel ffmpeg-4-libpostproc-devel ffmpeg-4-libavutil-devel ffmpeg-4-libavresample-devel ffmpeg-4-libavformat-devel ffmpeg-4-libavfilter-devel ffmpeg-4-libavdevice-devel vlc-devel
BuildRequires:  -post-build-checks -rpmlint-Factory
BuildRequires:  php7 apache2-mod_php7 php7-mysql php7-bz2 php7-gd php7-zlib php7-iconv php7-sockets

%if %{with mp_package}
BuildRequires:  faac libfaad-devel lame libxvidcore-devel libx264-devel
%endif

%{perl_requires}
%{?systemd_requires}
Requires:       apache2 php7 php7-mbstring apache2-mod_php7 php7-mysql php7-bz2 php7-gd php7-zlib php7-iconv php7-sockets php7-zip php7-APCu netpbm  mysql perl-Archive-Tar perl-Archive-Zip perl-DBI perl-DBD-mysql perl-Crypt-SSLeay perl-XML-Parser perl-libwww-perl perl-Date-Manip perl-MIME-Lite perl-MIME-tools perl-Sys-Mmap zip perl-PHP-Serialization perl-Sys-MemInfo perl-Sys-CPU perl-Data-UUID perl-Class-Std-Fast perl-SOAP-WSDL perl-Number-Bytes-Human perl-IO-Socket-Multicast perl-Cpanel-JSON-XS perl-JSON-MaybeXS perl-Crypt-Eksblowfish perl-Data-Entropy
Requires:       python3-zm_database_init >= 3.2.1
Requires(post): permissions
Requires(pre):  shadow
%if %{with mp_package}
Requires:       ffmpeg lame
%endif

Recommends:     perl-Device-SerialPort perl-Net-SFTP-Foreign perl-Expect php7-gd

%if %{with mp_package}
Conflicts:      ZoneMinder
%endif

License:        GPL
Group:          Productivity/Networking/Web/Servers
Summary:        A Linux based camera monitoring and analysis tool
Version:        1.34.21
Release:        2.1
Packager:       Monex <monex@liquid-co.de>
URL:            http://www.zoneminder.com/
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
Source0:        https://github.com/ZoneMinder/zoneminder/archive/%{version}/ZoneMinder-%{version}.tar.gz
Source1:        zm.service
Source2:        zm.logrotate
Source3:        README.SuSE
Source4:        zm.apache
Source5:        permissions
Source6:        permissions.secure
Source7:        permissions.paranoid
Source8:        MooTools-Core-1.6.0-compat.js
Source9:        LICENSE.mootools
Source10:       zm_tempfiles.conf
Source11:       zoneminder_mysql_settings.cnf
Source12:       crud-3.1.0-zm.tar.gz
Source13:       CakePHP-Enum-Behavior-1.0-zm.tar.gz
Patch1:         zm.conf.patch
Patch2:         zm_database_default_config.patch
Patch3:         ignore_signal_on_config_write.patch
Patch4:         reload_config.patch
Patch5:         fix-ZM_VERSION-already-defined-error.patch
Patch6:         systemd-name-conventions.patch
Patch7:         move-include-sys-uio.h-outside-defined-BSD-block.patch

%description
ZoneMinder is an integrated set of applications which provide a complete surveillance solution allowing capture, 
analysis, recording and monitoring of any CCTV or security cameras attached to a Linux based machine. 
It is designed to run on distributions which support the Video For Linux (V4L) interface and has been tested 
with video cameras attached to BTTV cards, various USB cameras and also supports most IP network cameras.


%debug_package
%prep

%if %{with mp_package}
%setup -q -n zoneminder-%{version}
%else
%setup -q -n zoneminder-%{version}
%endif
cp -a %SOURCE3 .
cp -a %SOURCE9 .
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1

# add ZM_VERSION to config file
cat >> zm.conf.in << EOF

# Current version of ZoneMinder
ZM_VERSION=%{version}

EOF

#install Crud
pushd web/api/app/Plugin/Crud/
tar xfvz %SOURCE12 --strip 1
popd

#install enum behaviour
pushd web/api/app/Plugin/CakePHP-Enum-Behavior
tar xfvz %SOURCE13 --strip 1
popd


%build
export CFLAGS=$RPM_OPT_FLAGS
export CXXFLAGS=$RPM_OPT_FLAGS

cmake \
  -DZM_DB_HOST=localhost \
  -DZM_DB_NAME=zm \
  -DZM_DB_USER=zm_admin \
  -DZM_RUNDIR=/run/zm \
  -DZM_TMPDIR=/tmp \
  -DZM_LOGDIR=/var/log/zm \
  -DZM_MYSQL_ENGINE=InnoDB \
  -DZM_WEBDIR=/usr/share/zoneminder/www \
  -DZM_CGIDIR=/usr/lib/zoneminder/cgi-bin \
  -DZM_LOGDIR=/var/log/zm \
  -DZM_RUNDIR=/run/zm \
  -DZM_SOCKDIR=/run/zm \
  -DZM_NO_FFMPEG=OFF \
  -DENABLE_MMAP=yes \
  -DZM_WEB_USER=wwwrun \
  -DZM_WEB_GROUP=www \
  -DCMAKE_INSTALL_PREFIX=/usr

%{__make} %{?_smp_mflags} VERBOSE=1

%install
make DESTDIR=$RPM_BUILD_ROOT install

# rm -f %buildroot/srv/www/htdocs/zm/api/.editorconfig
# rm -f %buildroot/srv/www/htdocs/zm/api/.gitattributes
# rm -f %buildroot/srv/www/htdocs/zm/api/.gitignore

%perl_process_packlist
%perl_gen_filelist
%__install -m 700 -d %buildroot/usr/share/zoneminder/db
%__install -m 600 db/*.sql %buildroot/usr/share/zoneminder/db

for f in %{_sysconfdir}/logrotate.d %{_sysconfdir}/init.d /usr/sbin %{_sysconfdir}/cron.hourly/ /var/log %{_sysconfdir}/apache2/vhosts.d %{_sysconfdir}/permissions.d/ /run/zm /var/cache/zoneminder /var/lib/zoneminder/events /var/lib/zoneminder/images
do
    %__install -d %buildroot/$f
done

for f in %{_unitdir} /usr/lib/tmpfiles.d
do
  %__install -d %buildroot/$f
done

%__install -m 644 %{S:1} %{buildroot}/%{_unitdir}
%__install -m 644 %{S:10} %{buildroot}/usr/lib/tmpfiles.d
%__install -d -m 750 %{buildroot}/%{_sysconfdir}/my.cnf.d/
%__install -m 640 %{S:11} %{buildroot}/%{_sysconfdir}/my.cnf.d/zoneminder_mysql_settings.cnf

%__install -m 775 -d %buildroot/var/log/zm
%__install -m 644 %{S:2} %buildroot/%{_sysconfdir}/logrotate.d/zm
%__install -m 644 %{S:4} %buildroot/%{_sysconfdir}/apache2/vhosts.d/zm.conf

%__install -m 644 %{S:5} %{buildroot}%{_sysconfdir}/permissions.d/%{name}
%__install -m 644 %{S:5} %{buildroot}%{_sysconfdir}/permissions.d/%{name}.easy

%__install -m 644 %{S:6} %{buildroot}%{_sysconfdir}/permissions.d/%{name}
%__install -m 644 %{S:7} %{buildroot}%{_sysconfdir}/permissions.d/%{name}

%__install -m 644 %{S:8} %buildroot/usr/share/zoneminder/www/mootools.js

echo %version > %buildroot/usr/share/zoneminder/version


%fdupes -s $RPM_BUILD_ROOT/%_mandir
%fdupes $RPM_BUILD_ROOT

%clean
rm -rf $RPM_BUILD_ROOT

%files -f %{name}.files
%defattr(-,root,root)
%dir /usr/share/zoneminder
%dir /usr/share/zoneminder/db
/usr/share/zoneminder/version
/usr/share/zoneminder/icons/*
/usr/share/zoneminder/db/*.sql
/usr/share/polkit-1/actions/com.zoneminder.systemctl.policy
/usr/share/polkit-1/rules.d/com.zoneminder.systemctl.rules
%{_sysconfdir}/apache2/vhosts.d/*.conf
%dir /usr/share/zoneminder/www/
/usr/share/zoneminder/www/*
/usr/lib/zoneminder/cgi-bin/*
/usr/share/applications/zoneminder.desktop

%{_unitdir}/*
/usr/lib/tmpfiles.d/*

%defattr(-,wwwrun,www)
%dir /var/cache/zoneminder
%dir /var/lib/zoneminder/events
%dir /var/lib/zoneminder/images
%ghost /run/zm

%defattr(-,root,mysql)
%dir %{_sysconfdir}/my.cnf.d/
%config(noreplace) %{_sysconfdir}/my.cnf.d/zoneminder_mysql_settings.cnf

%defattr(-,root,root)
%_sysconfdir/permissions.d/*
%{_sysconfdir}/logrotate.d/zm
%doc README* LICENSE*
%defattr(640,root,www)
%config(noreplace) %{_sysconfdir}/zm.conf
%config(noreplace) %{_sysconfdir}/conf.d/*
%defattr(-,root,www)
%dir /var/log/zm

%post
/sbin/ldconfig
touch /usr/share/zoneminder/lock
if [ -x /usr/sbin/a2enmod ]; then
  a2enmod -q php7 || a2enmod php7
  a2enmod -q rewrite || a2enmod rewrite
fi

%service_add_post zm.service
systemd-tmpfiles --create


%pre
/usr/bin/gpasswd -a wwwrun video >/dev/null 2>&1 || :
%service_add_pre zm.service

%preun
%stop_on_removal zm
if [ $1 -eq 0 ]; then
    if test -f /usr/share/zoneminder/lock ; then
        rm -f /usr/share/zoneminder/lock
    fi
fi

%service_del_preun zm.service

%postun
%insserv_cleanup
/sbin/ldconfig

%service_del_postun zm.service

%if %{with mp_package}
%changelog -n ZoneMinder-MP
%else
%changelog -n ZoneMinder
%endif
openSUSE Build Service is sponsored by