[core]: feature - check_for_gh_release - version pinning (#7279)

* [core]: feature - check_for_gh_release - version pinning

* Modify usage comments for check_for_gh_release

Updated usage example for check_for_gh_release function.

* Refactor jq installation command with STD variable

* remove unneeded dev/null
This commit is contained in:
CanbiZ 2025-08-29 12:29:52 +02:00 committed by GitHub
parent b73bfdf7fd
commit ede5f35f39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1930,7 +1930,7 @@ function setup_ffmpeg() {
# - If newer, sets global CHECK_UPDATE_RELEASE and returns 0 # - If newer, sets global CHECK_UPDATE_RELEASE and returns 0
# #
# Usage: # Usage:
# if check_for_gh_release "flaresolverr" "FlareSolverr/FlareSolverr"; then # if check_for_gh_release "flaresolverr" "FlareSolverr/FlareSolverr" [optional] "v1.1.1"; then
# # trigger update... # # trigger update...
# fi # fi
# exit 0 # exit 0
@ -1944,6 +1944,7 @@ function setup_ffmpeg() {
check_for_gh_release() { check_for_gh_release() {
local app="$1" local app="$1"
local source="$2" local source="$2"
local pinned_version="${3:-}" # optional
local current_file="$HOME/.${app,,}" local current_file="$HOME/.${app,,}"
msg_info "Check for update: ${app}" msg_info "Check for update: ${app}"
@ -1956,7 +1957,7 @@ check_for_gh_release() {
# jq check # jq check
if ! command -v jq &>/dev/null; then if ! command -v jq &>/dev/null; then
$STD apt-get update $STD apt-get update -qq
$STD apt-get install -y jq || { $STD apt-get install -y jq || {
msg_error "Failed to install jq" msg_error "Failed to install jq"
return 1 return 1
@ -1964,7 +1965,7 @@ check_for_gh_release() {
fi fi
# get latest release # get latest release
local release local release
release=$(curl -fsSL "https://api.github.com/repos/${source}/releases/latest" | release=$(curl -fsSL "https://api.github.com/repos/${source}/releases/latest" |
jq -r '.tag_name' | sed 's/^v//') jq -r '.tag_name' | sed 's/^v//')
@ -1974,12 +1975,27 @@ check_for_gh_release() {
fi fi
local current="" local current=""
if [[ -f "$current_file" ]]; then [[ -f "$current_file" ]] && current=$(<"$current_file")
current=$(<"$current_file")
# PINNED Releases
if [[ -n "$pinned_version" ]]; then
if [[ "$pinned_version" == "$release" ]]; then
msg_ok "${app} pinned to v${pinned_version} (no update needed)"
return 1
else
if [[ "$current" == "$pinned_version" ]]; then
msg_ok "${app} pinned to v${pinned_version} (already installed, upstream v${release})"
return 1
fi
msg_info "${app} pinned to v${pinned_version} (upstream v${release}) → update/downgrade required"
CHECK_UPDATE_RELEASE="$pinned_version"
return 0
fi
fi fi
if [[ "$release" != "$current" ]] || [[ ! -f "$current_file" ]]; then if [[ "$release" != "$current" ]] || [[ ! -f "$current_file" ]]; then
CHECK_UPDATE_RELEASE="$release" CHECK_UPDATE_RELEASE="$release"
msg_info "New release available: v${release} (current: v${current:-none})"
return 0 return 0
else else
msg_ok "${app} is up to date (v${release})" msg_ok "${app} is up to date (v${release})"