%undefine _debugsource_packages
%global _default_patch_fuzz 2

Name:		gitea
Version:	1.22.6
Release:	1%{dist}
Summary:	Git with a cup of tea, painless self-hosted git service
License:	MIT
Group:		Development/Other
URL:		https://gitea.io/
Source0:	https://github.com/go-gitea/gitea/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source6:    gitea.sysusers
Source10:   gitea.service
Source11:   gitea.service.d.conf
Source12:   app-gitea.ini
Patch0:     make-version.patch
Requires:   git-core
BuildRequires:	git
BuildRequires:	golang >= 1.22
BuildRequires:  make
BuildRequires:  pam-devel
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  pkgconfig(openssl) >= 3.0, pkgconfig(openssl) < 3.8
BuildRequires:  npm >= 1:10.0
#BuildRequires:  nodejs >= 1:20.0
BuildRequires:  systemd-rpm-macros

%description
The goal of this project is to make the easiest, fastest, and most painless way
of setting up a self-hosted Git service. It is similar to GitHub, Bitbucket,
and Gitlab. Gitea is a fork of Gogs.

%prep
%autosetup -p1

%build
ulimit -n 8192
# Build fails in prod mode
export NODE_ENV="development"
export GOPATH="`pwd`/.godeps"
%if 0%{?rhel} < 9
export CGO_CFLAGS="$CGO_CFLAGS -I%{_includedir}/openssl3"
%endif
export EXTRA_GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"
export LDFLAGS='-linkmode=external -compressdwarf=false -X "code.gitea.io/gitea/modules/setting.StaticRootPath=%{_datadir}/gitea/web/" -X "code.gitea.io/gitea/modules/setting.AppWorkPath=%{_localstatedir}/lib/gitea/" -X "code.gitea.io/gitea/modules/setting.CustomPath=%{_localstatedir}/lib/gitea/custom/" -X "code.gitea.io/gitea/modules/setting.CustomConf=%{_sysconfdir}/gitea/app.ini"'
export TAGS="bindata tidb sqlite sqlite_unlock_notify pam"

make -j1 VERSION=%{version} generate all


%install
mkdir -p %{buildroot}%{_localstatedir}/lib/%{name}
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}
mkdir -p %{buildroot}%{_sysconfdir}/systemd/system/%{name}.service.d/
install -Dm 0755 %{name} %{buildroot}%{_bindir}/%{name}
install -Dm 0640 %{SOURCE10} %{buildroot}%{_unitdir}/%{name}.service
install -Dm 0640 %{SOURCE11} %{buildroot}%{_sysconfdir}/systemd/system/%{name}.service.d/port.conf
install -Dm 0660 %{SOURCE12} %{buildroot}%{_sysconfdir}/%{name}/app.ini

install -p -D -m 0644 %{SOURCE6} \
    %{buildroot}%{_sysusersdir}/%{name}.conf

mkdir -p %{buildroot}%{_tmpfilesdir}
cat > %{buildroot}%{_tmpfilesdir}/%{name}.conf <<EOF
d /run/%{name} 0755 gitea gitea -
EOF

install -d -m 755 %{buildroot}%{_datadir}/%{name}/web
cp -r options public templates %{buildroot}%{_datadir}/%{name}/web

%pre
%sysusers_create_compat %{SOURCE6}

%post
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf
%systemd_post gitea.service 

%preun
%systemd_preun gitea.service

%postun
%systemd_postun gitea.service

%files
%doc custom/conf/app.example.ini
%doc CHANGELOG.md CODE_OF_CONDUCT.md CONTRIBUTING.md README*.md SECURITY.md
%{_bindir}/%{name}
%dir %attr(0700,%name,%name) %{_localstatedir}/lib/%{name}
%dir %attr(0700,%name,%name) %{_localstatedir}/log/%{name}
%dir %{_sysconfdir}/%{name}
%config(noreplace) %attr(0660,root,%name) %{_sysconfdir}/%{name}/app.ini
%config(noreplace) %attr(0644,root,root) %{_sysconfdir}/systemd/system/%{name}.service.d/port.conf
%{_datadir}/%{name}/web
%{_unitdir}/%{name}.service
%{_tmpfilesdir}/%{name}.conf
%{_sysusersdir}/%{name}.conf

%changelog
* Mon Dec 16 2024 Raven <raven@sysadmins.ws> - 1.22.6-1
- update to 1.22.6

* Thu Dec 12 2024 Raven <raven@sysadmins.ws> - 1.22.5-1
- update to 1.22.5

* Tue Nov 26 2024 Raven <raven@sysadmins.ws> - 1.22.4-1
- update to 1.22.4

* Wed Oct  9 2024 Raven <raven@sysadmins.ws> - 1.22.3-1
- update to 1.22.3

* Fri Sep  6 2024 Raven <raven@sysadmins.ws> - 1.22.2-1
- update to 1.22.2

* Thu Jul  4 2024 Raven <raven@sysadmins.ws> - 1.22.1-1
- update to 1.22.1

* Tue May 28 2024 Raven <raven@sysadmins.ws> - 1.22.0-1
- update to 1.22.0

* Tue Mar 26 2024 Raven <raven@sysadmins.ws> - 1.21.10-1
- update to 1.21.10

* Fri Mar 22 2024 Raven <raven@sysadmins.ws> - 1.21.9-1
- update to 1.21.9

* Wed Mar 13 2024 Raven <raven@sysadmins.ws> - 1.21.8-1
- update to 1.21.8

* Tue Feb 27 2024 Raven <raven@sysadmins.ws> - 1.21.7-1
- update to 1.21.7

* Mon Feb 26 2024 Raven <raven@sysadmins.ws> - 1.21.6-2
- fix overwriting of gitea.service.d/port.conf

* Mon Feb 26 2024 Raven <raven@sysadmins.ws> - 1.21.6-1
- update to 1.21.6

* Wed Feb 21 2024 Raven <raven@sysadmins.ws> - 1.21.5-5
- add systemd scriptlets

* Wed Feb 21 2024 Raven <raven@sysadmins.ws> - 1.21.5-4
- add CAP_NET_BIND_SERVICE

* Tue Feb 20 2024 Raven <raven@sysadmins.ws> - 1.21.5-3
- package static assets

* Tue Feb 20 2024 Raven <raven@sysadmins.ws> - 1.21.5-2
- update default configs

* Tue Feb 20 2024 Raven <raven@sysadmins.ws> - 1.21.5-1
- Initial build
