File AdGuardHome.spec of Package AdGuardHome

#
# spec file for package AdGuardHome
#
# Copyright (c) 2021 SUSE LLC
#
# 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/
#

%if 0%{?fedora_version}
%global _missing_build_ids_terminate_build 0
%global debug_package %{nil}
%endif

Name:           AdGuardHome
Version:        0.107.43
Release:        0
Summary:        Network-wide ads & trackers blocking DNS server
License:        GPL-3.0
URL:            https://github.com/AdguardTeam/AdGuardHome
Source0:        %{name}-%{version}.tar.xz
Source1:        vendor.tar.xz
Source2:        node_modules.tar.xz
Source4:        adguardhome.service
Source5:        adguardhome.xml
BuildRequires:  golang(API) = 1.20
%if 0%{?suse_version} >= 1550
BuildRequires:  nodejs20
BuildRequires:  npm20
%else
BuildRequires:  nodejs(abi) >= 14.0
BuildRequires:  npm >= 14.0
%endif
%if 0%{?suse_version}
BuildRequires:  yarn >= 1.22.5
%{?systemd_ordering}
%else
BuildRequires:  yarnpkg >= 1.22.5
BuildRequires:  systemd-rpm-macros
Requires:       systemd
%endif

Provides:       adguardhome

%description
AdGuard Home is a network-wide software for blocking ads & tracking. After you
set it up, it'll cover ALL your home devices, and you don't need any client-side
software for that.

%prep
%setup -q -a 1
%__tar xf %{S:2} -C client

%build
%define version_pkg "github.com/AdguardTeam/AdGuardHome/internal/version"
# ref https://github.com/AdguardTeam/AdGuardHome/issues/4595
export NODE_OPTIONS=--openssl-legacy-provider
npm --prefix client run build-prod
go generate -v -x ./...
go build -buildmode pie -ldflags="-s -w -X %{version_pkg}.version=v%{version} -X %{version_pkg}.channel=release"

%install
install -Dm 0755 -t %{buildroot}%{_bindir} %{name}
install -Dm 0644 -t %{buildroot}%{_unitdir} %{S:4}
install -Dm 0644 -t %{buildroot}%{_prefix}/lib/firewalld/services/ %{S:5}
mkdir -p %{buildroot}/var/lib/adguardhome/

%pre
%service_add_pre adguardhome.service
%preun
%service_del_preun adguardhome.service
%post
if [ "$1" = 1 ]; then
    groupadd --system adguardhome
    useradd --create-home --system --gid adguardhome -d /var/lib/adguardhome -s /sbin/nologin adguardhome
    chown -R adguardhome:adguardhome /var/lib/adguardhome
fi
%systemd_post adguardhome.service
%postun
if [ "$1" = 0 ]; then
    userdel -f adguardhome
    systemctl daemon-reload
    rm -rf /var/lib/adguardhome
fi
%service_del_postun adguardhome.service

%files
%license LICENSE.txt
%doc CHANGELOG.md AGHTechDoc.md HACKING.md README.md
%{_bindir}/%{name}
%{_unitdir}/adguardhome.service
%{_prefix}/lib/firewalld/services/adguardhome.xml
%dir %{_prefix}/lib/firewalld
%dir %{_prefix}/lib/firewalld/services

%changelog

openSUSE Build Service is sponsored by