%global commit eec25221eadfa47b09de5bd0dc15e90b1263d43a
%global shortcommit %(c=%{commit}; echo ${c:0:7})
%global _hardened_build 1

Name:           geminid
Version:        0
Release:        1.20210415git%{shortcommit}%{?dist}
Summary:        A Gemini Server in C

License:        BSD 3-Clause
URL:            https://github.com/jovoro/geminid/
Source0:        https://github.com/jovoro/geminid/archive/%{shortcommit}.tar.gz#/%{name}-%{shortcommit}.tar.gz
Source1:        %{name}.service
Source2:        %{name}.firewalld

BuildRequires:  gcc
BuildRequires:  make
BuildRequires:  flex
BuildRequires:  openssl-devel
BuildRequires:  libconfig-devel
BuildRequires:  file-devel
BuildRequires:  systemd-rpm-macros
Requires:       firewalld

%description
A Gemini Server in C. Please note that this is not production-ready
code. The current state is a result of a few hours of hacking, barely
able to even serve content. But the goal is to have a compliant gemini
server written in C.


%prep
%autosetup -n %{name}-%{commit}


%build
export RPM_BUILD_NCPUS=2
%make_build 


%install
rm -rf $RPM_BUILD_ROOT
install -d -m 0755 %{buildroot}%{_sysconfdir}
install -p -m 640 example.conf %{buildroot}%{_sysconfdir}/%{name}.conf
install -D -m 755 %{name} %{buildroot}%{_bindir}/%{name}
install -D -m 644 %{SOURCE1} %{buildroot}/%{_unitdir}/%{name}.service
install -D -m 644 %{SOURCE2} %{buildroot}%{_prefix}/lib/firewalld/services/gemini.xml


%pre
getent group geminid >/dev/null 2>&1 || groupadd -r geminid 2>&1 || :
getent passwd geminid >/dev/null 2>&1 || useradd -r -l -g geminid \
    -d %{_var}/empty/%{name} -s /sbin/nologin -c "Gemini daemon" geminid >/dev/null 2>&1 || :

%post
%systemd_post %{name}.service

%preun
%systemd_preun %{name}.service

%postun
%systemd_postun_with_restart %{name}.service


%files
%license LICENSE
%doc README.md example.conf docroot
%config(noreplace) %attr(0640, geminid, root) %{_sysconfdir}/%{name}.conf
%{_bindir}/%{name}
%{_unitdir}/%{name}.service
%{_prefix}/lib/firewalld/services/*.xml


%changelog
* Fri Apr 02 2021 Greg Wildman <greg@techno.co.za> - 0.20210330git7e1fc07-1
- Initial spec.

-