File openlist.spec of Package openlist
%global _build_id_links none
%global debug_package %{nil}
%undefine source_date_epoch_from_changelog
%global upstream_version 4.1.9
%global software_name openlist
%global build_tags jsoniter
# Map rpm arch to Go arch
%global go_arch %{lua:\
local m = {\
x86_64 = 'amd64',\
aarch64 = 'arm64',\
armv7hl = 'arm',\
armv6hl = 'arm',\
i686 = '386',\
ppc64le = 'ppc64le',\
s390x = 's390x',\
riscv64 = 'riscv64',\
mips64el = 'mips64le',\
mipsel = 'mipsle',\
mips = 'mips'\
}\
local a = rpm.expand('%_arch')\
print(m[a] or a)\
}
Name: %{software_name}
Version: %{upstream_version}
Release: 1%{?dist}
Summary: A file list/WebDAV program that supports multiple storages
License: AGPL-3.0-only
URL: https://github.com/OpenListTeam/OpenList
Source0: https://github.com/OpenListTeam/OpenList/archive/refs/tags/v%{upstream_version}.tar.gz
# Vendored Go modules for offline/limited-network builds.
# The archive MUST contain a top-level "vendor/" directory along with go.mod and go.sum.
Source1: %{software_name}-%{upstream_version}-vendor.tar.gz
# Frontend dist (embedded into binary)
Source2: %{software_name}-frontend-%{upstream_version}.tar.gz
# Systemd service file
Source3: %{software_name}.service
# Systemd user instance service file
Source4: %{software_name}@.service
# Sysusers configuration
Source5: %{software_name}.sysusers
BuildRequires: git, curl, tar, gcc, make, golang, systemd-rpm-macros
%{?systemd_requires}
%description
OpenList (previously AList) is a file list/WebDAV program that supports
multiple storages, including local, WebDAV, S3, FTP, and many cloud storage
services. It provides a web interface for browsing and managing files.
%prep
%autosetup -p1 -n OpenList-%{upstream_version}
# Use vendored Go modules to minimize network access during build.
# (In mock/Koji, network is typically disabled; without vendor/ this will fail.)
tar -xf %{SOURCE1}
if [ ! -d vendor ]; then
echo "ERROR: vendor/ directory not found. Provide a vendored modules tarball via Source1." >&2
exit 1
fi
# Extract frontend dist
mkdir -p public/dist
tar -xzf %{SOURCE2} -C public/dist
%build
# Get build metadata
_built_at="$(date +'%%F %%T %%z')"
_git_author="The OpenList Projects Contributors <noreply@openlist.team>"
_git_commit="$(git log --pretty=format:'%%h' -1 2>/dev/null || echo 'unknown')"
_version="%{upstream_version}"
_web_version="%{upstream_version}"
# Build ldflags
_ldflags="-w -s \
-X 'github.com/OpenListTeam/OpenList/v4/internal/conf.BuiltAt=${_built_at}' \
-X 'github.com/OpenListTeam/OpenList/v4/internal/conf.GitAuthor=${_git_author}' \
-X 'github.com/OpenListTeam/OpenList/v4/internal/conf.GitCommit=${_git_commit}' \
-X 'github.com/OpenListTeam/OpenList/v4/internal/conf.Version=${_version}' \
-X 'github.com/OpenListTeam/OpenList/v4/internal/conf.WebVersion=${_web_version}'"
# Prefer offline build: do not use module proxy or sumdb.
export GOPROXY=off
export GOSUMDB=off
export GOMODCACHE="$PWD/.gomodcache"
CGO_ENABLED=1 go build \
-v \
-trimpath \
-buildmode=pie \
-mod=vendor \
-modcacherw \
-buildvcs=false \
-tags=%{build_tags} \
-ldflags="${_ldflags}" \
-o %{software_name} \
.
%install
# Install binary
install -Dsm755 %{software_name} -t %{buildroot}%{_bindir}
# Install systemd service files
install -Dm644 %{SOURCE3} -t %{buildroot}%{_unitdir}
install -Dm644 %{SOURCE4} -t %{buildroot}%{_unitdir}
# Install sysusers configuration
install -Dm644 %{SOURCE5} %{buildroot}%{_sysusersdir}/%{software_name}.conf
# Note: Directories are managed by systemd's StateDirectory/ConfigurationDirectory
# and will be automatically created with correct ownership (openlist:openlist)
%check
# Tests are run during go build with vendor modules
%pre
%if 0%{?suse_version}
%service_add_pre %{software_name}.service
%sysusers_create %{SOURCE5}
%else
%sysusers_create_compat %{SOURCE5}
%endif
%post
%if 0%{?suse_version}
%service_add_post %{software_name}.service
%else
%systemd_post %{software_name}.service
%endif
%preun
%if 0%{?suse_version}
%service_del_preun %{software_name}.service
%else
%systemd_preun %{software_name}.service
%endif
%postun
%if 0%{?suse_version}
%service_del_postun %{software_name}.service
%else
%systemd_postun_with_restart %{software_name}.service
%endif
%files
%license LICENSE
%{_bindir}/%{software_name}
%{_unitdir}/%{software_name}.service
%{_unitdir}/%{software_name}@.service
%{_sysusersdir}/%{software_name}.conf
%changelog