Created
September 17, 2025 05:54
-
-
Save Bonveio/bb8cb10f8f514611e8395c5f935670d7 to your computer and use it in GitHub Desktop.
A simple shell script to download and extract specific Termux (.deb) packages for multiple architectures. Useful for creating a local multi-arch repository.
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
| #!/bin/sh | |
| # A simple shell script to download and extract specific Termux (.deb) packages for multiple architectures. | |
| # Configuration | |
| base_url="https://packages.termux.dev/apt/termux-main/pool/main" | |
| package_dirs="o/openssl/ o/openssl-static/ o/openssl-tool/ a/argp/ a/argp-static/ b/brotli/ p/pkg-config/" | |
| architectures="aarch64 arm" | |
| base_dir="/opt/d" | |
| check_commands() { | |
| for cmd in wget awk dpkg-deb; do | |
| if ! command -v "$cmd" >/dev/null 2>&1; then | |
| echo "Error: $cmd is not available." >&2 | |
| exit 1 | |
| fi | |
| done | |
| } | |
| check_commands | |
| mkdir -p "$base_dir" | |
| # Process each package directory | |
| for pkg_dir in $package_dirs; do | |
| # Fetch directory listing | |
| index_html=$(wget -q -O - "$base_url/$pkg_dir") || { | |
| echo "Failed to fetch $base_url/$pkg_dir" >&2 | |
| continue | |
| } | |
| # Process each architecture | |
| for arch in $architectures; do | |
| # Extract all candidate package URLs for this arch | |
| package_list=$( | |
| printf '%s' "$index_html" | | |
| awk -v arch="$arch" ' | |
| /href="[^"]+\.deb"/ { | |
| n = match($0, /href="[^"]+\.deb"/) | |
| if (n) { | |
| href = substr($0, RSTART+6, RLENGTH-7) | |
| if (href !~ /\.\.\//) { | |
| if (href ~ arch) { | |
| print href | |
| } | |
| } | |
| } | |
| }' | |
| ) | |
| # Download + extract each package found | |
| for package_info in $package_list; do | |
| pkg_name=$(printf '%s' "$package_info" | awk -F/ '{print $NF}' | sed 's/%3A/:/g') | |
| echo "Downloading $pkg_name..." | |
| wget -q -O "/tmp/$pkg_name" "$base_url/$pkg_dir$package_info" || { | |
| echo "Failed to download $pkg_name" >&2 | |
| continue | |
| } | |
| arch_dir="$base_dir/$arch" | |
| mkdir -p "$arch_dir" | |
| echo "Extracting $pkg_name to $arch_dir..." | |
| dpkg-deb -x "/tmp/$pkg_name" "$arch_dir" | |
| done | |
| done | |
| done | |
| echo "Cleaning up..." | |
| rm -f /tmp/*.deb | |
| echo "Extracted files:" | |
| find "$base_dir" -type f | sort |
Comments are disabled for this gist.