File gitea.spec of Package gitea
%define realname gitea
%define srcext tar.gz
%define gitea_group git
%define gitea_user git
%define gitea_home %{_localstatedir}/lib/gitea
%if %{defined suse_version}
%if ! %{defined _fillupdir}
%define _fillupdir /var/adm/fillup-templates
%endif
%define sysconffile %{_fillupdir}/sysconfig.gitea
%else
%define sysconffile %{_sysconfdir}/sysconfig/gitea
%endif
# Common info
Name: %{realname}
Version: 1.19.3
Release: wiz%{?extraver:0.}1%{?dist}
License: Apache-2.0
Group: Development/Tools/Version Control
URL: https://gitea.io/
Summary: Lightweight code hosting solution
# Build-time parameters
BuildRequires: go >= 1.16
BuildRequires: nodejs(engine) >= 10.0
BuildRequires: npm
%if 0%{?suse_version}
BuildRequires: fdupes
%endif
BuildRoot: %{_tmppath}/%{name}-root
Source0: https://github.com/go-gitea/gitea/archive/refs/tags/v%{version}.tar.gz#/gitea-%{version}.tar.gz
# cd gitea; go mod vendor -v && tar -Jcvf ../vendor.tar.xz vendor && rm -rf vendor/; cd ..
Source1: vendor.tar.xz
# cd gitea; npm install --no-save && npx browserslist@latest --update-db && tar -Jcf ../node_modules.tar.xz node_modules package-lock.json; rm -rf node_modules; git reset --hard; cd -
Source11: node_modules.tar.xz
%description
Gitea is a painless self-hosted Git service. It is similar to GitHub, Bitbucket,
and GitLab. Gitea is a fork of Gogs.
The goal of this project is to provide the easiest, fastest, and most painless
way of setting up a self-hosted Git service.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver} -a1 -a11
# Fix application version string
%{__sed} -i '/^\s*Version\s*=/ s/".*"/"%{version}"/' main.go
# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro'
GITEA_LDFLAGS='-X "code.gitea.io/gitea/modules/setting.CustomPath=%{gitea_home}"'
GITEA_LDFLAGS+=' -X "code.gitea.io/gitea/modules/setting.AppWorkPath=%{gitea_home}"'
GITEA_LDFLAGS+=" -extldflags \"$_LDFLAGS\""
export GOPATH=$(pwd -P)/.gomodules
export GOCACHE=$(pwd -P)/.gocache
export GOTRACEBACK=crash
export CGO_ENABLED=1
export CGO_CFLAGS="$_CFLAGS"
export CGO_LDFLAGS="$_LDFLAGS"
### %{?_smp_mflags}
%{__make} build \
GITEA_VERSION=%{version} \
VERSION=%{version} \
EXTRA_GOFLAGS="-buildmode=pie -gcflags=all=-dwarf=false" \
TAGS=sqlite \
LDFLAGS="$GITEA_LDFLAGS"
# Install built stuff
%install
# Install executable
%{__install} -d -m0755 %{buildroot}%{_bindir}
%{__install} -m0755 gitea %{buildroot}%{_bindir}/gitea
# Install config/assets
%{__install} -d -m0755 %{buildroot}%{_sysconfdir}
%{__ln_s} ..%{gitea_home}/conf %{buildroot}%{_sysconfdir}/gitea
%{__install} -d -m0755 %{buildroot}%{gitea_home}/conf
%{__install} -d -m0755 %{buildroot}%{gitea_home}/log
%{__install} -d -m0755 %{buildroot}%{gitea_home}/options
%{__cp} -r options/locale %{buildroot}%{gitea_home}/options
%{__cp} -r public %{buildroot}%{gitea_home}
%{__cp} -r templates %{buildroot}%{gitea_home}
# Fix config
%{__sed} -r \
-e '/^RUN_MODE/ s|dev|prod|' \
-e '/^ROOT\s*=/ s|(=\s*.*)$|= %{gitea_home}/repositories|' \
custom/conf/app.example.ini \
> %{buildroot}%{gitea_home}/conf/app.ini
# sysystemd unit/init script
%if %{defined _unitdir}
%{__install} -d -m0755 %{buildroot}%{_unitdir}
%{__sed} -r \
-e '/^ExecStart/ s|/usr/local/bin|%{_bindir}|' \
-e '/^Environment/ s|HOME=\S+|HOME=%{gitea_home}|' \
contrib/systemd/gitea.service \
> %{buildroot}%{_unitdir}/gitea.service
%else
%{__install} -d -m0755 %{buildroot}%{_initrddir}
if [ '%{expand:%_vendor}' = 'suse'} ]; then
INIT_SCRIPT=contrib/init/suse/gitea
else
INIT_SCRIPT=contrib/init/centos/gitea
fi
%{__sed} -r \
-e '/GITEA_PATH/ s|/usr/local/bin|%{_bindir}|' \
"$INIT_SCRIPT" \
> %{buildroot}%{_initrddir}/gitea
%{__chmod} a+x %{buildroot}%{_initrddir}/gitea
%endif
# Logs symlink
%{__install} -d -m0755 %{buildroot}/var/log
%{__ln_s} ../lib/gitea/log %{buildroot}/var/log/gitea
# File duplicates
%if 0%{?suse_version}
%fdupes %{buildroot}%{gitea_home}
%endif
# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
# Files list
%files
%defattr(-,root,root)
%doc CHANGELOG.md CONTRIBUTING.md DCO LICENSE MAINTAINERS README.md README_ZH.md
%doc custom/conf/app.example.ini
%{_sysconfdir}/gitea
%{_bindir}/gitea
%dir %attr(0750,git,git) %{gitea_home}
%attr(-,git,git) %{gitea_home}/*
%config(noreplace) %attr(0600,git,git) %{gitea_home}/conf/app.ini
/var/log/gitea
%if %{defined _unitdir}
%{_unitdir}/gitea.service
%else
%{_initrddir}/gitea
%endif
%pre
/usr/sbin/groupadd -r %{gitea_group} &>/dev/null ||:
/usr/sbin/useradd -g %{gitea_group} -s /bin/false -r -M \
-c "Git repos owner" -d %{_localstatedir}/lib/git %{gitea_user} &>/dev/null ||:
%if "%{expand:%_vendor}" == "suse" && %{defined _unitdir}
%{service_add_pre gitea.service}
%endif
%if "%{expand:%_vendor}" == "suse"
%post
%if %{defined _unitdir}
%{fillup_only}
%{service_add_post gitea.service}
%else
%{fillup_and_insserv gitea}
%endif
%preun
%if %{defined _unitdir}
%{service_del_preun gitea.service}
%else
%{stop_on_removal gitea.service}
%endif
%postun
%if %{defined _unitdir}
%{service_del_postun gitea.service}
%else
%{restart_on_update gitea.service}
%endif
%endif
%changelog