qf: create file if not exist

This commit is contained in:
CanbiZ 2025-08-29 16:20:21 +02:00
parent 36bf265fc6
commit bc545df207
2 changed files with 44 additions and 28 deletions

View File

@ -27,7 +27,7 @@ function update_script() {
msg_error "No ${APP} Installation Found!" msg_error "No ${APP} Installation Found!"
exit exit
fi fi
if check_for_gh_release "paperless-ngx" "paperless-ngx/paperless-ngx"; then if check_for_gh_release "paperless" "paperless-ngx/paperless-ngx"; then
msg_info "Stopping all Paperless-ngx Services" msg_info "Stopping all Paperless-ngx Services"
systemctl stop paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue systemctl stop paperless-consumer paperless-webserver paperless-scheduler paperless-task-queue
msg_ok "Stopped all Paperless-ngx Services" msg_ok "Stopped all Paperless-ngx Services"

View File

@ -1964,75 +1964,91 @@ check_for_gh_release() {
} }
fi fi
# Fetch all releases (newest → oldest) # Fetch releases (newest → oldest)
local releases local releases=""
releases=$(curl -fsSL "https://api.github.com/repos/${source}/releases" | releases=$(
jq -r '.[].tag_name' | sed 's/^v//') curl -fsSL --max-time 15 \
-H 'Accept: application/vnd.github+json' \
-H 'X-GitHub-Api-Version: 2022-11-28' \
"https://api.github.com/repos/${source}/releases" |
jq -r '.[].tag_name' | sed 's/^v//'
) || true
if [[ -z "$releases" ]]; then if [[ -z "$releases" ]]; then
msg_error "Unable to fetch releases for ${app}" msg_error "Unable to fetch releases for ${app}"
return 1 return 1
fi fi
# Define current and latest versions
local latest current local latest current
latest=$(echo "$releases" | head -n1) latest=$(echo "$releases" | head -n1)
[[ -f "$current_file" ]] && current=$(<"$current_file") current=""
if [[ -f "$current_file" ]]; then
current="$(<"$current_file")"
fi
# helper: get index (lower index = newer) # Helper: get index of a version (lower = newer)
get_index() { get_index() {
local ver="$1" local ver="${1:-}"
echo "$releases" | nl -ba | grep -w "$ver" | awk '{print $1}' [[ -z "$ver" ]] && return 1
local idx
idx=$(nl -ba <<<"$releases" | awk -v v="$ver" '$2==v{print $1; exit}')
[[ -n "$idx" ]] || return 1
echo "$idx"
} }
# --- Pinning enabled --- # Pinning enabled
if [[ -n "$pinned_version" ]]; then if [[ -n "$pinned_version" ]]; then
# Ensure pin exists upstream if ! grep -qxF "$pinned_version" <<<"$releases"; then
if ! echo "$releases" | grep -qx "$pinned_version"; then msg_error "Pinned version v${pinned_version} not found upstream"
msg_error "Pinned version v${pinned_version} not found in upstream releases!"
return 1 return 1
fi fi
local pinned_index current_index
pinned_index=$(get_index "$pinned_version")
current_index=$(get_index "$current")
if [[ -z "$current" ]]; then if [[ -z "$current" ]]; then
msg_info "${app} pinned to v${pinned_version}, no local version → install required" msg_info "${app} pinned to v${pinned_version}, no local version → install required"
CHECK_UPDATE_RELEASE="$pinned_version" CHECK_UPDATE_RELEASE="$pinned_version"
: >"$current_file"
return 0 return 0
fi fi
if [[ "$current" == "$pinned_version" ]]; then if [[ "$current" == "$pinned_version" ]]; then
if [[ "$pinned_version" == "$latest" ]]; then if [[ "$pinned_version" == "$latest" ]]; then
msg_ok "${app} pinned to v${pinned_version} (no update needed)" msg_ok "${app} pinned to v${pinned_version} (up to date)"
else else
msg_ok "${app} pinned to v${pinned_version} (already installed, upstream v${latest})" msg_ok "${app} pinned to v${pinned_version} (already installed, upstream v${latest})"
fi fi
return 1 return 1
fi fi
# Local older than pinned → update local pinned_index current_index
pinned_index="$(get_index "$pinned_version" || true)"
current_index="$(get_index "$current" || true)"
if [[ -z "$current_index" ]] || [[ "$current_index" -gt "$pinned_index" ]]; then if [[ -z "$current_index" ]] || [[ "$current_index" -gt "$pinned_index" ]]; then
msg_info "${app} pinned to v${pinned_version} (installed v${current:-none}) → update required" msg_info "${app} pinned to v${pinned_version} (installed v${current:-none}) → update required"
CHECK_UPDATE_RELEASE="$pinned_version" CHECK_UPDATE_RELEASE="$pinned_version"
: >"$current_file"
return 0 return 0
fi fi
# Local newer than pinned → downgrade
if [[ "$current_index" -lt "$pinned_index" ]]; then if [[ "$current_index" -lt "$pinned_index" ]]; then
msg_info "${app} pinned to v${pinned_version} (installed newer v${current}) → downgrade required" msg_info "${app} pinned to v${pinned_version} (installed newer v${current}) → downgrade required"
CHECK_UPDATE_RELEASE="$pinned_version" CHECK_UPDATE_RELEASE="$pinned_version"
: >"$current_file"
return 0 return 0
fi fi
fi
# --- No pin → compare against latest ---
if [[ "$current" != "$latest" ]] || [[ -z "$current" ]]; then
CHECK_UPDATE_RELEASE="$latest"
msg_info "New release available: v${latest} (current: v${current:-none})"
return 0
else
msg_ok "${app} is up to date (v${latest})"
return 1 return 1
fi fi
# No pinning → compare against latest
if [[ -z "$current" || "$current" != "$latest" ]]; then
CHECK_UPDATE_RELEASE="$latest"
msg_info "New release available: v${latest} (current: v${current:-none})"
: >"$current_file"
return 0
fi
msg_ok "${app} is up to date (v${latest})"
return 1
} }