#!/bin/bash # ============================================================================ # Name : fetch_release.sh # Description : Fetches a GitHub release, downloads all assets (including # source code), and generates a Debian-style changelog README. # ============================================================================ # Configuration variables REPO="termux/proot-distro" TAG="v4.29.0" PKG_NAME="proot-distro" DIR_NAME="${PKG_NAME}-${TAG}" API_URL="https://api.github.com/repos/${REPO}/releases/tags/${TAG}" # Ensure required tools are installed if ! command -v curl &> /dev/null || ! command -v jq &> /dev/null; then echo "Error: 'curl' and 'jq' are required. Please install them." exit 1 fi echo "Fetching release data for ${REPO} at tag ${TAG}..." RELEASE_JSON=$(curl -s "$API_URL") # Validate if the release exists if echo "$RELEASE_JSON" | grep -q '"message": "Not Found"'; then echo "Error: Release not found!" exit 1 fi # Extract metadata using jq VERSION=$(echo "$RELEASE_JSON" | jq -r '.tag_name') AUTHOR=$(echo "$RELEASE_JSON" | jq -r '.author.login') DATE_RAW=$(echo "$RELEASE_JSON" | jq -r '.published_at') BODY=$(echo "$RELEASE_JSON" | jq -r '.body') TARBALL_URL=$(echo "$RELEASE_JSON" | jq -r '.tarball_url') ZIPBALL_URL=$(echo "$RELEASE_JSON" | jq -r '.zipball_url') # Format date to RFC 2822 (Standard Debian changelog style) if possible # Fallback to the raw ISO 8601 date if 'date -d' is not supported (e.g., macOS/BSD) DATE_FORMATTED=$(date -d "$DATE_RAW" -R 2>/dev/null || echo "$DATE_RAW") # Create and enter the release directory echo "Creating directory: ${DIR_NAME}..." mkdir -p "$DIR_NAME" cd "$DIR_NAME" || exit 1 # Generate the Debian-style README.txt echo "Generating README.txt..." cat < README.txt ${PKG_NAME} - ${VERSION} ${BODY} -- ${AUTHOR} - ${DATE_FORMATTED} EOF # Download all compiled assets attached to the release echo "Downloading release assets..." echo "$RELEASE_JSON" | jq -r '.assets[] | "\(.browser_download_url) \(.name)"' | while read -r url name; do if [ -n "$url" ] && [ "$url" != "null" ]; then echo " -> Downloading ${name}..." curl -L -# -o "$name" "$url" fi done # Download source code archives echo "Downloading source code (tar.gz)..." curl -L -# -o "${PKG_NAME}-${VERSION}-source.tar.gz" "$TARBALL_URL" echo "Downloading source code (zip)..." curl -L -# -o "${PKG_NAME}-${VERSION}-source.zip" "$ZIPBALL_URL" echo "========================================" echo "Done! All files saved in: ./${DIR_NAME}/" ls -lh