#!/bin/bash

# Fetch the source tarball (with the built frontend) from dl.gitea.com,
# check it against the published SHA256 and repack it as .tar.lz.

VERSION=$1

if [ -z "$VERSION" ]; then
  echo "Usage: $0 <version>"
  exit 1
fi

FILE=gitea-src-$VERSION.tar.gz

wget "https://dl.gitea.com/gitea/$VERSION/$FILE" || exit 1
wget -O - "https://dl.gitea.com/gitea/$VERSION/$FILE.sha256" | sha256sum -c - || exit 1

rm -f gitea-src-*.tar.lz

gunzip "$FILE"
plzip -9 "${FILE%.gz}"
