File AdGuardHome.spec of Package AdGuardHome

#
# spec file for package AdGuardHome
#
# Copyright (c) 2022 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.67
Release:        0
Summary:        Network-wide ads & trackers blocking DNS server
License:        GPL-3.0-only
Group:          Productivity/Networking/Other
URL:            https://github.com/AdguardTeam/AdGuardHome
Source0:        %{name}-%{version}.tar.gz
Source1:        vendor.tar.gz
Source2:        node_modules.tar.gz
#Source3:        node_modules2.tar.xz
Source4:        %{name}.service
Source5:        %{name}.xml
Source99:	%{name}-rpmlintrc
BuildRequires:  go >= 1.24
BuildRequires:  golang-packaging
BuildRequires:  firewall-macros
BuildRequires:  systemd-rpm-macros
BuildRequires:  nodejs(abi) >= 22.0
BuildRequires:  npm >= 22.0
%if 0%{?suse_version}
BuildRequires:  yarn >= 1.22.5
%{?systemd_ordering}
%else
BuildRequires:  yarnpkg >= 1.22.5
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 %{SOURCE2} -C client
#%%__tar xf %%{SOURCE3} -C client2

%build
%if 0%{?suse_version} > 1600 || ( 0%{?sle_version} >= 150600 && 0%{?is_opensuse} )
# Need for Tumbleweed and Leap 15.6
# Need to build for nodejs >= 17
# Without it rise up build error: Error: error:0308010C:digital envelope routines::unsupported
export NODE_OPTIONS=--openssl-legacy-provider
%endif

%define version_pkg "github.com/AdguardTeam/AdGuardHome/internal/version"
npm --prefix client run build-prod
# yarn --offline --cwd client2 build
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}
# systemd
install -Dm 0644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}.service
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}
# firewall
install -Dm 0644 %{SOURCE5} %{buildroot}%{_prefix}/lib/firewalld/services/%{name}.xml
# dirs
install -d %{buildroot}%{_sysconfdir}/%{name}/
install -d %{buildroot}%{_localstatedir}/lib/%{name}/
install -d %{buildroot}%{_localstatedir}/log/%{name}/


%pre
%service_add_pre %{name}.service
if [ "$1" = 1 ]; then
    groupadd --system adguardhome || :
    useradd --create-home --system --gid adguardhome -d %{_localstatedir}/lib/%{name} -s /sbin/nologin adguardhome || :
    chown -R adguardhome:adguardhome %{_localstatedir}/lib/%{name} || :
fi

%preun
%service_del_preun %{name}.service
if [ "$1" = 0 ]; then
    userdel -f adguardhome || :
    groupdel -f adguardhome || :
    rm -rf %{_localstatedir}/lib/%{name} || :
    rm -rf %{_localstatedir}/log/%{name} || :
fi

%post
%service_add_post %{name}.service
%firewalld_reload

%postun
%service_del_postun %{name}.service

%files
%license LICENSE.txt
%doc CHANGELOG.md AGHTechDoc.md HACKING.md README.md
%{_bindir}/%{name}
%{_unitdir}/%{name}.service
%{_sbindir}/rc%{name}
%{_prefix}/lib/firewalld/services/%{name}.xml
%dir %{_prefix}/lib/firewalld
%dir %{_prefix}/lib/firewalld/services
%defattr(640,adguardhome,adguardhome,750)
%{_sysconfdir}/%{name}/
%{_localstatedir}/lib/%{name}/
%{_localstatedir}/log/%{name}/

%changelog
openSUSE Build Service is sponsored by