From 6cb93883e203efdd4aba00872970d2cf04143c5d Mon Sep 17 00:00:00 2001 From: Huy Nguyen <79745143+34306@users.noreply.github.com> Date: Mon, 2 Mar 2026 22:34:10 +0700 Subject: [PATCH] fix the download if not exist and hash check the file to make sure it's not corrupted --- .DS_Store | Bin 6148 -> 6148 bytes README.md | 47 +++++++++++++++++----- vphone-aio.sh | 106 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 129 insertions(+), 24 deletions(-) diff --git a/.DS_Store b/.DS_Store index a70cffd78e6be41f5df58cc255019c05670f4462..9812a6fba9971f54866c3b9268afa429428cdae5 100644 GIT binary patch delta 194 zcmZoMXfc=|#>B`mu~2NHo}wTt0|Nsi1A_oVN^x>dQht8UWI@K&Vjxi#20ey!hD?SM zm<+?j9?7^^!vn~2x%n){WZ k1sU_%HnVf^a{yfkCJ*F;Q%yo}wrV0|Nsi1A_oVPP$=ma(-?Bkk2$RQJs-xvLd4-vysvL z$+nCVY@Z$mUaeU/dev/null 2>&1 || { + echo "ERROR: wget not found. Install with: brew install wget" + exit 1 + } + + echo " Some split parts are missing. Downloading..." + echo "" + for suffix in "${ALL_SUFFIXES[@]}"; do + local part_file="$SCRIPT_DIR/vphone-cli.tar.zst.part_${suffix}" + if [ ! -f "$part_file" ]; then + echo " Downloading vphone-cli.tar.zst.part_${suffix} ..." + wget -q --show-progress -O "$part_file" \ + "${REPO_URL}/vphone-cli.tar.zst.part_${suffix}?download=" || { + echo "ERROR: Failed to download part_${suffix}" + rm -f "$part_file" + exit 1 + } + fi + done + echo "" + fi +} + +verify_hashes() { + echo " Verifying SHA-256 checksums..." + local failed=false + for suffix in "${ALL_SUFFIXES[@]}"; do + local part_file="$SCRIPT_DIR/vphone-cli.tar.zst.part_${suffix}" + local expected="${PART_HASHES[$suffix]}" + local actual + actual="$(shasum -a 256 "$part_file" | awk '{print $1}')" + if [ "$actual" != "$expected" ]; then + echo " FAIL: part_${suffix} (expected ${expected:0:12}... got ${actual:0:12}...)" + failed=true + else + echo " OK: part_${suffix}" + fi + done + if $failed; then + echo "" + echo "ERROR: Hash verification failed. Some files may be corrupted." + echo " Delete the bad parts and re-run this script to re-download them." + exit 1 + fi + echo " All checksums passed." +} + # ── Merge split parts & extract if needed ──────────────────────── if [ ! -d "$PROJECT" ]; then command -v zstd >/dev/null 2>&1 || { @@ -81,39 +155,41 @@ if [ ! -d "$PROJECT" ]; then # Merge split parts if the full archive doesn't exist yet if [ ! -f "$ARCHIVE" ]; then - PARTS=("$SCRIPT_DIR"/vphone-cli.tar.zst.part_*) - if [ ${#PARTS[@]} -eq 0 ] || [ ! -f "${PARTS[0]}" ]; then - echo "ERROR: No vphone-cli.tar.zst or split parts found." - echo "Make sure vphone-cli.tar.zst.part_* files are next to this script." - exit 1 - fi + echo "[1/5] Checking split parts..." + download_missing_parts - echo "[1/4] Merging ${#PARTS[@]} split parts into vphone-cli.tar.zst ..." + echo "[2/5] Verifying integrity of split parts..." + verify_hashes + echo "" + + PARTS=("$SCRIPT_DIR"/vphone-cli.tar.zst.part_*) + echo "[3/5] Merging ${#PARTS[@]} split parts into vphone-cli.tar.zst ..." cat "$SCRIPT_DIR"/vphone-cli.tar.zst.part_* > "$ARCHIVE" echo " Done. ($(du -h "$ARCHIVE" | cut -f1))" echo "" - echo "[2/4] Extracting vphone-cli.tar.zst ..." + echo "[4/5] Extracting vphone-cli.tar.zst ..." else - echo "[1/4] vphone-cli.tar.zst already exists, skipping merge." + echo "[1/5] vphone-cli.tar.zst already exists, skipping download & merge." echo "" - echo "[2/4] Extracting vphone-cli.tar.zst ..." + echo "[4/5] Extracting vphone-cli.tar.zst ..." fi zstd -dc "$ARCHIVE" | tar xf - -C "$SCRIPT_DIR" echo " Done." - # Clean up the merged archive to save disk space + # Clean up the merged archive and split parts to save disk space rm -f "$ARCHIVE" - echo " Cleaned up archive to save space." + rm -f "$SCRIPT_DIR"/vphone-cli.tar.zst.part_* + echo " Cleaned up archive and split parts to save space." else - echo "[1/4] vphone-cli/ already exists, skipping merge & extraction." + echo "[1/5] vphone-cli/ already exists, skipping merge & extraction." fi echo "" # ── Start iproxy tunnels ───────────────────────────────────────── -echo "[3/4] Starting iproxy tunnels ..." +echo "[4/5] Starting iproxy tunnels ..." iproxy 22222 22222 >/dev/null 2>&1 & IPROXY_SSH_PID=$! @@ -125,7 +201,7 @@ echo " VNC : localhost:5901 -> device:5901" # ── Build & Boot VM ────────────────────────────────────────────── echo "" -echo "[4/4] Building and booting the VM ..." +echo "[5/5] Building and booting the VM ..." echo "" echo "==========================================" echo ""