%global _hardened_build 1

Summary:          Decode ADS-B airplane beacon traffic with an RTL-SDR dongle
Name:             dump1090
Version:          6.0
Release:          1%{?dist}
License:          GPLv2+
URL:              https://github.com/flightaware/dump1090
Source0:          https://github.com/flightaware/dump1090/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:          %{name}.service
Source2:          %{name}-sysconfig
Source3:          %{name}-tmpfiles.conf

%{?systemd_requires}
%if 0%{?fedora}
BuildRequires:    systemd-rpm-macros
%endif
BuildRequires:    systemd
BuildRequires:    rtl-sdr-devel
BuildRequires:    hackrf-devel
BuildRequires:    libusb-devel
BuildRequires:    ncurses-devel
BuildRequires:    gcc
Requires:         rtl-sdr
Requires:         hackrf

%description
dump1090 is a program that utilizes an RTL-SDR dongle
to collect, decode, and display ADS-B beacon/location
messages in your terminal, or run it as a daemon. A web
interface is provided, use a http server like lighttpd or
nginx, to see a continuously updated map of nearby planes.

%prep
%autosetup -p1

%build
# GCC 10 exposes ld errors for variables being defined in headers
export CFLAGS="-fcommon"
export DUMP1090_VERSION=%{version}
%make_build BLADERF=no
%make_build BLADERF=no faup1090

%install
mkdir -p %{buildroot}%{_tmpfilesdir}
install -m 0644 %{SOURCE3} %{buildroot}%{_tmpfilesdir}/%{name}.conf
install -d -m 0755 %{buildroot}/run/%{name}/
install -D -m644 %{SOURCE1} %{buildroot}/%{_unitdir}/dump1090.service
install -D -m644 %{SOURCE2} %{buildroot}/%{_sysconfdir}/sysconfig/dump1090

install -D faup1090 %{buildroot}/%{_libexecdir}/faup1090
install -D dump1090 %{buildroot}/%{_bindir}/dump1090
install -D view1090 %{buildroot}/%{_bindir}/view1090

# Move the config.js file into /etc/dump1090. Create symbolic link
# for the webpage.
mkdir -p %{buildroot}/%{_sysconfdir}/%{name}/
mv public_html/config.js %{buildroot}/%{_sysconfdir}/%{name}/
mkdir -p %{buildroot}/%{_datadir}/%{name}/html
pushd public_html
    find . -type f -exec chmod 644 {} \;
    ln -s %{_sysconfdir}/%{name}/config.js config.js
    cp -a * %{buildroot}/%{_datadir}/%{name}/html/
popd

%pre
getent group dump1090 >/dev/null 2>&1 || groupadd -r dump1090 2>&1 || :
getent passwd dump1090 >/dev/null 2>&1 || useradd -r -l -g dump1090 \
    -d %{_var}/empty/%{name} -s /sbin/nologin -c "Dump1090 daemon" dump1090 >/dev/null 2>&1 || :

%post
%systemd_post dump1090.service

%preun
%systemd_preun dump1090.service

%postun
%systemd_postun_with_restart dump1090.service

%files
%doc COPYING LICENSE README* debian/lighttpd
%license COPYING
%config(noreplace) %{_sysconfdir}/dump1090/config.js
%config(noreplace) %{_sysconfdir}/sysconfig/dump1090
%{_bindir}/dump1090
%{_bindir}/view1090
%{_libexecdir}/faup1090
%{_datadir}/%{name}
%{_unitdir}/dump1090.service
%{_tmpfilesdir}/%{name}.conf
%dir /run/%{name}/

%changelog
* Sat Sep 04 2021 Greg Wildman <greg@techno.co.za> - 6.0-1
- Update version

* Fri Oct 30 2020 Greg Wildman <greg@techno.co.za> - 4.0-2
- Update version

* Sat Jul 04 2020 Greg Wildman <greg@techno.co.za> - 3.8.1-2
- Fix build requires for el8

* Tue Jun 02 2020 Greg Wildman <greg@techno.co.za> - 3.8.1-1
- Update version

* Sun Apr 21 2019 Greg Wildman <greg@techno.co.za> - 3.7.0.1-1
- Update version

* Wed Sep 26 2018 Greg Wildman <greg@techno.co.za> - 3.6.3-2
- Change over to FlightAware dump1090-fa fork.
- Add curses as build dependency.

* Sat Aug 18 2018 Greg Wildman <greg@techno.co.za> - 20180510gitfb5942d-3
- Added outstanding pull requests
- Moved web page config to /etc

* Sat Aug 18 2018 Greg Wildman <greg@techno.co.za> - 20180510gitfb5942d-1
- Update to latest git master
- Moved user out of /home

* Mon Mar 21 2016 Benji Wiebe <benjiwiebe_fedoraproject.org> - 20160303git85aa200-5
- Changed version format in changelog
- Marked config file as config(noreplace) file in spec

* Fri Mar 18 2016 Benji Wiebe <benjiwiebe_fedoraproject.org> - 20160303git85aa200-4
- Reworded description

* Thu Mar 17 2016 Benji Wiebe <benjiwiebe_fedoraproject.org> - 20160303git85aa200-3
- Changed permissions on .service file
- Minor improvements in spec file

* Wed Mar 16 2016 Benji Wiebe <benjiwiebe_fedoraproject.org> - 20160303git85aa200-2
- Added a description
- Included RPM ownership of /usr/share/dump1090