Created
June 25, 2026 00:26
-
-
Save vcheckzen/9915ac999bb0a3bce91d3cfce0bc2ced to your computer and use it in GitHub Desktop.
Setup proot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| BASE_DIR="$HOME/proot-debian" | |
| ROOTFS_DIR="$BASE_DIR/rootfs" | |
| BIN_DIR="$BASE_DIR/bin" | |
| WORK_DIR="$BASE_DIR/workspace" | |
| PROOT="$BIN_DIR/proot" | |
| ENTER="$BASE_DIR/enter.sh" | |
| ROOTFS_FILE="$BASE_DIR/rootfs.tar.xz" | |
| INDEX_BASE="https://images.linuxcontainers.org/images/debian/trixie/amd64/cloud/" | |
| MIRROR_INDEX="https://down.nigx.cn/images.linuxcontainers.org/images/debian/trixie/amd64/cloud/" | |
| mkdir -p "$ROOTFS_DIR" "$BIN_DIR" "$WORK_DIR" | |
| echo "[1/4] Downloading proot..." | |
| PROOT_URL="https://master.dl.sourceforge.net/project/proot.mirror/v5.3.0/proot-v5.3.0-x86_64-static?viasf=1&fid=296683f2ebc377b4" | |
| if [ ! -f "$PROOT" ]; then | |
| wget -q --show-progress -O "$PROOT" "$PROOT_URL" | |
| chmod +x "$PROOT" | |
| fi | |
| echo "[2/4] Resolving rootfs (mirror -> index fallback)..." | |
| download_rootfs() { | |
| # ========================= | |
| # 1. 解析 mirror index | |
| # ========================= | |
| echo "[*] Parsing mirror index..." | |
| MIRROR_HTML=$(wget -q -O - "$MIRROR_INDEX" || true) | |
| MIRROR_DIR=$(echo "$MIRROR_HTML" | \ | |
| grep -oE '[0-9]{8}_[0-9]{2}:[0-9]{2}/' | \ | |
| sort | tail -n 1) | |
| if [ -n "$MIRROR_DIR" ]; then | |
| MIRROR_URL="${MIRROR_INDEX}${MIRROR_DIR}rootfs.tar.xz" | |
| echo "[*] Trying mirror rootfs: $MIRROR_URL" | |
| if wget -q --show-progress -O "$ROOTFS_FILE" "$MIRROR_URL"; then | |
| return 0 | |
| fi | |
| fi | |
| # ========================= | |
| # 2. fallback official index | |
| # ========================= | |
| echo "[*] Mirror failed, parsing official index..." | |
| OFFICIAL_HTML=$(wget -q -O - "$INDEX_BASE") | |
| OFFICIAL_DIR=$(echo "$OFFICIAL_HTML" | \ | |
| grep -oE '[0-9]{8}_[0-9]{2}:[0-9]{2}/' | \ | |
| sort | tail -n 1) | |
| if [ -z "$OFFICIAL_DIR" ]; then | |
| echo "Failed to resolve rootfs directory" | |
| exit 1 | |
| fi | |
| OFFICIAL_URL="${INDEX_BASE}${OFFICIAL_DIR}rootfs.tar.xz" | |
| echo "[*] Downloading official: $OFFICIAL_URL" | |
| wget -q --show-progress -O "$ROOTFS_FILE" "$OFFICIAL_URL" | |
| } | |
| if [ ! -f "$ROOTFS_DIR/bin/bash" ]; then | |
| download_rootfs | |
| echo "[3/4] Extracting rootfs..." | |
| mkdir -p "$ROOTFS_DIR" | |
| tar -xf "$ROOTFS_FILE" -C "$ROOTFS_DIR" | |
| fi | |
| echo "[4/4] Creating launcher..." | |
| cat > "$ENTER" <<EOF | |
| #!/usr/bin/env bash | |
| exec "$PROOT" \ | |
| -S "$ROOTFS_DIR" \ | |
| -b "$WORK_DIR:/workspace" \ | |
| /bin/bash | |
| EOF | |
| chmod +x "$ENTER" | |
| echo "" | |
| echo "✅ Setup complete!" | |
| echo "" | |
| echo "Run:" | |
| echo " $ENTER" | |
| echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment