%global forgeurl https://github.com/yggdrasil-network/yggdrasil-go
%global version 0.5.12
%global commit 73705ff09ddfef8b458390aafe84315671952f1a
%global date 20250220
%global gomodulesmode GO111MODULE=on
%global source_date_epoch_from_changelog 0
%global _enable_debug_packages 0
%forgemeta

Name: yggnet
Version: %{forgeversion}
Release: %{autorelease}
Summary: Yggdrasil overlay network
License: LGPL-3.0-only
URL: https://yggdrasil-network.github.io/
Source0: %{forgesource}
Source1: %{name}.sysusers
Source2: %{name}.howto
BuildRequires: git-core
BuildRequires: golang-bin
BuildRequires: go-rpm-macros
BuildRequires: systemd-rpm-macros

%description
Yggdrasil is an overlay mesh network that relies on IPv6.
Key features of this network:
- Supports large, complex or even Internet-scale topologies.
- Responds quickly to connection failures or mobility events.
- Provides end-to-end encryption for traffic over the network.
- Works entirely ad-hoc by design and completely decentralized.
- Supported on Linux, macOS, Windows, Android, iOS and more.

%prep
%forgesetup
%__sed -i -e 's/yggdrasil/%{name}/' src/config/defaults_linux.go
for SVC in yggdrasil yggdrasil-default-config
do %__sed -e '/^Description=/!s/yggdrasil/%{name}/g' \
contrib/systemd/${SVC}.service > ${SVC/yggdrasil/%{name}}.service
done

%build
export GOPROXY="https://proxy.golang.org,direct"
export GOFLAGS="-trimpath"
export GO_LDFLAGS="-s -w"
for CMD in yggdrasil yggdrasilctl
do %gobuild -o ${CMD/yggdrasil/%{name}} ./cmd/${CMD}
done

%install
for SVC in %{name} %{name}-default-config
do %__install -p -D -m 644 -t %{buildroot}%{_unitdir} ${SVC}.service
done
%__install -p -D -m 644 %{SOURCE1} %{buildroot}%{_sysusersdir}/%{name}.conf
%__install -p -D -m 755 -t %{buildroot}%{_bindir} %{name} %{name}ctl
%__install -p -D -m 644 -t %{buildroot}%{_pkgdocdir} %{SOURCE2} CHANGELOG.md README.md

%pre
%sysusers_create_compat %{SOURCE1}

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service

%files
%license LICENSE
%doc %{_pkgdocdir}
%{_sysusersdir}/*
%{_unitdir}/*
%{_bindir}/*