#!/usr/bin/bash set -euo pipefail IFS=$'\n\t' SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" if [[ -d "${SCRIPT_DIR}/../../.git" ]] || [[ -f "${SCRIPT_DIR}/../../nodo/config/etc/mirrors.env" ]]; then REPO_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" else REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" fi if [[ -f "${REPO_ROOT}/nodo/config/etc/mirrors.env" ]]; then # shellcheck source=/dev/null source "${REPO_ROOT}/nodo/config/etc/mirrors.env" elif [[ -f "${REPO_ROOT}/config/etc/mirrors.env" ]]; then # shellcheck source=/dev/null source "${REPO_ROOT}/config/etc/mirrors.env" elif [[ -f "${REPO_ROOT}/etc/mirrors.env" ]]; then # shellcheck source=/dev/null source "${REPO_ROOT}/etc/mirrors.env" fi STAGING_DIR="${MIRRORS_STAGING_DIR:-$HOME/ipfs/staging}" get_dir_size() { local dir="$1" if [[ -d "${dir}" ]]; then du -sh "${dir}" 2>/dev/null | cut -f1 else echo "0 B" fi } main() { local format="${1:-table}" local force="${2:-}" local cache_file="/tmp/mxos-sizes-cache.json" if [[ "${format}" == "json" && "${force}" != "--force" && -f "${cache_file}" ]]; then local cache_age cache_age=$(($(date +%s) - $(stat -c %Y "${cache_file}"))) if (( cache_age < 14400 )); then cat "${cache_file}" return 0 fi fi local sz_f43_everything local sz_f44_everything local sz_f45_everything local sz_fedora_iso local sz_f43_iso local sz_f44_iso local sz_f45_iso local sz_centos_core local sz_centos_sigs local sz_centos_iso local sz_total sz_f43_everything="$(get_dir_size "${STAGING_DIR}/fedora/releases/43/Everything")" sz_f44_everything="$(get_dir_size "${STAGING_DIR}/fedora/releases/44/Everything")" sz_f45_everything="$(get_dir_size "${STAGING_DIR}/fedora/releases/45/Everything")" sz_fedora_iso="$(get_dir_size "${STAGING_DIR}/fedora/iso")" sz_f43_iso="$(get_dir_size "${STAGING_DIR}/fedora/iso/43")" sz_f44_iso="$(get_dir_size "${STAGING_DIR}/fedora/iso/44")" sz_f45_iso="$(get_dir_size "${STAGING_DIR}/fedora/iso/45")" sz_centos_core="$(get_dir_size "${STAGING_DIR}/centos-stream/10-stream")" sz_centos_sigs="$(get_dir_size "${STAGING_DIR}/centos-stream/SIGs/10-stream")" sz_centos_iso="$(get_dir_size "${STAGING_DIR}/centos-stream/10-stream/iso")" sz_total="$(get_dir_size "${STAGING_DIR}")" if [[ "${format}" == "json" ]]; then cat << JSON { "fedora43_everything": { "path": "/ipns/mirrors.mx-os.mx/fedora/releases/43/Everything", "current_size": "${sz_f43_everything}", "estimate": "125 GB" }, "fedora44_everything": { "path": "/ipns/mirrors.mx-os.mx/fedora/releases/44/Everything", "current_size": "${sz_f44_everything}", "estimate": "125 GB" }, "fedora45_everything": { "path": "/ipns/mirrors.mx-os.mx/fedora/releases/45/Everything", "current_size": "${sz_f45_everything}", "estimate": "125 GB" }, "fedora_iso": { "path": "/ipns/mirrors.mx-os.mx/fedora/iso", "current_size": "${sz_fedora_iso}", "estimate": "30 GB" }, "fedora43_iso": { "path": "/ipns/mirrors.mx-os.mx/fedora/iso/43", "current_size": "${sz_f43_iso}", "estimate": "8 GB" }, "fedora44_iso": { "path": "/ipns/mirrors.mx-os.mx/fedora/iso/44", "current_size": "${sz_f44_iso}", "estimate": "8 GB" }, "fedora45_iso": { "path": "/ipns/mirrors.mx-os.mx/fedora/iso/45", "current_size": "${sz_f45_iso}", "estimate": "10 GB" }, "centos_stream10": { "path": "/ipns/mirrors.mx-os.mx/centos-stream/10-stream", "current_size": "${sz_centos_core}", "estimate": "80 GB" }, "centos_stream10_sigs": { "path": "/ipns/mirrors.mx-os.mx/centos-stream/SIGs/10-stream", "current_size": "${sz_centos_sigs}", "estimate": "25 GB" }, "centos_stream10_iso": { "path": "/ipns/mirrors.mx-os.mx/centos-stream/10-stream/iso", "current_size": "${sz_centos_iso}", "estimate": "12 GB" }, "total": { "path": "/ipns/mirrors.mx-os.mx", "current_size": "${sz_total}", "estimate": "500 GB" } } JSON elif [[ "${format}" == "update-readme" || "${format}" == "--update-readme" ]]; then local readme_file="${REPO_ROOT}/README.rst" echo "==> Actualizando tamaños medidos en ${readme_file}..." SZ_F43="${sz_f43_everything}" \ SZ_F44="${sz_f44_everything}" \ SZ_F45="${sz_f45_everything}" \ SZ_CENTOS_CORE="${sz_centos_core}" \ SZ_CENTOS_SIGS="${sz_centos_sigs}" \ SZ_TOTAL="${sz_total}" \ perl -i -pe ' if ($in_f43) { s/^(\s+-\s+).*/${1}$ENV{SZ_F43}/; $in_f43 = 0; } if (/Fedora 43 Everything/) { $in_f43_row = 1; } if ($in_f43_row && /fedora\/releases\/43\/Everything/) { $in_f43 = 1; $in_f43_row = 0; } if ($in_f44) { s/^(\s+-\s+).*/${1}$ENV{SZ_F44}/; $in_f44 = 0; } if (/Fedora 44 Everything/) { $in_f44_row = 1; } if ($in_f44_row && /fedora\/releases\/44\/Everything/) { $in_f44 = 1; $in_f44_row = 0; } if ($in_f45) { s/^(\s+-\s+).*/${1}$ENV{SZ_F45}/; $in_f45 = 0; } if (/Fedora 45 Everything/) { $in_f45_row = 1; } if ($in_f45_row && /fedora\/releases\/45\/Everything/) { $in_f45 = 1; $in_f45_row = 0; } if ($in_centos_core) { s/^(\s+-\s+).*/${1}$ENV{SZ_CENTOS_CORE}/; $in_centos_core = 0; } if (/\*\*CentOS Stream 10\*\*/) { $in_centos_core_row = 1; } if ($in_centos_core_row && /centos-stream\/10-stream`/) { $in_centos_core = 1; $in_centos_core_row = 0; } if ($in_centos_sigs) { s/^(\s+-\s+).*/${1}$ENV{SZ_CENTOS_SIGS}/; $in_centos_sigs = 0; } if (/CentOS Stream 10 SIGs/) { $in_centos_sigs_row = 1; } if ($in_centos_sigs_row && /centos-stream\/SIGs\/10-stream/) { $in_centos_sigs = 1; $in_centos_sigs_row = 0; } if ($in_total) { s/^(\s+-\s+).*/${1}$ENV{SZ_TOTAL}/; $in_total = 0; } if (/Catálogo Completo/) { $in_total_row = 1; } if ($in_total_row && /ipfs pin add \/ipns\/mirrors\.mx-os\.mx$/) { $in_total = 1; $in_total_row = 0; } ' "${readme_file}" echo "==> Recompilando documentación HTML..." "${SCRIPT_DIR}/mxos-build-html.bash" echo "==> Actualización completada." else cat << TABLE ==================================================================================================== Módulos de Enclavillado Comunitario (IPFS) Directorio de staging: ${STAGING_DIR} ==================================================================================================== Módulo Ruta IPNS Actual Estimado ---------------------------------------------------------------------------------------------------- 1. Fedora 43 Everything /ipns/mirrors.mx-os.mx/fedora/releases/43/... ${sz_f43_everything:-0B} ~125 GB 2. Fedora 44 Everything /ipns/mirrors.mx-os.mx/fedora/releases/44/... ${sz_f44_everything:-0B} ~125 GB 3. Fedora 45 Everything /ipns/mirrors.mx-os.mx/fedora/releases/45/... ${sz_f45_everything:-0B} ~125 GB 4. Fedora ISOs /ipns/mirrors.mx-os.mx/fedora/iso ${sz_fedora_iso:-0B} ~30 GB 5. Fedora 43 ISO /ipns/mirrors.mx-os.mx/fedora/iso/43 ${sz_f43_iso:-0B} ~8 GB 6. Fedora 44 ISO /ipns/mirrors.mx-os.mx/fedora/iso/44 ${sz_f44_iso:-0B} ~8 GB 7. Fedora 45 ISO /ipns/mirrors.mx-os.mx/fedora/iso/45 ${sz_f45_iso:-0B} ~10 GB 8. CentOS Stream 10 /ipns/mirrors.mx-os.mx/centos-stream/10-stream ${sz_centos_core:-0B} ~80 GB 9. CentOS Stream 10 SIGs /ipns/mirrors.mx-os.mx/centos-stream/SIGs/... ${sz_centos_sigs:-0B} ~25 GB 10. CentOS Stream 10 ISO /ipns/mirrors.mx-os.mx/centos-stream/10-s... ${sz_centos_iso:-0B} ~12 GB 11. Catálogo Completo /ipns/mirrors.mx-os.mx ${sz_total:-0B} ~500 GB ==================================================================================================== TABLE fi } main "$@"