File dnscrypt-proxy2.spec of Package dnscrypt-proxy2
#
# spec file for package dnscrypt-proxy2
#
# Copyright (c) 2018-2019 cunix
#
# 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.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%global provider github
%global provider_tld com
%global project jedisct1
%global repo dnscrypt-proxy
%global provider_prefix %{provider}.%{provider_tld}/%{project}/%{repo}
%define systemd_service %{repo}.service
%define systemd_socket %{repo}.socket
%define vendor_lic_dir vendored
Name: %{repo}2
Version: 2.0.25
Release: 0
Summary: Proxy for encrypted DNS protocols
# Vendored packages might use different License
# Those are packaged in the license directory "vendored"
License: ISC
Group: Productivity/Networking/DNS/Utilities
Url: https://%{provider_prefix}
Source0: %{repo}-%{version}.tar.gz
Source1: rpmlintrc
# Files to use with sed.
Source2: example-dnscrypt-proxy.toml.sed
# Systemd Units
Source3: dnscrypt-proxy.service
Source4: dnscrypt-proxy.socket
# Help output as man page.
Source5: dnscrypt-proxy-help
# Find licenses of vendored packages.
Source6: find_licenses.sh
# Install licenses of vendored packages.
Source7: install_licenses.sh
# Some words
Source8: README.openSUSE
BuildRoot: %{_tmppath}/%{repo}-%{version}-build
# for strings.Builder
BuildRequires: go >= 1.10
BuildRequires: golang-packaging
BuildRequires: xz
BuildRequires: fdupes
BuildRequires: shadow
BuildRequires: systemd-rpm-macros
# for daemon group/user
Requires(pre): shadow
# for DNS over HTTPS with certificate validation
# but not needed for DNSCrypt
Recommends: ca-certificates
# Not sure if using both packages is problematic (e. g. binary names are the same).
# To reduce possible conflicts, this packages uses sometimes "dnscrypt-proxy"
# and otherwise "dnscrypt-proxy2" as directory names, etc.
Provides: %{repo} = %{version}
Obsoletes: %{repo} < 2.0.0
%{go_nostrip}
%{go_provides}
%description
A flexible DNS proxy, with support for encrypted DNS protocols such as
DNSCrypt v2 and DNS-over-HTTP/2.
Written in go, it includes all the major features from version 1.9.5,
with improved reliability, flexibility, usability and performance.
%prep
%setup -q -n %{repo}-%{version}
# Find licenses of vendored packages and prepare for installation
bash %{SOURCE6} %{vendor_lic_dir}
%build
# duplicate original config file
cp ./%{repo}/example-dnscrypt-proxy.toml ./dnscrypt-proxy.toml.default
# Edit default port and file locations
sed -i -f %{SOURCE2} ./dnscrypt-proxy.toml.default > /dev/null
# duplicate edited config file
cp ./dnscrypt-proxy.toml.default ./dnscrypt-proxy.toml
# Delete "example" to prevent fdupes from deleting the backup config file if run for buildroot
sed -i "s/## This is an example configuration file./## This is a configuration file./" ./dnscrypt-proxy.toml
export GOPATH=$HOME/go
mkdir -pv $HOME/go/src/%{repo}
rm -rf $HOME/go/src/%{repo}/*
cp -avr * $HOME/go/src/%{repo}
cd $HOME/go/src/%{repo}/%{repo}
# upstream does:
# env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w"
go build -v
%pre
# group and user
getent group %{repo} >/dev/null || %{_sbindir}/groupadd -r %{repo}
getent passwd %{repo} >/dev/null || %{_sbindir}/useradd -r -g %{repo} -d %{_localstatedir}/lib/%{repo} -s /bin/false -c "dnscrypt-proxy2" %{repo}
%service_add_pre %{systemd_service}
%service_add_pre %{systemd_socket}
%post
%service_add_post %{systemd_service}
%service_add_post %{systemd_socket}
%preun
%service_del_preun %{systemd_service}
%service_del_preun %{systemd_socket}
%postun
%service_del_postun %{systemd_service}
%service_del_postun %{systemd_socket}
%install
# Binary
install -D -m 0755 $HOME/go/src/%{repo}/%{repo}/%{repo} %{buildroot}%{_bindir}/%{repo}
# Systemd
install -D -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{systemd_service}
install -D -m 0644 %{SOURCE4} %{buildroot}%{_unitdir}/%{systemd_socket}
# service link
install -d -m 0755 %{buildroot}%{_sbindir}
ln -sf %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{repo}
#Config file examples
install -D -m 0644 ./%{repo}/example-dnscrypt-proxy.toml %{buildroot}/%{_docdir}/%{name}/example-dnscrypt-proxy.toml
install -D -m 0644 ./dnscrypt-proxy.toml.default %{buildroot}/%{_docdir}/%{name}/dnscrypt-proxy.toml.default
install -D -m 0644 ./%{repo}/example-blacklist.txt %{buildroot}/%{_docdir}/%{name}/example-blacklist.txt
install -D -m 0644 ./%{repo}/example-cloaking-rules.txt %{buildroot}/%{_docdir}/%{name}/example-cloaking-rules.txt
install -D -m 0644 ./%{repo}/example-forwarding-rules.txt %{buildroot}/%{_docdir}/%{name}/example-forwarding-rules.txt
install -D -m 0644 ./%{repo}/example-whitelist.txt %{buildroot}/%{_docdir}/%{name}/example-whitelist.txt
# The config file
install -D -m 0644 ./dnscrypt-proxy.toml %{buildroot}/%{_sysconfdir}/%{repo}/dnscrypt-proxy.toml
# Working Directory
install -d -m 750 %{buildroot}%{_localstatedir}/lib/%{repo}
# Vendor Licenses
install -d -m 0755 %{buildroot}%{_licensedir}/%{name}/%{vendor_lic_dir}
bash %{SOURCE7} %{vendor_lic_dir} %{buildroot}/%{_licensedir}/%{name}/%{vendor_lic_dir}
# help output as man page
install -D -m 0644 %{SOURCE5} %{buildroot}/%{_mandir}/man1/%{repo}.1
# Some tips and hints from maintainer. Improvements and feedback welcome!
cp %{SOURCE8} README.openSUSE
%fdupes %{buildroot}
%check
%files
%defattr(-,root,root)
%{_bindir}/dnscrypt-proxy
%{_sbindir}/rc%{repo}
%{_unitdir}/%{systemd_service}
%{_unitdir}/%{systemd_socket}
%dir %attr(0750,%{repo},%{repo}) %{_localstatedir}/lib/%{repo}
%dir %{_sysconfdir}/%{repo}
%config(noreplace) %{_sysconfdir}/%{repo}/dnscrypt-proxy.toml
%{_mandir}/man1/%{repo}.1*
%doc README.md ChangeLog README.openSUSE
%license LICENSE
%dir %attr(0755,root,root) %{_licensedir}/%{name}/%{vendor_lic_dir}
%{_licensedir}/%{name}/%{vendor_lic_dir}/*
%{_docdir}/%{name}/example-dnscrypt-proxy.toml
%{_docdir}/%{name}/dnscrypt-proxy.toml.default
%{_docdir}/%{name}/example-blacklist.txt
%{_docdir}/%{name}/example-cloaking-rules.txt
%{_docdir}/%{name}/example-forwarding-rules.txt
%{_docdir}/%{name}/example-whitelist.txt
%changelog