57 lines
2.6 KiB
Bash
57 lines
2.6 KiB
Bash
#!/bin/bash
|
|||
|
|
# Publish a new avatar-decorations version to the Gitea generic package
|
||
|
|
# registry and write the pin that LXC 106's deploy installs (matrix #22).
|
||
|
|
#
|
||
|
|
# GITEA_TOKEN=… deploy/publish-decorations.sh <dir> <version>
|
||
|
|
#
|
||
|
|
# <dir> holds <slug>.png files and thumbs/<slug>.webp (the same layout the app
|
||
|
|
# requests). The set is split into ≤150 MB tar parts (the registry's proxy
|
||
|
|
# refuses large uploads), each part is uploaded, and cinny/decorations.sha256
|
||
|
|
# is rewritten. Commit that file to deploy; nothing changes until you do.
|
||
|
|
set -euo pipefail
|
||
|
|
SRC=${1:?usage: publish-decorations.sh <dir> <version>}
|
||
|
|
VER=${2:?usage: publish-decorations.sh <dir> <version>}
|
||
|
|
: "${GITEA_TOKEN:?set GITEA_TOKEN (package write scope)}"
|
||
|
|
REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||
|
|
BASE="https://code.lotusguild.org/api/packages/LotusGuild/generic/avatar-decorations/$VER"
|
||
|
|
WORK=$(mktemp -d)
|
||
|
|
trap 'rm -rf "$WORK"' EXIT
|
||
|
|
|
||
|
|
mkdir -p "$WORK/decorations/thumbs"
|
||
|
|
cp "$SRC"/*.png "$WORK/decorations/"
|
||
|
|
cp "$SRC"/thumbs/*.webp "$WORK/decorations/thumbs/"
|
||
|
|
cd "$WORK"
|
||
|
|
for f in decorations/*.png; do
|
||
|
|
s=$(basename "$f" .png)
|
||
|
|
[ -f "decorations/thumbs/$s.webp" ] || { echo "missing thumbs/$s.webp" >&2; exit 1; }
|
||
|
|
done
|
||
|
|
(cd decorations && find . -type f \( -name '*.png' -o -name '*.webp' \) | sort | xargs sha256sum > MANIFEST.sha256)
|
||
|
|
|
||
|
|
python3 - "$VER" <<'PY'
|
||
|
|
import os, subprocess, sys
|
||
|
|
ver, root, limit = sys.argv[1], 'decorations', 150 * 1024 * 1024
|
||
|
|
files = sorted(os.path.join(root, f) for f in os.listdir(root) if f.endswith('.png'))
|
||
|
|
first = [os.path.join(root, 'MANIFEST.sha256')] + sorted(os.path.join(root, 'thumbs', t) for t in os.listdir(os.path.join(root, 'thumbs')))
|
||
|
|
parts, cur, size = [], list(first), sum(os.path.getsize(f) for f in first)
|
||
|
|
for f in files:
|
||
|
|
if size + os.path.getsize(f) > limit and cur:
|
||
|
|
parts.append(cur); cur, size = [], 0
|
||
|
|
cur.append(f); size += os.path.getsize(f)
|
||
|
|
parts.append(cur)
|
||
|
|
for i, p in enumerate(parts, 1):
|
||
|
|
lst = f'part{i}.list'
|
||
|
|
open(lst, 'w').write('\n'.join(p) + '\n')
|
||
|
|
subprocess.run(['tar', '--sort=name', '--owner=0', '--group=0', '--mtime=@0', '-cf',
|
||
|
|
f'avatar-decorations-{ver}.part{i}.tar', '-T', lst], check=True)
|
||
|
|
PY
|
||
|
|
|
||
|
|
sha256sum avatar-decorations-"$VER".part*.tar > SHA256SUMS
|
||
|
|
for f in avatar-decorations-"$VER".part*.tar SHA256SUMS; do
|
||
|
|
code=$(curl -s -o /dev/null -w '%{http_code}' -X PUT -H "Authorization: token $GITEA_TOKEN" \
|
||
|
|
--upload-file "$f" "$BASE/$f")
|
||
|
|
[ "$code" = 201 ] || { echo "upload of $f failed: HTTP $code" >&2; exit 1; }
|
||
|
|
echo "uploaded $f"
|
||
|
|
done
|
||
|
|
cp SHA256SUMS "$REPO_ROOT/cinny/decorations.sha256"
|
||
|
|
echo "Pinned $VER in cinny/decorations.sha256: commit it to deploy."
|