Name:           @PACKAGE_NAME@
Version:        @PACKAGE_VERSION@
Release:        1%{?dist}
Summary:        A motion detection system

Group:          Applications/Multimedia
License:        GPLv2+
URL:            https://motion-project.github.io/
Source0:        https://github.com/Motion-Project/motion
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

BuildRequires:  libjpeg-devel ffmpeg-devel zlib-devel
#This requires comes from the startup script, it will be there until motion supports libv4l calls in the code
Requires: libv4l
Requires(post): chkconfig
Requires(preun): chkconfig initscripts
Requires(postun): initscripts

%description
Motion is a software motion detector. It grabs images from video4linux devices
and/or from webcams (such as the axis network cameras). Motion is the perfect
tool for keeping an eye on your property keeping only those images that are
interesting. Motion is strictly command line driven and can run as a daemon
with a rather small footprint. This version is built with ffmpeg support but
without MySQL and PostgreSQL support.

%prep
%setup -q

%build
%configure --sysconfdir=%{_sysconfdir}/%{name} --without-optimizecpu --with-ffmpeg --without-mysql --without-pgsql
make %{?_smp_mflags}

%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
#We rename the configuration file
mv %{buildroot}%{_sysconfdir}/%{name}/motion-dist.conf %{buildroot}%{_sysconfdir}/%{name}/motion.conf
#We change the PID file path to match the one in the startup script
sed -i 's|/var/run/motion/motion.pid|/var/run/motion.pid|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
#We remove SQL directives in the configuration file, as we don't use them
sed -i 's|sql_log_image|; sql_log_image|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
sed -i 's|sql_log_snapshot|; sql_log_snapshot|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
sed -i 's|sql_log_mpeg|; sql_log_mpeg|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
sed -i 's|sql_log_timelapse|; sql_log_timelapse|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
sed -i 's|sql_query|; sql_query|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
#We set the log file and target directory - logging is for 3.3 branch
sed -i 's|;logfile|logfile /var/log/motion.log|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
sed -i 's|target_dir /usr/local/apache2/htdocs/cam1|target_dir /var/motion|g' %{buildroot}%{_sysconfdir}/%{name}/motion.conf
#We install our startup script
install -D -m 0755 motion.init-Fedora %{buildroot}%{_initrddir}/%{name}

%post
#We add the motion init script to the services when installing
/sbin/chkconfig --add %{name}

%preun
#We stop the service and remove it from init scripts when erasing
if [ $1 = 0 ] ; then
    /sbin/service %{name} stop >/dev/null 2>&1
    /sbin/chkconfig --del %{name}
fi

%postun
#We restart the service during an upgrade
if [ "$1" -ge "1" ] ; then
    /sbin/service %{name} condrestart >/dev/null 2>&1
fi

%clean
rm -rf %{buildroot}

%files
#Permissions are bogus upstream, we need to be sure to set them here
%defattr (-,root,root,-)
%dir %{_sysconfdir}/%{name}
%dir %{_datadir}/%{name}-%{version}
%dir %{_datadir}/%{name}-%{version}/examples
%doc CHANGELOG COPYING CREDITS INSTALL README motion_guide.html
%attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/motion-dist.conf
%attr(0755,root,root) %{_datadir}/%{name}-%{version}/examples/motion.init-Debian
%attr(0755,root,root) %{_datadir}/%{name}-%{version}/examples/motion.init-FreeBSD.sh
%attr(0755,root,root) %{_datadir}/%{name}-%{version}/examples/motion.init-Fedora
%attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread1.conf
%attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread2.conf
%attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread3.conf
%attr(0644,root,root) %{_datadir}/%{name}-%{version}/examples/thread4.conf
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/%{name}/motion.conf
%attr(0755,root,root) %{_bindir}/motion
%attr(0644,root,root) %{_mandir}/man1/motion.1*
%attr(0755,root,root) %{_initrddir}/%{name}

%changelog
* Thu Mar 06 2010 Steven Moix <steven.moix@axianet.ch> - 3.2.12-1
- New upstream release, important bugfixes only

* Wed Oct 21 2009 Thorsten Leemhuis <fedora [AT] leemhuis [DOT] info> - 3.2.11.1-3
- rebuild for new ffmpeg

* Tue Aug 11 2009 Steven Moix <steven.moix@axianet.ch> - 3.2.11.1-1
- Drop patch for ffmpeg 0.5 compatibility
- Drop ffmpeg detection patch
- Moved default output directory to /var/motion
- New startup script with added v4l2convert to support more cameras - https://bugzilla.rpmfusion.org/show_bug.cgi?id=681
- Fix Segfault on reload or quit for vloopback (maybe other v4l1 devices too)
- Fix fd leaks in external pipe
- Avoid possible stack smashing in v4l_open_vidpipe()
- Fix segfault for new libjpeg v7

* Mon Jul 06 2009 Steven Moix <steven.moix@axianet.ch> - 3.3.0-1
- SPEC Preparation for the 3.3 branch

* Sun Jun 05 2009 Steven Moix <steven.moix@axianet.ch> - 3.2.11-5
- Patch and rebuild for ffmpeg 0.5

* Sun Mar 29 2009 Thorsten Leemhuis <fedora [AT] leemhuis [DOT] info> - 3.2.11-4
- rebuild for new F11 features

* Wed Mar 18 2009 Steven Moix <steven.moix@axianet.ch> - 3.2.11-3
- Even more corrected init script thanks to Stewart Adam

* Sun Mar 15 2009 Steven Moix <steven.moix@axianet.ch> - 3.2.11-2
- Removed the ffmpeg requires
- Corrected the spec file
- New init script with a corrected start() function and LSB header support

* Tue Mar 03 2009 Steven Moix <steven.moix@axianet.ch> - 3.2.11-1
- Updated to Fedora 10 standard

* Sun Sep 18 2005 Kenneth Lavrsen <kenneth@lavrsen.dk> - 3.2.4-1
- Generic version of livna spec file replacing the old less optimal specfile.

* Thu Sep 15 2005 Dams <anvil[AT]livna.org> - 3.2.3-0.lvn.1
- Initial released based upon upstream spec file
