diff --git a/misc/tools.func b/misc/tools.func index 19ca7435..2b8a2a5b 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -449,7 +449,7 @@ function setup_php() { $STD apt-get install -y apache2 $STD systemctl restart apache2 || true fi - + if [[ "$PHP_APACHE" == "YES" ]] && [[ -n "$CURRENT_PHP" ]]; then if [[ -f /etc/apache2/mods-enabled/php${CURRENT_PHP}.load ]]; then $STD a2dismod php${CURRENT_PHP} || true @@ -914,7 +914,7 @@ function fetch_and_deploy_gh_release() { } } - ### Prebuild Mode ### + ### Prebuild Mode ### elif [[ "$mode" == "prebuild" ]]; then local pattern="${6%\"}" pattern="${pattern#\"}" @@ -933,7 +933,6 @@ function fetch_and_deploy_gh_release() { break ;; esac - done [[ -z "$asset_url" ]] && { @@ -949,39 +948,42 @@ function fetch_and_deploy_gh_release() { return 1 } + local unpack_tmp + unpack_tmp=$(mktemp -d) mkdir -p "$target" + if [[ "$filename" == *.zip ]]; then if ! command -v unzip &>/dev/null; then $STD apt-get install -y unzip fi - - 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 - + unzip -q "$tmpdir/$filename" -d "$unpack_tmp" elif [[ "$filename" == *.tar.* ]]; 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 + tar -xf "$tmpdir/$filename" -C "$unpack_tmp" else msg_error "Unsupported archive format: $filename" - rm -rf "$tmpdir" + rm -rf "$tmpdir" "$unpack_tmp" return 1 fi + local top_dirs + top_dirs=$(find "$unpack_tmp" -mindepth 1 -maxdepth 1 -type d | wc -l) + + if [[ "$top_dirs" -eq 1 ]]; then + # Strip leading folder + local inner_dir + inner_dir=$(find "$unpack_tmp" -mindepth 1 -maxdepth 1 -type d) + shopt -s dotglob nullglob + cp -r "$inner_dir"/* "$target/" + shopt -u dotglob nullglob + else + # Copy all contents + shopt -s dotglob nullglob + cp -r "$unpack_tmp"/* "$target/" + shopt -u dotglob nullglob + fi + + rm -rf "$unpack_tmp" + ### Singlefile Mode ### elif [[ "$mode" == "singlefile" ]]; then local pattern="${6%\"}"