File dnstap-bgp.spec of Package dnstap-bgp

%define realname dnstap-bgp
%define realver  1.1.0
%define srcext   tar.gz

%if ! 0%{?go_os:1}
%define go_os %(go env GOOS)
%endif
%if ! 0%{?go_arch:1}
%define go_arch %(go env GOARCH)
%endif

# Common info
Name:          %{realname}
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       MPL-2.0
Group:         System/Management
URL:           https://github.com/blind-oracle/dnstap-bgp
Summary:       Announce domains captured from DNSTap over BGP

# Build-time parameters
BuildRequires: go
BuildRoot:     %{_tmppath}/%{name}-root
Source:        https://codeload.github.com/blind-oracle/dnstap-bgp/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# go mod vendor -v && tar -Jcvf ../vendor.tar.xz vendor && rm -rf vendor/
Source11:      vendor.tar.xz

%description
This daemon was created to solve the problem of manipulating traffic based on
domain names instead of IP addresses. It does this by intercepting DNS replies
and exporting the resolved IPs using BGP protocol. The BGP peers can then use
this information to influence the traffic flow.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a11

# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
export GOPATH=$(pwd -P)/.gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
go build -v -mod=vendor -buildmode=pie \
    -gcflags=all=-dwarf=false \
    -ldflags='all=-s -w -X main.version=%{version}' \
    -o bin/dnstap-bgp

# Install built stuff
%install
%{__sed} -i '/^After/ a\Before=unbound.service' deploy/dnstap-bgp.service
%{__install} -D -m0755 bin/dnstap-bgp %{buildroot}%{_bindir}/dnstap-bgp
%{__install} -D -m0644 deploy/dnstap-bgp.conf %{buildroot}%{_sysconfdir}/dnstap-bgp/dnstap-bgp.conf
%{__install} -D -m0644 deploy/dnstap-bgp %{buildroot}%{_sysconfdir}/default/dnstap-bgp
%{__install} -D -m0644 deploy/dnstap-bgp.service %{buildroot}%{_unitdir}/dnstap-bgp.service
%{__install} -d -m0755 %{buildroot}/var/cache/dnstap-bgp
%{__sed} -ri \
    -e 's|/var/cache/domains.txt|%{_sysconfdir}/dnstap-bgp/domains.txt|' \
    -e 's|/var/cache/dnstap-bgp\.db|/var/cache/dnstap-bgp/cache.db|' \
    %{buildroot}%{_sysconfdir}/dnstap-bgp/dnstap-bgp.conf

# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

# Files
%files
%defattr(-,root,root)
%license LICENSE
%doc README.md
%{_bindir}/dnstap-bgp
%dir %{_sysconfdir}/dnstap-bgp
%config(noreplace) %{_sysconfdir}/dnstap-bgp/dnstap-bgp.conf
%config(noreplace) %{_sysconfdir}/default/dnstap-bgp
%{_unitdir}/dnstap-bgp.service
%dir /var/cache/dnstap-bgp

%if "%{expand:%_vendor}" == "suse"
%pre
%{service_add_pre dnstap-bgp.service}

%post
%{service_add_post dnstap-bgp.service}

%preun
%{service_del_preun dnstap-bgp.service}

%postun
%{service_del_postun dnstap-bgp.service}
%endif

%changelog
openSUSE Build Service is sponsored by