Files
snippets/ggt/iggt.sh
T
2026-08-23 18:52:19 +07:00

79 lines
2.3 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
readonly REPOSITORY="lutinglt/gitea-github-theme"
readonly SCRIPT_DIRECTORY="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
usage() {
printf 'Usage: %s <gitea-version> <custom-path>\n' "${0##*/}" >&2
printf 'Example: %s 1.27.0 "$(gitea help | awk '\''/CustomPath:/ {print $2}'\'')"\n' "${0##*/}" >&2
exit 2
}
require_command() {
command -v "$1" >/dev/null 2>&1 || {
printf 'Required command not found: %s\n' "$1" >&2
exit 1
}
}
[[ $# -eq 2 ]] || usage
gitea_version="$1"
custom_path="$2"
if [[ -z "$custom_path" || "$custom_path" == *$'\n'* ]]; then
printf 'CustomPath must be exactly one non-empty path.\n' >&2
exit 1
fi
manifest_path="$("$SCRIPT_DIRECTORY/install-gitea-github-theme.sh" --print-manifest-path \
"$custom_path/public/assets/css" "$custom_path/templates")"
# Move manifests written by earlier script versions out of CustomPath before Gitea dump scans it.
for legacy_manifest in \
"$custom_path/.gitea-github-theme-files" \
"$custom_path/templates/.gitea-github-theme-files"; do
if [[ -f "$legacy_manifest" && ! -e "$manifest_path" ]]; then
mkdir -p "$(dirname "$manifest_path")"
mv -- "$legacy_manifest" "$manifest_path"
printf 'Moved theme manifest to %s.\n' "$manifest_path"
break
fi
done
if [[ ! "$gitea_version" =~ ^v?([0-9]+\.[0-9]+) ]]; then
printf 'Unable to determine major.minor from Gitea version: %s\n' "$gitea_version" >&2
exit 1
fi
release_prefix="v${BASH_REMATCH[1]}."
require_command curl
require_command jq
theme_version="$(
curl --connect-timeout 10 --fail --silent --show-error --location \
"https://api.github.com/repos/${REPOSITORY}/releases" \
| jq -r --arg prefix "$release_prefix" '
[ .[]
| select(.prerelease == false and (.tag_name | startswith($prefix)))
| .tag_name
]
| first // empty
'
)"
if [[ -z "$theme_version" ]]; then
printf 'No stable %s* theme release was found; removing any installed matching theme files.\n' "$release_prefix" >&2
exec "$SCRIPT_DIRECTORY/install-gitea-github-theme.sh" --remove \
"$custom_path/public/assets/css" \
"$custom_path/templates" \
"$manifest_path"
fi
exec "$SCRIPT_DIRECTORY/install-gitea-github-theme.sh" \
"$theme_version" \
"$custom_path/public/assets/css" \
"$custom_path/templates" \
"$manifest_path"