diff --git a/misc/tools.func b/misc/tools.func index 5baa8bb7a..88c7b71c3 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -2482,6 +2482,8 @@ check_for_gh_tag() { # - Does not modify anything, only checks version state # - Does not support pre-releases # ------------------------------------------------------------------------------ +TOOLS_GH_REL_JSON="" + check_for_gh_release() { local app="$1" local source="$2" @@ -2501,6 +2503,10 @@ check_for_gh_release() { ensure_dependencies jq + local gh_check_json + gh_check_json=$(mktemp /tmp/tools-gh-check-XXXXXX.json) || return 7 + trap 'rm -f "$gh_check_json"' RETURN + # Build auth header if token is available local header_args=() [[ -n "${GITHUB_TOKEN:-}" ]] && header_args=(-H "Authorization: Bearer $GITHUB_TOKEN") @@ -2511,14 +2517,14 @@ check_for_gh_release() { # For pinned versions, query the specific release tag directly if [[ -n "$pinned_version_in" ]]; then local pinned_version_encoded="${pinned_version_in//\//%2F}" - http_code=$(curl -sSL --max-time 20 -w "%{http_code}" -o /tmp/gh_check.json \ + http_code=$(curl -sSL --max-time 20 -w "%{http_code}" -o "$gh_check_json" \ -H 'Accept: application/vnd.github+json' \ -H 'X-GitHub-Api-Version: 2022-11-28' \ "${header_args[@]}" \ "https://api.github.com/repos/${source}/releases/tags/${pinned_version_encoded}" 2>/dev/null) || true - if [[ "$http_code" == "200" ]] && [[ -s /tmp/gh_check.json ]]; then - releases_json="[$(/dev/null) || true - if [[ "$http_code" == "200" ]] && [[ -s /tmp/gh_check.json ]]; then - releases_json="[$(/dev/null) || true - if [[ "$http_code" == "200" ]] && [[ -s /tmp/gh_check.json ]]; then - releases_json=$(/dev/null) || true + http_code=$(curl --connect-timeout 10 --max-time "${api_timeouts[$((attempt - 1))]:-240}" -sSL -w "%{http_code}" -o "$gh_rel_json" "${header[@]}" "$api_url" 2>/dev/null) || true if [[ "$http_code" == "200" ]]; then success=true break @@ -3690,7 +3707,7 @@ fetch_and_deploy_gh_release() { fi local json tag_name - json=$( " prompt - if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then - msg_info "Updating Portainer" - docker stop portainer - docker rm portainer - docker pull portainer/portainer-ce:latest - docker run -d \ - -p 9000:9000 \ - -p 9443:9443 \ - --name=portainer \ - --restart=always \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v portainer_data:/data \ - portainer/portainer-ce:latest - msg_ok "Updated Portainer to $PORTAINER_LATEST" + if _docker_is_noninteractive; then + msg_info "Skipping Portainer update prompt (non-interactive)" + else + read -r -p "${TAB3}Update Portainer $PORTAINER_CURRENT → $PORTAINER_LATEST? " prompt + if [[ ${prompt,,} =~ ^(y|yes)$ ]]; then + msg_info "Updating Portainer" + docker stop portainer + docker rm portainer + docker pull portainer/portainer-ce:latest + docker run -d \ + -p 9000:9000 \ + -p 9443:9443 \ + --name=portainer \ + --restart=always \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v portainer_data:/data \ + portainer/portainer-ce:latest + msg_ok "Updated Portainer to $PORTAINER_LATEST" + fi fi else msg_ok "Portainer is up-to-date ($PORTAINER_CURRENT)" @@ -4472,7 +4498,7 @@ EOF fi # Interactive Container Update Check - if [[ "${DOCKER_SKIP_UPDATES:-}" != "true" ]] && [ "$docker_installed" = true ]; then + if [[ "${DOCKER_SKIP_UPDATES:-}" != "true" ]] && [ "$docker_installed" = true ] && ! _docker_is_noninteractive; then msg_info "Checking for container updates" # Get list of running containers with update status @@ -5246,15 +5272,15 @@ setup_hwaccel() { # ══════════════════════════════════════════════════════════════════════════════ # Resolve the IGC tag that the latest compute-runtime was built against. # Must be called AFTER a fetch_and_deploy_gh_release for intel/compute-runtime -# so that /tmp/gh_rel.json contains the compute-runtime release metadata. +# so that TOOLS_GH_REL_JSON contains the compute-runtime release metadata. # Sets the variable named by $1 (default: igc_tag) to the discovered tag. # ══════════════════════════════════════════════════════════════════════════════ _resolve_igc_tag() { local -n _out_ref="${1:-igc_tag}" _out_ref="latest" - if [[ -f /tmp/gh_rel.json ]]; then + if [[ -n "${TOOLS_GH_REL_JSON:-}" && -f "$TOOLS_GH_REL_JSON" ]]; then local _body _parsed - _body=$(jq -r '.body // empty' /tmp/gh_rel.json 2>/dev/null) || return 0 + _body=$(jq -r '.body // empty' "$TOOLS_GH_REL_JSON" 2>/dev/null) || return 0 _parsed=$(grep -oP 'intel-graphics-compiler/releases/tag/\K[^\s\)]+' <<<"$_body" | head -1) [[ -n "$_parsed" ]] && _out_ref="$_parsed" fi @@ -5288,7 +5314,7 @@ _setup_intel_arc() { if [[ "$os_codename" == "trixie" || "$os_codename" == "sid" ]]; then msg_info "Fetching Intel compute-runtime from GitHub for Arc support" - # Fetch a compute-runtime package first so /tmp/gh_rel.json is populated, + # Fetch a compute-runtime package first so TOOLS_GH_REL_JSON is populated, # then resolve the matching IGC tag from the release notes. # libigdgmm - bundled in compute-runtime releases fetch_and_deploy_gh_release "libigdgmm12" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" || true @@ -5352,7 +5378,7 @@ _setup_intel_modern() { if [[ "$os_codename" == "trixie" || "$os_codename" == "sid" ]]; then msg_info "Fetching Intel compute-runtime from GitHub" - # Fetch a compute-runtime package first so /tmp/gh_rel.json is populated, + # Fetch a compute-runtime package first so TOOLS_GH_REL_JSON is populated, # then resolve the matching IGC tag from the release notes. # libigdgmm first (bundled in compute-runtime releases) fetch_and_deploy_gh_release "libigdgmm12" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" || true @@ -6727,24 +6753,13 @@ setup_meilisearch() { fi fi - # If migration is needed but dump failed, we have options: - # 1. Abort the update (safest, but annoying) - # 2. Backup data directory and proceed (allows manual recovery) - # 3. Just proceed and hope for the best (dangerous) - # We choose option 2: backup and proceed with warning if [[ "$NEEDS_MIGRATION" == "true" ]] && [[ -z "$DUMP_UID" ]]; then - local MEILI_DB_PATH - MEILI_DB_PATH=$(grep -E "^db_path\s*=" /etc/meilisearch.toml 2>/dev/null | sed 's/.*=\s*"\(.*\)"/\1/' | tr -d ' ' || true) - MEILI_DB_PATH="${MEILI_DB_PATH:-/var/lib/meilisearch/data}" - - if [[ -d "$MEILI_DB_PATH" ]] && [[ -n "$(ls -A "$MEILI_DB_PATH" 2>/dev/null)" ]]; then - local BACKUP_PATH="${MEILI_DB_PATH}.backup.$(date +%Y%m%d%H%M%S)" - msg_warn "Backing up MeiliSearch data to ${BACKUP_PATH}" - mv "$MEILI_DB_PATH" "$BACKUP_PATH" - mkdir -p "$MEILI_DB_PATH" - msg_info "Data backed up. After update, you may need to reindex your data." - msg_info "Old data is preserved at: ${BACKUP_PATH}" + msg_error "MeiliSearch migration requires a successful dump before upgrade" + msg_error "Ensure the service is running and master_key is configured, or set MEILISEARCH_SKIP_MIGRATION=1 to force (data loss risk)" + if [[ "${MEILISEARCH_SKIP_MIGRATION:-}" != "1" ]]; then + return 100 fi + msg_warn "MEILISEARCH_SKIP_MIGRATION=1 — proceeding without dump (manual reindex may be required)" fi # Stop service and update binary @@ -9041,6 +9056,10 @@ check_for_gl_release() { ensure_dependencies jq + local gl_check_json + gl_check_json=$(mktemp /tmp/tools-gl-check-XXXXXX.json) || return 7 + trap 'rm -f "$gl_check_json"' RETURN + local repo_encoded repo_encoded=$(printf '%s' "$source" | sed 's|/|%2F|g') @@ -9052,23 +9071,23 @@ check_for_gl_release() { # For pinned versions, try to fetch the specific release tag first if [[ -n "$pinned_version_in" ]]; then local pinned_encoded="${pinned_version_in//\//%2F}" - http_code=$(curl -sSL --max-time 20 -w "%{http_code}" -o /tmp/gl_check.json \ + http_code=$(curl -sSL --max-time 20 -w "%{http_code}" -o "$gl_check_json" \ "${header[@]}" \ "https://gitlab.com/api/v4/projects/$repo_encoded/releases/$pinned_encoded" 2>/dev/null) || true - if [[ "$http_code" == "200" ]] && [[ -s /tmp/gl_check.json ]]; then - releases_json="[$(/dev/null) || true - if [[ "$http_code" == "200" ]] && [[ -s /tmp/gl_check.json ]]; then - releases_json=$(/dev/null) || true + http_code=$(curl $api_timeout -sSL -w "%{http_code}" -o "$gl_rel_json" "${header[@]}" "$api_url" 2>/dev/null) || true if [[ "$http_code" == "200" ]]; then success=true break @@ -9375,7 +9398,7 @@ fetch_and_deploy_gl_release() { fi local json tag_name - json=$(