From 5081a6bc1e481074ede346ec04006c4e625b7628 Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Fri, 21 Aug 2026 08:22:17 +0300 Subject: [PATCH] Refactor installation script for improved archive handling and error logging - Introduced a new variable to determine the type of archive being processed, enhancing the logic for handling different file types. - Updated the installation process to ensure proper extraction of both zip and tar files, improving compatibility with various archive formats. - Enhanced logging to provide clearer feedback on the type of archive being processed, aiding in troubleshooting. - Added error handling to ensure the installation process returns a failure status if the archive does not contain the expected binaries. --- src/gpu_rent/remote/install_llamacpp.sh | 34 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/gpu_rent/remote/install_llamacpp.sh b/src/gpu_rent/remote/install_llamacpp.sh index baca59b..bf71bd9 100644 --- a/src/gpu_rent/remote/install_llamacpp.sh +++ b/src/gpu_rent/remote/install_llamacpp.sh @@ -147,7 +147,7 @@ ensure_vulkan_runtime() { install_from_archive_url() { local url="$1" - local tmp + local tmp kind tmp="$(mktemp -d)" ( cd "$tmp" @@ -158,20 +158,32 @@ install_from_archive_url() { else log "WARN: LLAMACPP_SHA256 не задан — checksum skip" fi - if file pkg.bin | grep -qi zip; then - apt-get install -y -qq unzip >/dev/null 2>&1 || true - unzip -qo pkg.bin -d out - else - mkdir -p out - tar -xaf pkg.bin -C out 2>/dev/null || tar -xzf pkg.bin -C out - fi + mkdir -p out + # Do NOT grep -i zip — that matches "gzip" and breaks .tar.gz. + kind="$(file -b pkg.bin 2>/dev/null || true)" + case "$url" in + *.zip) + apt-get install -y -qq unzip >/dev/null 2>&1 || true + unzip -qo pkg.bin -d out + ;; + *) + if [[ "$kind" == Zip\ archive* ]] || [[ "$kind" == *"Zip archive"* ]]; then + apt-get install -y -qq unzip >/dev/null 2>&1 || true + unzip -qo pkg.bin -d out + else + tar -xaf pkg.bin -C out 2>/dev/null \ + || tar -xzf pkg.bin -C out 2>/dev/null \ + || tar -xf pkg.bin -C out + fi + ;; + esac local found found="$(find out -type f -name 'llama-server' | head -n1 || true)" if [[ -z "$found" ]]; then found="$(find out -type f -name 'server' | head -n1 || true)" fi if [[ -z "$found" ]]; then - log "в архиве нет llama-server" + log "в архиве нет llama-server (file says: ${kind:-unknown})" exit 1 fi install -m 755 "$found" "$SERVER_BIN" @@ -204,7 +216,9 @@ install_linux_release() { else log "WARN: Linux prebuilt без GPU backend (CPU) — ${url##*/}" fi - install_from_archive_url "$url" + if ! install_from_archive_url "$url"; then + return 1 + fi echo "asset:${tag}" >"$STAMP" chown "${SWARM_USER}:${SWARM_USER}" "$STAMP" }