feat(release): add CentOS 7/8-compatible RPM build script
This commit is contained in:
Executable
+132
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
||||
PLUGIN_DIR="$(cd "$ROOT/.." && pwd)"
|
||||
REPO_ROOT="$(git -C "$PLUGIN_DIR" rev-parse --show-toplevel)"
|
||||
|
||||
VERSION="${VERSION:-}"
|
||||
if [[ -z "${VERSION}" ]]; then
|
||||
VERSION="$(sed -n 's/.*"version":[[:space:]]*"\([^"]*\)".*/\1/p' "$PLUGIN_DIR/package.json" | head -n 1)"
|
||||
fi
|
||||
if [[ -z "${VERSION}" ]]; then
|
||||
echo "Could not determine package version" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IMAGE="${RPM_IMAGE:-almalinux:8}"
|
||||
RELEASE_DIR="$PLUGIN_DIR/_release/$VERSION"
|
||||
SOURCE_STAGE="$RELEASE_DIR/plagin-tokens-$VERSION"
|
||||
BASE_NAME="plagin-tokens-${VERSION}"
|
||||
SOURCE_ARCHIVE="${BASE_NAME}.tar.gz"
|
||||
RPM_NAME="${BASE_NAME}-1.noarch.rpm"
|
||||
|
||||
if [[ ! -d "$SOURCE_STAGE" ]]; then
|
||||
echo "Building source stage through release/package.sh..."
|
||||
( cd "$PLUGIN_DIR" && VERSION="$VERSION" BUILD_RPM=0 bash release/package.sh )
|
||||
fi
|
||||
|
||||
if [[ ! -f "$SOURCE_STAGE/README.md" ]]; then
|
||||
echo "Source staging directory is incomplete: $SOURCE_STAGE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Rework source tree into the same top-level expected by %setup.
|
||||
SOURCE_ARCHIVE_PATH="$RELEASE_DIR/$SOURCE_ARCHIVE"
|
||||
if [[ ! -f "$SOURCE_ARCHIVE_PATH" ]]; then
|
||||
tar -C "$RELEASE_DIR" -czf "$SOURCE_ARCHIVE_PATH" "$(basename "$SOURCE_STAGE")"
|
||||
fi
|
||||
|
||||
RPMBUILD_DIR="$RELEASE_DIR/rpmbuild"
|
||||
rm -rf "$RPMBUILD_DIR"
|
||||
mkdir -p "$RPMBUILD_DIR"/{SOURCES,SPECS,BUILD,BUILDROOT,RPMS,SRPMS}
|
||||
cp "$SOURCE_ARCHIVE_PATH" "$RPMBUILD_DIR/SOURCES/"
|
||||
|
||||
cat > "$RPMBUILD_DIR/SPECS/plagin-tokens.spec" <<'SPEC'
|
||||
%global _rpmdir %{_topdir}/RPMS
|
||||
%global _srcrpmdir %{_topdir}/SRPMS
|
||||
|
||||
Name: plagin-tokens
|
||||
Version: 0.1.0
|
||||
Release: 1%{?dist}
|
||||
Summary: Live token speed indicator for opencode web
|
||||
License: Proprietary
|
||||
Group: Applications/System
|
||||
BuildArch: noarch
|
||||
URL: https://gitea.andre-y-ru.ru/andrew/plagin_tokens
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
|
||||
%description
|
||||
plagin-tokens tracks opencode streaming responses, exposes token throughput
|
||||
through a local HTTP server, and provides a floating macOS HUD and static
|
||||
overlay plugin. Run plagin-tokens-install after installation.
|
||||
|
||||
%prep
|
||||
%setup -q -n %{name}-%{version}
|
||||
|
||||
%install
|
||||
rm -rf %{buildroot}
|
||||
mkdir -p %{buildroot}/opt
|
||||
cp -a %{_builddir}/%{name}-%{version} %{buildroot}/opt/%{name}
|
||||
|
||||
install -Dm 0755 release/install-opencode-plugin.sh \
|
||||
%{buildroot}/usr/local/bin/plagin-tokens-install
|
||||
|
||||
install -Dm 0644 README.md \
|
||||
%{buildroot}/usr/share/doc/plagin-tokens/README.md
|
||||
|
||||
install -d %{buildroot}/etc/skel/.config/opencode/plugins
|
||||
ln -s /opt/plagin-tokens/src/plugin.ts \
|
||||
%{buildroot}/etc/skel/.config/opencode/plugins/plagin-tokens.ts
|
||||
|
||||
%files
|
||||
%defattr(-,root,root,-)
|
||||
%dir /opt/plagin-tokens
|
||||
/opt/plagin-tokens/*
|
||||
/usr/local/bin/plagin-tokens-install
|
||||
%doc /usr/share/doc/plagin-tokens/README.md
|
||||
/etc/skel/.config/opencode/plugins/plagin-tokens.ts
|
||||
|
||||
%post
|
||||
echo "plagin-tokens is installed; run plagin-tokens-install as a normal user."
|
||||
|
||||
%changelog
|
||||
* Fri Oct 31 2026 Andrew Emelyanenko 0.1.0-1
|
||||
- Initial RPM package.
|
||||
SPEC
|
||||
|
||||
if [[ "$VERSION" != "0.1.0" ]]; then
|
||||
sed -i '' "s/^Version:.*/Version: ${VERSION}/" "$RPMBUILD_DIR/SPECS/plagin-tokens.spec"
|
||||
fi
|
||||
|
||||
echo "Building RPM with $IMAGE..."
|
||||
docker run --rm --platform linux/amd64 \
|
||||
-v "$RPMBUILD_DIR:/rpmbuild" \
|
||||
-v "$RELEASE_DIR:/release" \
|
||||
-e "SOURCE_ARCHIVE=$SOURCE_ARCHIVE" \
|
||||
"$IMAGE" bash -c '
|
||||
set -euo pipefail
|
||||
# CentOS 7 stock mirrors are offline; switch to the historical vault mirror.
|
||||
if [ -f /etc/yum.repos.d/CentOS-Base.repo ]; then
|
||||
sed -i "s|^mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
sed -i "s|^#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-Base.repo
|
||||
fi
|
||||
rpm --version
|
||||
command -v rpmbuild >/dev/null 2>&1 || yum -q -y install rpm-build
|
||||
mkdir -p /root/rpmbuild
|
||||
cp -a /rpmbuild/. /root/rpmbuild/
|
||||
cp "/release/${SOURCE_ARCHIVE}" /root/rpmbuild/SOURCES/
|
||||
rpmbuild --target noarch -bb /root/rpmbuild/SPECS/plagin-tokens.spec
|
||||
cp /root/rpmbuild/RPMS/noarch/*.rpm /release/
|
||||
'
|
||||
cp "$RPMBUILD_DIR"/RPMS/noarch/*.rpm "$RELEASE_DIR/" 2>/dev/null || true
|
||||
|
||||
RPM_PRODUCED="$(find "$RELEASE_DIR" -maxdepth 1 -type f -name "plagin-tokens*.rpm" | tail -n 1)"
|
||||
if [[ -z "$RPM_PRODUCED" || ! -f "$RPM_PRODUCED" ]]; then
|
||||
echo "RPM was not produced by container build" >&2
|
||||
exit 1
|
||||
fi
|
||||
mv -f "$RPM_PRODUCED" "$RELEASE_DIR/$RPM_NAME"
|
||||
RPM_PATH="$RELEASE_DIR/$RPM_NAME"
|
||||
|
||||
echo "Built: $RPM_PATH"
|
||||
Reference in New Issue
Block a user