#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ARCHIVE_DIR="${ROOT_DIR}/archives" for archive in "${ARCHIVE_DIR}"/*.zip; do [ -e "${archive}" ] || continue echo "[unpack] ${archive}" split_head="${archive%.zip}.z01" if [ -f "${split_head}" ]; then if command -v 7z >/dev/null 2>&1; then 7z x "${archive}" -o"${ROOT_DIR}" continue fi if command -v zip >/dev/null 2>&1 && command -v unzip >/dev/null 2>&1; then merged_zip="${ROOT_DIR}/.$(basename "${archive%.zip}")_merged.zip" rm -f "${merged_zip}" zip "${archive}" -s 0 --out "${merged_zip}" unzip -oq "${merged_zip}" -d "${ROOT_DIR}" rm -f "${merged_zip}" continue fi echo "[skip] need 7z or zip+unzip for split archive ${archive}" >&2 continue fi if command -v unzip >/dev/null 2>&1; then unzip -oq "${archive}" -d "${ROOT_DIR}" else python3 -m zipfile -e "${archive}" "${ROOT_DIR}" fi done