File basicstation.spec of Package basicstation
#
# spec file for package basicstation
#
# Copyright (c) 2020 Frank Kunz
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
%if "@BUILD_FLAVOR@" == ""
ExclusiveArch: do_not_build
%endif
%define package_name basicstation
%define user_name lora
Name: %{package_name}-@BUILD_FLAVOR@
Version: 2.0.6
Release: 0
Summary: The LoRaWAN Gateway Software
License: BSD-3-Clause
Group: Productivity/Networking/Other
Url: https://doc.sm.tc/station
Source0: https://github.com/lorabasics/basicstation/archive/%{package_name}-%{version}.tar.gz
Source2: https://github.com/Lora-net/lora_gateway/archive/lora_gateway-5.0.1.tar.gz
Source3: https://github.com/Lora-net/sx1302_hal/archive/sx1302_hal-2.1.0.tar.gz
Source4: basicstation.service
Source5: lora-user.conf
Source6: README-ttn-suse.md
Patch0: 0001-Exit-when-excessive-drift-workaround.patch
Patch3: 0001-build-with-mbedtls-3.x.patch
Patch4: 0001-tests-Use-python3.patch
Patch5: 0001-tests-Add-function-to-initialize-PKI.patch
%if "@BUILD_FLAVOR@" == "linuxusb"
Patch1: 0001-Added-USB-support-via-ftdi.patch
Patch2: 0001-Linux-USB-support.patch
BuildRequires: libmpsse-devel
BuildRequires: libftdi1-devel
%endif
BuildRequires: git
BuildRequires: systemd-rpm-macros
BuildRequires: sysuser-tools
BuildRequires: system-group-hardware
BuildRequires: mbedtls-devel
# SECTION test requirements
%ifarch x86_64
%if "@BUILD_FLAVOR@" != "corecell"
BuildRequires: lcov
BuildRequires: python3
BuildRequires: python3-aiohttp
BuildRequires: python3-websockets
BuildRequires: procps
BuildRequires: curl
BuildRequires: netcat
%endif
%endif
# /SECTION
%sysusers_requires
%systemd_requires
%description
LoRa Basics™ Station - The LoRaWAN Gateway Software.
%prep
%setup -q -n %{package_name}-%{version}
%patch -P 0 -p 1
%patch -P 3 -p 1
%patch -P 4 -p 1
%patch -P 5 -p 1
%if "@BUILD_FLAVOR@" == "linuxusb"
%patch -P 2 -p 1
%endif
# force local build (no cross compile)
sed -i 's/LOCAL_ARCH := $(shell gcc -dumpmachine)/LOCAL_ARCH=${ARCH.${platform}}/g' setup.gmk
# disable remote shell (https://github.com/lorabasics/basicstation/issues/93)
sed -i 's/CFG.std = logini_lvl=INFO tlsdebug ral_lgw/CFG.std = logini_lvl=INFO tlsdebug ral_lgw no_rmtsh/g' setup.gmk
# parallel build
sed -i 's/${MAKE} -C/${MAKE} %{?_smp_mflags} -C/g' deps/lgw/makefile
sed -i 's/${MAKE} -C/${MAKE} %{?_smp_mflags} -C/g' deps/lgw1302/makefile
sed -i 's/${MAKE} -C ${<D}/${MAKE} %{?_smp_mflags} -C ${<D}/g' makefile
# drop build of mbedtls and use distro lib
rm -rf deps/mbedtls
sed -i 's/= mbedtls/=/g' setup.gmk
# to avoid the download of additional git repos during the build add them here as compressed images
%if "@BUILD_FLAVOR@" == "corecell"
pushd deps/lgw1302
tar -xf %{_topdir}/SOURCES/sx1302_hal-2.1.0.tar.gz
popd
%else
pushd deps/lgw
tar -xf %{_topdir}/SOURCES/lora_gateway-5.0.1.tar.gz
%if "@BUILD_FLAVOR@" != "linux"
mv platform-linux platform-@BUILD_FLAVOR@
%endif
%if "@BUILD_FLAVOR@" == "linuxusb"
# Patch USB support for linux
pushd platform-@BUILD_FLAVOR@
%patch -P 1 -p 1
popd
pushd git-repo
%patch -P 1 -p 1
popd
%endif
popd
%endif
cp %{SOURCE6} .
%build
%sysusers_generate_pre %{SOURCE5} %{user_name}
# parallel build does not work here
%__make platform=@BUILD_FLAVOR@ variant=std V=1
%if "@BUILD_FLAVOR@" != "corecell"
pushd deps/lgw/platform-@BUILD_FLAVOR@/util_pkt_logger
%__make %{?_smp_mflags}
popd
%endif
%if "@BUILD_FLAVOR@" == "rpi"
echo 'KERNEL=="spidev*", GROUP="dialout", MODE="0660"' > 95-spidev.rules
echo 'spidev' > spidev.conf
%endif
%install
install -D -t %{buildroot}%{_bindir} build-@BUILD_FLAVOR@-std/bin/station
%if "@BUILD_FLAVOR@" != "corecell"
install -D -t %{buildroot}%{_bindir} deps/lgw/platform-@BUILD_FLAVOR@/util_pkt_logger/util_pkt_logger
strip %{buildroot}%{_bindir}/util_pkt_logger
%endif
install -m 644 -D -t %{buildroot}%{_unitdir}/ %SOURCE4
mkdir -p %{buildroot}%{_sysusersdir}
install -m 0644 %{SOURCE5} %{buildroot}%{_sysusersdir}/
mkdir -p %{buildroot}/var/lib/%{user_name}
%if "@BUILD_FLAVOR@" == "rpi"
install -m 644 -D -t %{buildroot}/usr/lib/udev/rules.d 95-spidev.rules
install -m 644 -D -t %{buildroot}/usr/lib/modules-load.d spidev.conf
%endif
strip %{buildroot}%{_bindir}/station
%check
# regression testing is limited on x86_64/armv7l arch only as
# there are side effects on VMs when emulating other archs.
###pushd regr-tests
# verbose output to console
###sed -i 's|./run-regression-tests|./run-regression-tests -v|g' makefile
###%__make
###popd
%pre -f %{user_name}.pre
%service_add_pre basicstation.service
%post
%service_add_post basicstation.service
%preun
%service_del_preun basicstation.service
%postun
%service_del_postun basicstation.service
%files -n %{name}
%doc CHANGELOG.md README.md README-ttn-suse.md
%{_bindir}/station
%if "@BUILD_FLAVOR@" != "corecell"
%{_bindir}/util_pkt_logger
%endif
%{_unitdir}/basicstation.service
%{_sysusersdir}/%{user_name}-user.conf
%attr(750,%{user_name},root) %dir /var/lib/%{user_name}
%if "@BUILD_FLAVOR@" == "rpi"
%dir /usr/lib/modules-load.d
%dir /usr/lib/udev
/usr/lib/modules-load.d/spidev.conf
/usr/lib/udev/rules.d/95-spidev.rules
%endif
%changelog