# Generated by rust2rpm 27
%bcond check 1

# prevent library files from being installed
%global __cargo_is_lib() 0

Version:        {{version}}
Name:           minecraft-server
Release:        %autorelease
Summary:        Wrapper for the Java and Bedrock Minecraft servers that adds proper systemd support

# https://docs.fedoraproject.org/en-US/packaging-guidelines/Rust/#_license_tags
# Output of %%{cargo_license_summary}
# 0BSD OR MIT OR Apache-2.0
# Apache-2.0
# Apache-2.0 OR BSL-1.0
# Apache-2.0 OR ISC OR MIT
# Apache-2.0 OR MIT
# (Apache-2.0 OR MIT) AND BSD-3-Clause
# Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT
# BSD-3-Clause
# CC0-1.0
# MIT
# MIT OR Apache-2.0
# MIT OR Apache-2.0 OR Zlib
# MIT OR Zlib OR Apache-2.0
# MPL-2.0
# Unlicense OR MIT
# Zlib
# Zlib OR Apache-2.0 OR MIT
License:        0BSD OR MIT OR Apache-2.0 AND Apache-2.0 AND Apache-2.0 OR BSL-1.0 AND Apache-2.0 OR ISC OR MIT AND Apache-2.0 OR MIT AND (Apache-2.0 OR MIT) AND BSD-3-Clause AND Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT AND BSD-3-Clause AND CC0-1.0 AND MIT AND MIT OR Apache-2.0 AND MIT OR Apache-2.0 OR Zlib AND MIT OR Zlib OR Apache-2.0 AND MPL-2.0 AND Unlicense OR MIT AND Zlib AND Zlib OR Apache-2.0 OR MIT
# LICENSE.dependencies contains a full license breakdown

URL:            https://gitlab.com/kaidelorenzo/minecraft-server-rs
# Sources can be obtained by
# git clone https://gitlab.com/kaidelorenzo/minecraft-server-rs
# cd minecraft-server-rs
# tito build --tgz
Source:         %{name}-%{version}.tar.gz

BuildRequires:  cargo-rpm-macros >= 24
BuildRequires:  systemd-rpm-macros
BuildRequires:  java-21-headless

%package java
Summary:        Wrapper for the Java Minecraft server that adds proper systemd support
# java-21-headless is provided by Oracle Java and OpenJDK Java
Requires:       java-21-headless

%package bedrock
Summary:        Wrapper for the Bedrock Minecraft server that adds proper systemd support

%global _description %{expand:
minecraft-server is a wrapper for the Java and Bedrock Minecraft servers 
that adds proper systemd support. The core functionality includes proper 
signal handling for SIGINT and SIGTERM, systemd user services, support 
for the XDG Base Directory Specification, and a Fedora Copr package for 
seamless upgrades.}

%global _java_description %{expand:
minecraft-server-java is a wrapper for the Java Minecraft server
that adds proper systemd support. The core functionality includes proper 
signal handling for SIGINT and SIGTERM, systemd user services, support 
for the XDG Base Directory Specification, and a Fedora Copr package for 
seamless upgrades.}

%global _bedrock_description %{expand:
minecraft-server-bedrock is a wrapper for the Bedrock Minecraft server 
that adds proper systemd support. The core functionality includes proper 
signal handling for SIGINT and SIGTERM, systemd user services, support 
for the XDG Base Directory Specification, and a Fedora Copr package for 
seamless upgrades.}

%description %{_description}
%description java %{_java_description}
%description bedrock %{_bedrock_description}

%prep
%autosetup -n %{name}-%{version} -p1
%cargo_prep

%generate_buildrequires
%cargo_generate_buildrequires

%build
%cargo_build
%{cargo_license_summary}
%{cargo_license} > LICENSE.dependencies

%install
install -Dpm 0644 systemd/minecraft-server-java.socket -t %{buildroot}%{_userunitdir}
install -Dpm 0644 systemd/minecraft-server-java.service -t %{buildroot}%{_userunitdir}
install -Dpm 0644 systemd/minecraft-server-bedrock.socket -t %{buildroot}%{_userunitdir}
install -Dpm 0644 systemd/minecraft-server-bedrock.service -t %{buildroot}%{_userunitdir}

install -Dpm 0644 manuals/minecraft-server-java.1 -t %{buildroot}%{_mandir}/man1
install -Dpm 0644 manuals/minecraft-server-bedrock.1 -t %{buildroot}%{_mandir}/man1

pushd %{name}
%cargo_install
popd

%if %{with check}
%check
%cargo_test
%endif

# these systemd commands are miserably documented but this is a good reference
# https://github.com/systemd/systemd/blob/main/src/rpm/systemd-update-helper.in
# https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_systemd
# we don't need the post ones because we aren't shipping a preset file but we'll add them anyway
# we do want the preun as to disable the service if the user had enabled it to remove symlinks
%post java
%systemd_user_post minecraft-server-java.socket
%systemd_user_post minecraft-server-java.service

%post bedrock
%systemd_user_post minecraft-server-bedrock.socket
%systemd_user_post minecraft-server-bedrock.service

# disable systemd units on uninstall
%preun java
%systemd_user_preun minecraft-server-java.socket
%systemd_user_preun minecraft-server-java.service

%preun bedrock
%systemd_user_preun minecraft-server-bedrock.socket
%systemd_user_preun minecraft-server-bedrock.service

# mark systemd units for restart on upgrade
%postun java
%systemd_user_postun_with_restart minecraft-server-java.socket
%systemd_user_postun_with_restart minecraft-server-java.service

%postun bedrock
%systemd_user_postun_with_restart minecraft-server-bedrock.socket
%systemd_user_postun_with_restart minecraft-server-bedrock.service

%files java
%license LICENSE
%license LICENSE.dependencies
%doc README.md
%{_mandir}/man1/minecraft-server-java.1.gz
%{_bindir}/minecraft-server-java
%{_userunitdir}/minecraft-server-java.socket
%{_userunitdir}/minecraft-server-java.service

%files bedrock
%license LICENSE
%license LICENSE.dependencies
%doc README.md
%{_mandir}/man1/minecraft-server-bedrock.1.gz
%{_bindir}/minecraft-server-bedrock
%{_userunitdir}/minecraft-server-bedrock.socket
%{_userunitdir}/minecraft-server-bedrock.service

%changelog
%autochangelog

view changes at
https://gitlab.com/kaidelorenzo/minecraft-server-rs/-/releases
