feature/generador-instaladores-linux-windows
This commit is contained in:
131
build-all.sh
Executable file
131
build-all.sh
Executable file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env bash
|
||||
# =============================================================================
|
||||
# CloudRestoreAS — build de TODO en una sola tarea (ejecutar desde WSL).
|
||||
#
|
||||
# Linux : build en Docker (ubuntu:22.04) -> dist/CloudRestoreAS (autocontenido)
|
||||
# Windows: build vía powershell.exe -> build.ps1 -> dist/CloudRestoreAS.exe
|
||||
# Paquete: dist/release/CloudRestoreAS-linux.tar.gz y CloudRestoreAS-win.zip
|
||||
#
|
||||
# Uso:
|
||||
# ./build-all.sh # ambos + empaquetado
|
||||
# ./build-all.sh --linux-only # solo Linux
|
||||
# ./build-all.sh --windows-only # solo Windows
|
||||
# ./build-all.sh --no-package # sin generar .tar.gz/.zip
|
||||
# ./build-all.sh --clean # rebuild desde cero (borra venvs/bundled/dist)
|
||||
# =============================================================================
|
||||
set -uo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$ROOT"
|
||||
|
||||
DO_LINUX=1
|
||||
DO_WINDOWS=1
|
||||
DO_PACKAGE=1
|
||||
DO_CLEAN=0
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--linux-only) DO_WINDOWS=0 ;;
|
||||
--windows-only) DO_LINUX=0 ;;
|
||||
--no-package) DO_PACKAGE=0 ;;
|
||||
--clean) DO_CLEAN=1 ;;
|
||||
-h|--help)
|
||||
grep '^#' "$0" | grep -v '^#!' | sed 's/^# \{0,1\}//'; exit 0 ;;
|
||||
*) echo "Opción desconocida: $arg" >&2; exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# --- helpers -----------------------------------------------------------------
|
||||
BLUE='\033[36m'; GREEN='\033[32m'; YELLOW='\033[33m'; RED='\033[31m'; NC='\033[0m'
|
||||
say() { echo -e "${BLUE}==>${NC} $*"; }
|
||||
ok() { echo -e "${GREEN}OK:${NC} $*"; }
|
||||
warn() { echo -e "${YELLOW}AVISO:${NC} $*" >&2; }
|
||||
err() { echo -e "${RED}ERROR:${NC} $*" >&2; }
|
||||
|
||||
# SECONDS es incremental de bash; lo usamos para medir cada etapa.
|
||||
stage_start() { STAGE_T0=$SECONDS; }
|
||||
stage_end() { echo -e " (${1} en $((SECONDS - STAGE_T0))s)"; }
|
||||
|
||||
WIN_OK=0
|
||||
LIN_OK=0
|
||||
|
||||
# --- limpieza opcional -------------------------------------------------------
|
||||
if [[ "$DO_CLEAN" -eq 1 ]]; then
|
||||
say "Limpieza (--clean): borrando venvs, bundled y dist"
|
||||
# bundled/ y venv-linux los crea Docker como root; borrar vía contenedor.
|
||||
if command -v docker >/dev/null 2>&1; then
|
||||
docker run --rm -v "$ROOT:/app" ubuntu:22.04 bash -c \
|
||||
'rm -rf /app/packaging/bundled/linux /app/venv-linux /app/dist/CloudRestoreAS /app/dist/release' \
|
||||
>/dev/null 2>&1 || true
|
||||
fi
|
||||
rm -rf "$ROOT/venv-windows" "$ROOT/packaging/bundled/windows" \
|
||||
"$ROOT/dist/CloudRestoreAS.exe" 2>/dev/null || true
|
||||
ok "limpieza completada"
|
||||
fi
|
||||
|
||||
# --- Build Linux (Docker) ----------------------------------------------------
|
||||
if [[ "$DO_LINUX" -eq 1 ]]; then
|
||||
say "Build Linux (Docker, autocontenido)"
|
||||
stage_start
|
||||
if ! command -v docker >/dev/null 2>&1; then
|
||||
err "docker no disponible; no se puede construir Linux"
|
||||
[[ "$DO_WINDOWS" -eq 0 ]] && exit 1
|
||||
elif bash "$ROOT/packaging/scripts/docker-build-linux.sh"; then
|
||||
if [[ -f "$ROOT/dist/CloudRestoreAS" ]]; then
|
||||
LIN_OK=1; ok "dist/CloudRestoreAS"
|
||||
else
|
||||
err "el build Linux terminó sin binario"
|
||||
fi
|
||||
else
|
||||
err "falló el build Linux"
|
||||
fi
|
||||
stage_end "Linux"
|
||||
fi
|
||||
|
||||
# --- Build Windows (PowerShell -> build.ps1) ---------------------------------
|
||||
if [[ "$DO_WINDOWS" -eq 1 ]]; then
|
||||
say "Build Windows (PowerShell + build.ps1)"
|
||||
stage_start
|
||||
WIN_PATH="$(wslpath -w "$ROOT" 2>/dev/null || true)"
|
||||
if command -v powershell.exe >/dev/null 2>&1 && [[ -n "$WIN_PATH" ]]; then
|
||||
# build.ps1 auto-detecta el Python de Windows (Python313/312/311) y arma venv-windows.
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \
|
||||
"Set-Location -LiteralPath '$WIN_PATH'; & .\\build.ps1"
|
||||
PS_RC=$?
|
||||
if [[ "$PS_RC" -eq 0 && -f "$ROOT/dist/CloudRestoreAS.exe" ]]; then
|
||||
WIN_OK=1; ok "dist/CloudRestoreAS.exe"
|
||||
else
|
||||
err "falló el build Windows (código $PS_RC)"
|
||||
[[ "$DO_LINUX" -eq 0 ]] && { stage_end "Windows"; exit 1; }
|
||||
fi
|
||||
else
|
||||
warn "powershell.exe no disponible desde WSL; se omite el build Windows."
|
||||
warn "Ejecuta build.ps1 en Windows para generar el .exe."
|
||||
[[ "$DO_LINUX" -eq 0 ]] && exit 1
|
||||
fi
|
||||
stage_end "Windows"
|
||||
fi
|
||||
|
||||
# --- Empaquetado -------------------------------------------------------------
|
||||
if [[ "$DO_PACKAGE" -eq 1 ]]; then
|
||||
say "Empaquetado (.tar.gz Linux / .zip Windows)"
|
||||
stage_start
|
||||
bash "$ROOT/packaging/scripts/package-release.sh" || warn "empaquetado con incidencias"
|
||||
stage_end "Empaquetado"
|
||||
fi
|
||||
|
||||
# --- Resumen -----------------------------------------------------------------
|
||||
echo
|
||||
say "Resumen"
|
||||
[[ "$DO_LINUX" -eq 1 ]] && { [[ "$LIN_OK" -eq 1 ]] && ok "Linux regenerado" || err "Linux NO generado"; }
|
||||
[[ "$DO_WINDOWS" -eq 1 ]] && { [[ "$WIN_OK" -eq 1 ]] && ok "Windows regenerado" || warn "Windows NO generado"; }
|
||||
if [[ -d "$ROOT/dist/release" ]]; then
|
||||
echo "Artefactos en dist/release/:"
|
||||
ls -lh "$ROOT/dist/release" | awk 'NR>1 {print " " $9 " " $5}'
|
||||
fi
|
||||
|
||||
# Éxito si todo lo solicitado se generó.
|
||||
FAIL=0
|
||||
[[ "$DO_LINUX" -eq 1 && "$LIN_OK" -ne 1 ]] && FAIL=1
|
||||
[[ "$DO_WINDOWS" -eq 1 && "$WIN_OK" -ne 1 ]] && FAIL=1
|
||||
exit $FAIL
|
||||
Reference in New Issue
Block a user