From d361d23a2d2326968b50b9b311a8b5c74036fc46 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 7 Jul 2025 19:50:00 +0200 Subject: [PATCH] Update tools.func --- misc/tools.func | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/misc/tools.func b/misc/tools.func index 7b9b0490..0547d2f0 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -929,13 +929,27 @@ function fetch_and_deploy_gh_release() { if ! command -v unzip &>/dev/null; then $STD apt-get install -y unzip fi - $STD unzip "$tmpdir/$filename" -d "$target" + + local top_level_entries + top_level_entries=$(unzip -l "$tmpdir/$filename" | awk '{print $4}' | grep -v '^$' | cut -d/ -f1 | sort -u) + + if [[ $(wc -l <<<"$top_level_entries") -eq 1 ]]; then + unzip -q "$tmpdir/$filename" -d "$tmpdir/unzip" + shopt -s dotglob nullglob + cp -r "$tmpdir/unzip/"* "$target/" + shopt -u dotglob nullglob + else + unzip -q "$tmpdir/$filename" -d "$target" + fi + elif [[ "$filename" == *.tar.* ]]; then - if tar -tf "$tmpdir/$filename" | grep -qE '^([^/]+/){2}'; then + local top_level_entries + top_level_entries=$(tar -tf "$tmpdir/$filename" | cut -d/ -f1 | sort -u) + + if [[ $(wc -l <<<"$top_level_entries") -eq 1 ]]; then tar --strip-components=1 -xf "$tmpdir/$filename" -C "$target" else tar -xf "$tmpdir/$filename" -C "$target" - fi else msg_error "Unsupported archive format: $filename" rm -rf "$tmpdir"