%global gitproject0 gitprep
%global gitowner0 yuki-kimoto
%global commit0 719a651a66eb064adbf4864fc70e3ffb8dd72dec
%global commitdate0 20241220
%global shortcommit0 %(c=%{commit0}; echo ${c:0:7})
%global localport 10222
%global pkguser git
%global pkggroup git
%global pkghome %{_localstatedir}/lib/%{name}/data/rep
%global sysusers g %{pkggroup} -\
u %{pkguser} -:%{pkggroup} "gitprep server daemon" %{pkghome} %{_bindir}/bash
Name: gitprep
Summary: Portable GitHub system on your own server
Version: 2.6.3
Release: 0.rc1.%{commitdate0}.%{shortcommit0}.1%{?dist}
License: (GPL-1.0-or-later OR Artistic-1.0-Perl) and MIT
URL: https://github.com/yuki-kimoto/gitprep
Source: https://github.com/%{gitowner0}/%{gitproject0}/archive/%{commit0}.tar.gz#/%{name}-%{shortcommit0}.tar.gz
BuildArch: noarch
BuildRequires: perl-interpreter
BuildRequires: perl-generators
BuildRequires: perl(DBIx::Custom)
BuildRequires: perl(DBD::SQLite)
BuildRequires: systemd-rpm-macros
Requires: perl(Mojolicious)
Requires: perl(Mojo::ByteStream)
Requires: perl(Mojolicious::Plugin::INIConfig)
Requires: perl(Mojolicious::Plugin::AutoRoute)
Requires: perl(Mojolicious::Plugin::BasicAuth)
Requires: perl(Mojolicious::Plugin::DBViewer)
Requires: perl(Mojolicious::Plugin::AccessLog)
Requires: perl(Mojolicious::Plugin::RequestBase)
Requires: perl(DBD::SQLite)
Requires: perl(IO::Select)
Requires: perl(Symbol)
Requires: perl(Imager)
Requires: git-core
Requires: httpd-filesystem
Requires(post): policycoreutils policycoreutils-python-utils
%{?systemd_requires}
Recommends: logrotate
%global pkgdatadir %{_datadir}/%{name}
%global __provides_exclude_from %{pkgdatadir}
%global __requires_exclude ^perl\\(Gitprep
%{?perl_default_filter}
%description
GitPrep is a portable Github-like system which can be installed and hosted
on your own Unix/Linux server.
Features:
- Github clone: GitPrep has the same interface as GitHub.
- Support issue system.
- Portable: You can install GitPrep on your own Unix/Linux server.
- Only needs Perl 5.10.1+.
- Smart HTTP support: you can pull and push repository via HTTP.
- Built-in web server, and reverse proxy support.
- SSL support.
- Public key authentication support.
- Git branches and tags protection support.
#-------------------------------------------------------------------------------
%prep
#-------------------------------------------------------------------------------
%autosetup -p 1 -n %{name}-%{commit0}
find . -name '.git*' | xargs -r rm -rf
# The rpm package fully relies on dependency packages, thus unbundle
# the 'extlib' directory.
find . -type f | while read FILE
do sed -i -e '\#use lib "$FindBin::Bin.*/extlib/#d' "${FILE}"
done
for FILE in gitprep morbo
do sed -i -e '/PERL5LIB/d;s#$DIR/extlib/bin/#%{_bindir}/#g' "${FILE}"
done
# Fix version.
sed -i "/\\\$VERSION =/s/=.*/= 'v%{version}';/" ./lib/Gitprep.pm
#-------------------------------------------------------------------------------
%build
#-------------------------------------------------------------------------------
# Nothing to do.
#-------------------------------------------------------------------------------
%install
#-------------------------------------------------------------------------------
# Program.
install -d -m755 '%{buildroot}%{pkgdatadir}/'
cp -a gitprep lib morbo public script setup_database templates svg \
'%{buildroot}%{pkgdatadir}/'
mv '%{buildroot}%{pkgdatadir}/svg/octicons/LICENSE' LICENSE_MIT
# Gitprep shell script.
cat > '%{buildroot}%{pkgdatadir}/script/gitprep-shell' <<- 'EOF'
#!%{_bindir}/bash
exec perl '%{pkgdatadir}/script/gitprep-shell-raw' "${@}"
EOF
chmod +x '%{buildroot}%{pkgdatadir}/script/gitprep-shell'
# Data,
install -d -m755 '%{buildroot}%{_localstatedir}/lib/%{name}/data'
ln -s '%{_localstatedir}/lib/%{name}/data' '%{buildroot}%{pkgdatadir}/'
# Lock.
install -d -m755 '%{buildroot}%{_localstatedir}/lib/%{name}/lock'
> '%{buildroot}%{_localstatedir}/lib/%{name}/lock/authorized_keys'
ln -s '%{_localstatedir}/lib/%{name}/lock' '%{buildroot}%{pkgdatadir}/'
# Temporary directory.
install -d -m755 '%{buildroot}%{_rundir}/%{name}'
install -d -m755 '%{buildroot}%{_tmpfilesdir}'
cat > '%{buildroot}%{_tmpfilesdir}/%{name}.conf' <<- 'EOF'
d %{_rundir}/%{name} 770 %{pkguser} %{pkggroup}
EOF
ln -s '%{_rundir}/%{name}' '%{buildroot}%{pkgdatadir}/tmp'
# Logging.
install -d -m755 '%{buildroot}%{_localstatedir}/log/%{name}'
ln -s '%{_localstatedir}/log/%{name}' '%{buildroot}%{pkgdatadir}/log'
# Configuration.
install -d -m755 '%{buildroot}%{_sysconfdir}/'
sed -e '/ssh_rep_url_base=/a\
ssh_rep_url_base=/~' \
-e '/mojo_log_file_path=/s#=.*#=%{_localstatedir}/log/%{name}/production.log#' \
-e '/access_log_file_path=/s#=.*#=%{_localstatedir}/log/%{name}/access.log#' \
-e '/^listen=/s/:10020/:%{localport}/' \
-e '/\[hypnotoad]/a\
;;; Daemon pid file.\
pid_file=%{_rundir}/%{name}/pid.file\
' < gitprep.conf.example > '%{buildroot}%{_sysconfdir}/gitprep.conf'
ln -s '%{_sysconfdir}/gitprep.conf' '%{buildroot}%{pkgdatadir}/'
# Command.
install -d -m755 '%{buildroot}%{_sbindir}/'
cat > '%{buildroot}%{_sbindir}/gitprepd' <<- 'EOF'
#!/usr/bin/bash
exec '%{pkgdatadir}/gitprep' "${@}"
EOF
# Daemon user/group.
install -d -m755 '%{buildroot}%{_localstatedir}/lib/%{name}/data/rep'
install -d -m755 '%{buildroot}%{_sysusersdir}'
echo '%{sysusers}' > '%{buildroot}%{_sysusersdir}/%{name}.conf'
# Systemd service.
install -d -m755 '%{buildroot}%{_unitdir}'
cat > '%{buildroot}%{_unitdir}/%{name}.service' <<- 'EOF'
[Unit]
Description=Portable GitHub system on your own server
After=syslog.target network-online.target
[Service]
Type=forking
PIDFile=%{_rundir}/%{name}/pid.file
User=%{pkguser}
Group=%{pkggroup}
ExecStart=%{_sbindir}/gitprepd
[Install]
WantedBy=multi-user.target
EOF
# Logrotate.
install -d -m755 '%{buildroot}%{_sysconfdir}/logrotate.d'
cat > '%{buildroot}%{_sysconfdir}/logrotate.d/%{name}' << 'EOF'
%{_localstatedir}/log/%{name}/*.log {
copytruncate
missingok
notifempty
}
EOF
# Apache proxy.
install -d -m755 '%{buildroot}%{_sysconfdir}/httpd/conf.d'
cat > '%{buildroot}%{_sysconfdir}/httpd/conf.d/%{name}.conf' << 'EOF'
# Gitprep reverse proxy.
ProxyRequests Off
RedirectMatch ^/gitprep$ /gitprep/
Require local
ProxyPreserveHost On
ProxyPass http://localhost:%{localport}/ keepalive=On
RequestHeader setifempty X-Forwarded-Proto "https" \
expr=%{REQUEST_SCHEME}=='https'
RequestHeader setifempty X-Forwarded-Proto "http" \
expr=%{REQUEST_SCHEME}!='https'
RequestHeader setifempty X-Request-Base "/gitprep/"
EOF
#-------------------------------------------------------------------------------
%pre
#-------------------------------------------------------------------------------
%sysusers_create - << 'EOF'
%{sysusers}
EOF
#-------------------------------------------------------------------------------
%post
#-------------------------------------------------------------------------------
%tmpfiles_create '%{_tmpfilesdir}/%{name}.conf'
cd '%{pkgdatadir}'
./setup_database
(
umask 077
cd '%{_localstatedir}/lib/%{name}/data'
mkdir -p rep/.ssh
touch rep/.ssh/authorized_keys
)
semanage fcontext -a -t ssh_home_t \
'%{_localstatedir}/lib/%{name}/data/rep/\.ssh(/.*)?' >&- 2>&- || :
restorecon -r '%{_localstatedir}/lib/%{name}/data/rep/\.ssh' || :
find data/* -follow -print0 | xargs -r0 chown '%{pkguser}:%{pkggroup}'
%systemd_post %{name}.service
#-------------------------------------------------------------------------------
%preun
#-------------------------------------------------------------------------------
%systemd_preun %{name}.service
#-------------------------------------------------------------------------------
%postun
#-------------------------------------------------------------------------------
%systemd_postun_with_restart %{name}.service
#-------------------------------------------------------------------------------
%files
#-------------------------------------------------------------------------------
%doc CHANGES README.md Copying Artistic LICENSE_MIT
%{pkgdatadir}
%attr(0755, -, -) %{_sbindir}/*
%attr(-, %{pkguser}, %{pkggroup}) %{_localstatedir}/lib/%{name}
%attr(750, %{pkguser}, %{pkggroup}) %{_localstatedir}/log/%{name}
%{_unitdir}/*
%{_sysusersdir}/*
%{_tmpfilesdir}/*
%config(noreplace) %{_sysconfdir}/%{name}.conf
%config(noreplace) %{_sysconfdir}/httpd/conf.d/%{name}.conf
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%ghost %attr(0770, %{pkguser}, %{pkggroup}) %{_rundir}/%{name}
#-------------------------------------------------------------------------------
%changelog
#-------------------------------------------------------------------------------
* Fri Dec 20 2024 Patrick Monnerat 2.6.3-0.rc1.20241220.719a651.1
- New snapshot.
* Mon Dec 9 2024 Patrick Monnerat 2.6.3-0.rc1.20241209.fc87571.2
- Patch "default-branch-handling" to fix writing to an obsolete db field.
* Mon Dec 9 2024 Patrick Monnerat 2.6.3-0.rc1.20241209.fc87571.1
- New snapshot.
* Thu Nov 21 2024 Patrick Monnerat 2.6.3-0.rc1.20241121.3e7f91b.1
- New snapshot.
- Unbundle extlib in prep section.
- Adjust selinux type of .ssh directory.
* Wed Oct 23 2024 Patrick Monnerat 2.6.3-0.rc1.20241023.6bfc718.1
- New snapshot.
- Rename command as "gitprepd" to avoid conflicts with possible local install.
* Mon Oct 7 2024 Patrick Monnerat 2.6.3-0.rc1.20241007.5412bdd.1
- New snapshot.
* Wed Sep 25 2024 Patrick Monnerat 2.6.3-0.rc1.20240925.61c4039.1
- New snapshot.
* Tue Aug 27 2024 Patrick Monnerat 2.6.3-0.rc1.20240827.9df7c7d.1
- New snapshot.
* Tue Aug 20 2024 Patrick Monnerat 2.6.3-0.rc1.20240820.4cd0a5a.1
- New snapshot.
* Sat Jul 13 2024 Patrick Monnerat 2.6.3-0.rc1.20240711.07623ed.1
- New snapshot.
* Sun Jul 09 2023 Patrick Monnerat 2.6.3-0.rc1.20240624.3fe6c48.1
- Initial rpm packaging.
- Patch "noextlib" unbundles external libraries.