#!/bin/bash # ============================================================================= # FWS — Pipeline « Build ISO » déclenché depuis le panneau admin # (admin/bugs/build.php → process détaché, logs dans le terminal). # # Exécuté DANS le conteneur web (fws-files), qui pilote le moteur Docker # Desktop via /var/run/docker.sock. Toutes les étapes se déroulent dans un # conteneur archlinux jetable (--privileged, exigé par mkarchiso), le dépôt # Windows D:\FWS-ISO étant monté sur /fws — exactement le repli Docker que # font build.sh / setup-aur.sh quand on les lance depuis Git Bash sans WSL. # # Étapes : # 1. passage sur la branche « main » (abandon propre si des modifications # locales non commitées empêchent le checkout — rien n'est jamais perdu) # 2. git pull origin main # 3. bash build.sh # 4. si build.sh échoue → bash setup-aur.sh, puis relance de build.sh # ============================================================================= set -u # ── Token Gitea (optionnel) : déposé par build.php dans # api/bugs/data/build/git-auth.env (jamais commité, jamais affiché). # Transmis au conteneur en variable d'environnement → git l'utilise pour # le pull sans qu'aucune donnée d'auth n'apparaisse dans les logs. AUTH_ENV="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../api/bugs/data/build/git-auth.env" GIT_AUTH=() if [ -f "$AUTH_ENV" ]; then . "$AUTH_ENV" fi if [ -n "${FWS_GIT_TOKEN:-}" ]; then AUTH64="$(printf '%s:%s' "${FWS_GIT_USER:-fws}" "$FWS_GIT_TOKEN" | base64 -w0 2>/dev/null || printf '%s:%s' "${FWS_GIT_USER:-fws}" "$FWS_GIT_TOKEN" | base64)" GIT_AUTH=( -e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=http.extraheader -e "GIT_CONFIG_VALUE_0=AUTHORIZATION: basic ${AUTH64}" ) fi IMG="docker.io/library/archlinux:latest" NAME="fws-iso-build" REPO_WIN='D:\FWS-ISO' # chemin Windows résolu par le moteur Docker Desktop now() { date '+%H:%M:%S'; } echo "[$(now)] ════════════ FWS — Build ISO ════════════" echo "[$(now)] Pipeline lancé depuis le panneau admin (conteneur web)." rc=0 echo "[$(now)] docker pull ${IMG}…" if ! docker pull "$IMG"; then echo "[$(now)] ÉCHEC : pull de l'image archlinux impossible (Docker Desktop arrêté ou réseau coupé ?)." rc=70 else # Nettoie un éventuel build précédent resté vivant (arrêt brutal). docker rm -f "$NAME" >/dev/null 2>&1 echo "[$(now)] Conteneur Arch : checkout main → pull → build.sh (repli setup-aur.sh)." docker run --rm --privileged --name "$NAME" \ -e FWS_IN_CONTAINER=1 \ "${GIT_AUTH[@]}" \ -v fws-pacman-cache:/var/cache/pacman/pkg \ -v "${REPO_WIN}:/fws" \ -w /fws \ "$IMG" \ bash -lc ' set -u cd /fws || { echo "==> /fws introuvable : le montage D:\FWS-ISO est-il actif ?"; exit 81; } echo "==> Installation de git dans le conteneur (image fraîche sans git)…" pacman -Sy --noconfirm git >/dev/null 2>&1 \ || { echo "==> ÉCHEC : pacman -Sy git (réseau du conteneur ?)."; exit 80; } echo "==> Branche actuelle : $(git branch --show-current)" echo "==> Passage sur main…" git checkout main 2>&1 || { echo echo "!! Impossible de passer sur main : des modifications locales non commitées" echo "!! dans D:\FWS-ISO empêchent le checkout (voir « git status »)." echo "!! Committe ou stash ces modifications, puis relance le build." exit 90 } echo "==> git pull (origin main)…" GIT_TERMINAL_PROMPT=0 git pull --ff-only origin main || { echo "!! git pull a échoué (réseau, droits, ou conflit ?)." exit 91 } echo echo "==> bash build.sh" if bash build.sh; then echo "==> ✅ build.sh terminé sans erreur." exit 0 fi echo echo "!! build.sh a échoué → lancement de setup-aur.sh, puis nouvel essai de build.sh" if ! bash setup-aur.sh; then echo "!! setup-aur.sh a échoué." exit 92 fi echo "==> bash build.sh (2e tentative)…" if bash build.sh; then echo "==> ✅ build.sh (2e tentative) terminé sans erreur." exit 0 fi echo "!! Nouvel échec de build.sh." exit 93 ' rc=$? docker rm -f "$NAME" >/dev/null 2>&1 || true fi echo "[$(now)] ════════════ Fin du pipeline (code ${rc}) ════════════" exit "$rc"