A run died cloning libxmlrpc, a package that was already built and sitting in local-repo, along with the seven others. Ten minutes of keyring refresh, system upgrade and 600 MB of build tools, thrown away on the first package, for a clone whose only purpose was to read a version number. That is why the clone happens at all: build_or_skip compares the PKGBUILD's version against local-repo to decide between building and skipping, and the PKGBUILD only exists once cloned. With no network there was no path left, even though the answer was already on disk. Three changes. Each clone now gets a second attempt after five seconds. A network that stumbles for a second should not cost a whole preparation phase. When both attempts fail, the package already built in local-repo is reused and the warning names the file that was picked. Offline there is no way to know whether a newer version exists upstream, so the one on hand is taken. The script only gives up when the package is genuinely absent, and it then says which host to check. A flag stops the bleeding after the first total failure: the remaining packages go straight to the fallback rather than waiting through two TCP timeouts each, which on eight packages is minutes of waiting for an answer already known. Two name-matching traps are covered by the new helpers. A version-agnostic lookup on "$pkg"-* would match "$pkg"-debug-* and install the debug package instead, so the glob requires a digit after the dash, which every pacman version starts with and no name suffix does. The same glob keeps a name from catching a longer one that has it as a prefix. Neither helper has a test yet. On the incident itself, only what the log shows: the mirrors gave up after 10 s and the AUR after 21 s, so the run met connection timeouts rather than refusals, and DNS had resolved. The container runs with --network=host, so podman's bridge was not in the path. Why the packets went nowhere was not measured. Transient, and now survivable. Signed-off-by: nocode <suzuku295@gmail.com>
485 lines
23 KiB
Bash
Executable File
485 lines
23 KiB
Bash
Executable File
#!/bin/bash
|
||
# ============================================================
|
||
# FWS — Build des paquets AUR (winboat-bin) + PKGBUILD locaux (deps Anaconda,
|
||
# fws-dnd) et création du repo pacman local fws-local/.
|
||
#
|
||
# Rejoue-le si tu changes la liste AUR_PACKAGES ou pour
|
||
# rafraîchir le repo local.
|
||
# ============================================================
|
||
set -e
|
||
trap 'rc=$?; echo -e "\033[0;31m[ERR] Échec (setup-aur.sh) ligne $LINENO, code $rc.\033[0m" >&2; exit $rc' ERR
|
||
|
||
# Paquets AUR à construire, DANS L'ORDRE (les deps avant les dépendants ; la
|
||
# boucle plus bas installe chaque paquet après build pour résoudre les chaînes).
|
||
# - libxmlrpc, satyr : deps de libreport (deps officielles uniquement)
|
||
# - libreport : tiré par python-meh ; chaîne AUR→AUR → APRÈS satyr+libxmlrpc
|
||
# - winboat-bin : app FWS
|
||
# - python-* : deps Anaconda présentes dans l'AUR (deps officielles only)
|
||
# python-blivet est packagé en LOCAL (pkgbuilds/, patché sans libselinux).
|
||
# gnome-kiosk (WM de la session GUI) est différé au chantier C.
|
||
# NB : python-iso639 RETIRÉ de l'AUR (mauvais projet homonyme, API sans find()) →
|
||
# packagé en LOCAL (pkgbuilds/python-iso639, projet PyPI « iso639 » 0.1.4).
|
||
# NB : python-langtable RETIRÉ de l'AUR (figé 0.0.51, sans list_common_languages) →
|
||
# packagé en LOCAL (pkgbuilds/python-langtable, 0.0.71).
|
||
# NB : broadcom-wl-dkms n'est PAS dans packages.x86_64 — il blackliste
|
||
# b43/bcma/ssb pour tout le système. build.sh l'embarque dans l'image et
|
||
# fws-setup-hardware ne l'installe que sur une Broadcom réellement muette.
|
||
AUR_PACKAGES=(libxmlrpc satyr libreport winboat-bin python-pid python-xkbregistry python-requests-ftp broadcom-wl-dkms)
|
||
DISTRO_NAME="${ARCH_WSL_DISTRO:-Arch}"
|
||
|
||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
|
||
BLUE='\033[0;34m'; CYAN='\033[0;36m'; NC='\033[0m'
|
||
info() { echo -e "${BLUE}==>${NC} $1"; }
|
||
success() { echo -e "${GREEN}[OK]${NC} $1"; }
|
||
warn() { echo -e "${YELLOW}[!!]${NC} $1"; }
|
||
error() { echo -e "${RED}[ERR]${NC} $1"; exit 1; }
|
||
step() { echo -e "\n${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
|
||
echo -e "${CYAN} $1${NC}"
|
||
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"; }
|
||
|
||
# ============================================================
|
||
# Bascule Git Bash → WSL si besoin
|
||
# ============================================================
|
||
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || -n "$WINDIR" ]]; then
|
||
info "Git Bash détecté — bascule dans WSL ($DISTRO_NAME)..."
|
||
export MSYS_NO_PATHCONV=1
|
||
export MSYS2_ARG_CONV_EXCL="*"
|
||
|
||
# Repli Docker Desktop si aucune distro WSL Arch n'est joignable
|
||
# (définit fws_docker_repl, cf. scripts/fws-docker-repl.sh).
|
||
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/scripts/fws-docker-repl.sh"
|
||
|
||
# WSL doit être présent.
|
||
command -v wsl.exe >/dev/null 2>&1 \
|
||
|| error "WSL introuvable — PowerShell admin : 'wsl --install', puis installe une distro Arch et relance."
|
||
|
||
# Choix de la distro Arch : override $ARCH_WSL_DISTRO, sinon nom exact,
|
||
# sinon 1re distro « arch » réellement joignable (énum via `wsl -l -q`,
|
||
# sortie UTF-16LE → on retire NUL/CR ; on garde la sonde « echo ok »).
|
||
pick_arch_distro() {
|
||
wsl.exe -d "$DISTRO_NAME" -u root -- echo ok >/dev/null 2>&1 && return 0
|
||
local d distros=()
|
||
mapfile -t distros < <(wsl.exe -l -q 2>/dev/null | tr -d '\0\r' | sed 's/[[:space:]]*$//;/^$/d')
|
||
for d in "${distros[@]}"; do
|
||
[[ "$d" == "$DISTRO_NAME" ]] || continue
|
||
wsl.exe -d "$d" -u root -- echo ok >/dev/null 2>&1 && { DISTRO_NAME="$d"; return 0; }
|
||
done
|
||
for d in "${distros[@]}"; do
|
||
[[ "$d" =~ [Aa][Rr][Cc][Hh] ]] || continue
|
||
wsl.exe -d "$d" -u root -- echo ok >/dev/null 2>&1 && { DISTRO_NAME="$d"; return 0; }
|
||
done
|
||
return 1
|
||
}
|
||
if ! pick_arch_distro; then
|
||
warn "Distros WSL installées :"
|
||
wsl.exe -l -v 2>/dev/null | tr -d '\0' >&2 || true
|
||
# Aucune distro WSL Arch ? Si Docker Desktop tourne, on relance ce
|
||
# script dans un conteneur archlinux (même principe que le repli
|
||
# podman des hôtes Linux non-Arch). fws_docker_repl sort le script
|
||
# lui-même en cas de succès ; sinon on garde le message d'erreur.
|
||
SCRIPT_DIR_WIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -W)"
|
||
if fws_docker_repl "setup-aur.sh" "$SCRIPT_DIR_WIN"; then
|
||
exit 0
|
||
fi
|
||
error "Aucune distro WSL Arch joignable (repli Docker indisponible). Installe ArchWSL (nom 'Arch') ou 'wsl --install -d archlinux', ou exporte ARCH_WSL_DISTRO=<nom>."
|
||
fi
|
||
info "Distro WSL : $DISTRO_NAME"
|
||
|
||
SCRIPT_DIR_WIN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -W)"
|
||
SCRIPT_PATH_WSL=$(MSYS_NO_PATHCONV=1 wsl.exe -d "$DISTRO_NAME" -u root -- \
|
||
wslpath "$(echo "$SCRIPT_DIR_WIN" | sed 's|/|\\\\|g')/setup-aur.sh" \
|
||
2>/dev/null | tr -d '\r\n')
|
||
[ -n "$SCRIPT_PATH_WSL" ] \
|
||
|| error "Traduction du chemin vers WSL échouée (wslpath). Vérifie ARCH_WSL_DISTRO ($DISTRO_NAME)."
|
||
wsl.exe -d "$DISTRO_NAME" -u root -- test -f "$SCRIPT_PATH_WSL" \
|
||
|| error "Script introuvable dans WSL : $SCRIPT_PATH_WSL"
|
||
|
||
# Relance en root depuis le vrai chemin ($0 → SCRIPT_DIR correct).
|
||
# Fins de ligne garanties LF par .gitattributes (*.sh text eol=lf).
|
||
MSYS_NO_PATHCONV=1 wsl.exe -d "$DISTRO_NAME" -u root -- bash "$SCRIPT_PATH_WSL"
|
||
exit 0
|
||
fi
|
||
|
||
# ============================================================
|
||
# Bascule conteneur : hôte non-Arch (Fedora, Ubuntu, …) →
|
||
# setup dans un conteneur Arch via podman (rootful, --privileged).
|
||
# Voir build.sh pour le détail du design ; même image, même volume de
|
||
# cache pacman, dépôt monté au MÊME chemin absolu (→ local-repo/ revient
|
||
# sur l'hôte). makepkg refuse root mais on est dans le conteneur en root :
|
||
# setup-aur.sh recrée son propre utilisateur fwsbuild, c'est transparent.
|
||
# ============================================================
|
||
host_is_arch() {
|
||
# Fedora empaquette aussi « pacman » → sa seule présence ne suffit pas.
|
||
command -v pacman >/dev/null 2>&1 \
|
||
&& grep -qiE '^ID(_LIKE)?=.*arch' /etc/os-release 2>/dev/null
|
||
}
|
||
|
||
if [ -z "$FWS_IN_CONTAINER" ] && ! host_is_arch; then
|
||
info "Hôte non-Arch détecté — setup dans un conteneur Arch (podman)..."
|
||
command -v podman >/dev/null 2>&1 \
|
||
|| error "podman introuvable. Fedora : 'sudo dnf install -y podman' ; Debian/Ubuntu : 'sudo apt install -y podman'."
|
||
|
||
SUDO=(); [ "$EUID" -eq 0 ] || SUDO=(sudo)
|
||
TTY=(); [ -t 0 ] && TTY=(-it)
|
||
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
IMAGE="docker.io/library/archlinux:latest"
|
||
|
||
# pull explicite : « run » ne re-résout pas « latest » une fois en cache.
|
||
info "Pull de l'image $IMAGE…"
|
||
"${SUDO[@]}" podman pull "$IMAGE"
|
||
|
||
info "Relance dans le conteneur (setup-aur.sh)…"
|
||
# --network=host : le bridge podman ne route plus vers l'extérieur sur
|
||
# certains réseaux (firewalld/NAT, → « Resolving timed out »). On partage la
|
||
# pile réseau de l'hôte (internet + DNS OK) pour les pacman/makepkg/AUR.
|
||
"${SUDO[@]}" podman run --rm "${TTY[@]}" --network=host --privileged \
|
||
-e FWS_IN_CONTAINER=1 \
|
||
-v "$REPO_DIR":"$REPO_DIR" \
|
||
-v fws-pacman-cache:/var/cache/pacman/pkg \
|
||
-w "$REPO_DIR" \
|
||
"$IMAGE" \
|
||
bash "$REPO_DIR/setup-aur.sh"
|
||
|
||
# podman rootful → local-repo/ appartient à root : on le rend à l'hôte.
|
||
OWNER="$(stat -c '%u:%g' "$REPO_DIR" 2>/dev/null || true)"
|
||
if [ -n "$OWNER" ] && [ -e "$REPO_DIR/local-repo" ]; then
|
||
"${SUDO[@]}" chown -R "$OWNER" "$REPO_DIR/local-repo" 2>/dev/null || true
|
||
fi
|
||
exit 0
|
||
fi
|
||
|
||
# ============================================================
|
||
# Vérifications
|
||
# ============================================================
|
||
command -v pacman >/dev/null || error "pacman introuvable (lance depuis Arch / WSL)"
|
||
# Élévation root : sudo de préférence, sinon su. $0 cité (chemins à espaces).
|
||
if [ "$EUID" -ne 0 ]; then
|
||
if command -v sudo >/dev/null 2>&1; then
|
||
exec sudo bash "$0" "$@"
|
||
else
|
||
exec su -c "bash \"$0\"" root
|
||
fi
|
||
fi
|
||
success "Arch Linux (root) ✓"
|
||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
LOCAL_REPO="$SCRIPT_DIR/local-repo"
|
||
BUILD_DIR="/tmp/fws-aur-build"
|
||
BUILD_USER="fwsbuild"
|
||
|
||
# ============================================================
|
||
step "0/4 — Préparation pacman (sandbox WSL + keyring)"
|
||
# ============================================================
|
||
# pacman ≥ 7 utilise landlock pour sandboxer les ops fs. Ni le kernel WSL
|
||
# ni (selon le noyau) le conteneur ne le supportent → désactivation explicite.
|
||
if grep -qi 'microsoft\|wsl' /proc/version 2>/dev/null || [ -n "$FWS_IN_CONTAINER" ]; then
|
||
if ! grep -qE '^[[:space:]]*DisableSandbox' /etc/pacman.conf; then
|
||
sed -i '/^\[options\]/a DisableSandbox' /etc/pacman.conf
|
||
warn "WSL/conteneur détecté → DisableSandbox ajouté à /etc/pacman.conf"
|
||
fi
|
||
fi
|
||
|
||
# Keyring : sur une WSL Arch ancienne, archlinux-keyring est périmé et
|
||
# bloque tout install ("unknown trust"). On bypass SigLevel uniquement
|
||
# pour mettre à jour le paquet keyring, puis on rétablit.
|
||
info "Refresh du trousseau pacman…"
|
||
pacman-key --init 2>/dev/null || true
|
||
|
||
if [ -f /etc/pacman.conf ] && ! grep -qE '^[[:space:]]*SigLevel[[:space:]]*=[[:space:]]*Never' /etc/pacman.conf; then
|
||
cp -f /etc/pacman.conf /etc/pacman.conf.fws.bak
|
||
sed -i 's/^SigLevel.*/SigLevel = Never/' /etc/pacman.conf
|
||
pacman -Sy --noconfirm --needed archlinux-keyring \
|
||
|| warn "Maj archlinux-keyring échouée (sigs bypass) — on continue"
|
||
mv -f /etc/pacman.conf.fws.bak /etc/pacman.conf
|
||
fi
|
||
|
||
pacman-key --populate archlinux 2>/dev/null || true
|
||
|
||
# Maj système complète : indispensable pour gérer les "package splits"
|
||
# (ex. gcc-libs → libgcc + libstdc++) sinon makepkg plantera sur
|
||
# "conflicting files" lors de l'install des dépendances.
|
||
info "Mise à jour complète du système (peut être long la première fois)…"
|
||
if ! pacman -Syu --noconfirm; then
|
||
# État « sale » (upgrade interrompu = fichiers présents mais non possédés par
|
||
# pacman) : la transaction échoue avec « exists in filesystem ». Ces fichiers
|
||
# appartiennent AUX paquets à mettre à jour → un --overwrite les réinstalle et
|
||
# répare l'état. Sans ça, tous les pacman -U suivants (install depuis
|
||
# local-repo) échouent en cascade avec des erreurs hors-sujet.
|
||
warn "pacman -Syu a échoué (conflits de fichiers ?) — retry avec --overwrite pour réparer l'état…"
|
||
pacman -Syu --noconfirm --overwrite='*' \
|
||
|| warn "pacman -Syu a partiellement échoué — on continue"
|
||
fi
|
||
|
||
# ============================================================
|
||
step "1/4 — Outils de build"
|
||
# ============================================================
|
||
# sudo : requis par makepkg -s (syncdeps) quand le build tourne dans un
|
||
# conteneur (fwsbuild est non-root ; l'image archlinux n'emporte pas sudo).
|
||
# Sur Arch natif / WSL, sudo est déjà présent → --needed ne fait rien.
|
||
pacman -Sy --needed --noconfirm base-devel git sudo
|
||
|
||
# ============================================================
|
||
step "2/4 — Préparation utilisateur de build (non-root pour makepkg)"
|
||
# ============================================================
|
||
rm -rf "$BUILD_DIR"
|
||
mkdir -p "$BUILD_DIR"
|
||
|
||
if ! id "$BUILD_USER" &>/dev/null; then
|
||
useradd -m "$BUILD_USER"
|
||
echo "$BUILD_USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/fwsbuild
|
||
chmod 440 /etc/sudoers.d/fwsbuild
|
||
success "Utilisateur $BUILD_USER créé"
|
||
fi
|
||
chown -R "$BUILD_USER:$BUILD_USER" "$BUILD_DIR"
|
||
|
||
# ============================================================
|
||
# Helpers — build INCRÉMENTAL (saute un paquet déjà présent dans local-repo
|
||
# à la même version pkgver-pkgrel). Gros gain quand on n'itère que sur 1 paquet.
|
||
# ============================================================
|
||
mkdir -p "$LOCAL_REPO"
|
||
|
||
# Version « [epoch:]pkgver-pkgrel » lue dans un PKGBUILD (sourcing en sous-shell).
|
||
# Vide si illisible → on (re)construit par sécurité. Nos paquets n'ont pas de
|
||
# pkgver() VCS, donc le pkgver littéral est exact.
|
||
pkgbuild_fullver() {
|
||
( cd "$1" 2>/dev/null && source ./PKGBUILD >/dev/null 2>&1 \
|
||
&& printf '%s%s-%s' "${epoch:+$epoch:}" "$pkgver" "$pkgrel" ) 2>/dev/null || true
|
||
}
|
||
|
||
# Le paquet <name> en version <fullver> est-il déjà dans local-repo ? Le motif
|
||
# « -$ver- » borne la version (évite qu'« anaconda » matche « anaconda-widgets »).
|
||
repo_has() {
|
||
[ -n "$2" ] || return 1
|
||
local f
|
||
for f in "$LOCAL_REPO/$1-$2-"*.pkg.tar.*; do [ -e "$f" ] && return 0; done
|
||
return 1
|
||
}
|
||
|
||
# Installe des .pkg (pacman -U) en tolérant les fichiers RÉSIDUELS NON POSSÉDÉS
|
||
# (« <pkg>: <path> exists in filesystem »). Ces fichiers sont des restes d'un
|
||
# pacman -Syu interrompu (extraction à moitié faite, DB jamais commitée) : ils
|
||
# n'appartiennent à AUCUN paquet et le transaction en cours les réécrit de toute
|
||
# façon → on ne supprime QUE les fichiers sans propriétaire (pacman -Qo vide),
|
||
# puis on réessaie. Un fichier possédé par un AUTRE paquet reste un vrai conflit
|
||
# (on ne le touche pas et le pacman -U finit par échouer proprement).
|
||
# Le paquet est-il dans local-repo, PEU IMPORTE la version ? Pendant du
|
||
# « repo_has », qui exige une version précise (celle du PKGBUILD, donc un clone
|
||
# réussi). Sert au repli hors ligne : mieux vaut construire l'ISO avec le paquet
|
||
# de la dernière fois que ne rien construire du tout.
|
||
#
|
||
# Le motif « -[0-9]* » n'est pas cosmétique : « $pkg-* » attraperait aussi
|
||
# « $pkg-debug-… », et on installerait le paquet de débogage à la place. Une
|
||
# version pacman commence toujours par un chiffre (ou « epoch: »), un suffixe
|
||
# de nom jamais.
|
||
repo_has_any() {
|
||
local f
|
||
for f in "$LOCAL_REPO/$1"-[0-9]*.pkg.tar.*; do [ -e "$f" ] && return 0; done
|
||
return 1
|
||
}
|
||
|
||
# Le plus RÉCEMMENT publié, s'il y en a plusieurs. Trier des versions en shell
|
||
# est un nid à bugs ; la date de copie dans local-repo dit la même chose ici,
|
||
# puisque publish_to_repo y copie au fil des builds.
|
||
repo_newest() {
|
||
ls -t "$LOCAL_REPO/$1"-[0-9]*.pkg.tar.* 2>/dev/null | head -1
|
||
}
|
||
|
||
# Clone l'AUR avec une SECONDE CHANCE. Un réseau qui bronche une seconde ne
|
||
# doit pas jeter dix minutes de préparation pacman : le run mourait sur le
|
||
# premier paquet, et sur le premier paquet SEULEMENT parce qu'il fallait lire
|
||
# son PKGBUILD — il était déjà construit dans local-repo.
|
||
clone_aur() {
|
||
local pkg="$1" try
|
||
for try in 1 2; do
|
||
[ "$try" = 2 ] && { warn "clonage $pkg : seconde tentative dans 5 s…"; sleep 5; }
|
||
rm -rf "$BUILD_DIR/$pkg"
|
||
su - "$BUILD_USER" \
|
||
-c "git clone --depth=1 https://aur.archlinux.org/${pkg}.git $BUILD_DIR/$pkg" \
|
||
&& return 0
|
||
done
|
||
return 1
|
||
}
|
||
|
||
pacman_ur() {
|
||
local i out rc conflicts=() f removed
|
||
for i in 1 2 3 4 5 6 7 8; do
|
||
if out="$(pacman -U --noconfirm --needed "$@" 2>&1)"; then
|
||
return 0
|
||
fi
|
||
rc=$?
|
||
mapfile -t conflicts < <(printf '%s\n' "$out" \
|
||
| sed -n 's/^[^:]*: \(.*\) exists in filesystem$/\1/p')
|
||
if [ "${#conflicts[@]}" -eq 0 ]; then
|
||
printf '%s\n' "$out" >&2
|
||
return "$rc"
|
||
fi
|
||
removed=0
|
||
for f in "${conflicts[@]}"; do
|
||
if ! pacman -Qo "$f" >/dev/null 2>&1; then
|
||
if [ -f "$f" ] || [ -L "$f" ]; then
|
||
rm -f "$f" && removed=$((removed + 1))
|
||
fi
|
||
fi
|
||
done
|
||
warn "Fichiers résiduels non possédés supprimés : $removed — nouvel essai ($i/8)…"
|
||
done
|
||
error "pacman -U a échoué après 8 essais (conflits de fichiers non résolus)"
|
||
}
|
||
|
||
# Publie les .pkg d'un build vers local-repo en purgeant d'abord les anciennes
|
||
# versions de CE paquet (+ son sous-paquet -debug). Le « -[0-9] » empêche
|
||
# « anaconda » d'attraper « anaconda-widgets » / « anaconda-debug ».
|
||
# Prend la LISTE EXPLICITE des fichiers à publier (pas un glob sur le dossier :
|
||
# un .pkg d'un build précédent peut traîner dans $BUILD_DIR/<name> et serait
|
||
# republié par-dessus la purge).
|
||
publish_to_repo() {
|
||
local name="$1"; shift
|
||
rm -f "$LOCAL_REPO/$name"-[0-9]*.pkg.tar.* \
|
||
"$LOCAL_REPO/$name"-debug-[0-9]*.pkg.tar.* 2>/dev/null || true
|
||
cp -f "$@" "$LOCAL_REPO/" || error "Copie de $name vers local-repo échouée"
|
||
}
|
||
|
||
# Paquets construits SANS être installés dans l'environnement de build.
|
||
# build_or_skip installe normalement chaque paquet pour que les chaînes AUR→AUR
|
||
# résolvent leurs dépendances. broadcom-wl-dkms n'a AUCUN dépendant ici, et
|
||
# l'installer serait carrément nuisible : il compile un module DKMS contre le
|
||
# noyau de l'environnement de build (inutile — le module est recompilé sur la
|
||
# machine cible — et fatal via set -e sur une image sans linux-headers), et il
|
||
# dépose un blacklist b43/bcma/ssb. Sur un run natif Arch/WSL, c'est le Wi-Fi de
|
||
# la machine de build qui tombe. On le construit, on le publie, on n'y touche pas.
|
||
NOINSTALL_PACKAGES=(broadcom-wl-dkms)
|
||
|
||
is_noinstall() {
|
||
local p
|
||
for p in "${NOINSTALL_PACKAGES[@]}"; do [ "$p" = "$1" ] && return 0; done
|
||
return 1
|
||
}
|
||
|
||
# Construit OU saute <name> (source déjà déposée dans $BUILD_DIR/<name>).
|
||
# Installe le résultat (depuis local-repo si sauté) pour que les paquets
|
||
# dépendants suivants résolvent leurs deps (chaînes AUR→AUR, anaconda…) —
|
||
# sauf pour les NOINSTALL_PACKAGES ci-dessus, qui sont seulement publiés.
|
||
build_or_skip() {
|
||
# NB : référencer "$1" et PAS "$name" ici — dans un `local a=… b=…` à une
|
||
# seule ligne, bash développe la 2ᵉ valeur AVANT que `name` ne soit affecté,
|
||
# donc "$name" y serait vide → d="/tmp/fws-aur-build/" (PKGBUILD introuvable).
|
||
local name="$1" d="$BUILD_DIR/$1" ver
|
||
[ -f "$d/PKGBUILD" ] || error "PKGBUILD introuvable pour $name ($d)"
|
||
ver="$(pkgbuild_fullver "$d")"
|
||
if repo_has "$name" "$ver"; then
|
||
success "$name $ver déjà construit → saut"
|
||
is_noinstall "$name" || pacman_ur "$LOCAL_REPO/$name-$ver-"*.pkg.tar.*
|
||
return 0
|
||
fi
|
||
info "Build $name ${ver:+($ver) }(peut prendre plusieurs minutes)…"
|
||
chown -R "$BUILD_USER:$BUILD_USER" "$d"
|
||
su - "$BUILD_USER" -c "cd '$d' && makepkg -sf --noconfirm" \
|
||
|| error "Build $name échoué"
|
||
# N'installer/publier QUE les paquets produits par CE PKGBUILD dans SA
|
||
# version courante (makepkg --packagelist), jamais un glob "$d/"* : après
|
||
# un bump de pkgrel, l'ancien .pkg traîne encore dans $d (BUILD_DIR n'est
|
||
# pas nettoyé entre les runs) → pacman -U recevait 2× le même nom de
|
||
# paquet (« erreur : cible répétée ») et la vieille version repartait
|
||
# dans local-repo. Le grep filtre tout bruit éventuel de su - (PAM…).
|
||
# NB : --packagelist liste aussi un -debug qui n'est PAS toujours produit
|
||
# (paquet pur python : rien à stripper) → ne garder que les fichiers
|
||
# réellement présents sur disque.
|
||
local -a pkgfiles=() existing=()
|
||
local f
|
||
mapfile -t pkgfiles < <(su - "$BUILD_USER" -c "cd '$d' && makepkg --packagelist" \
|
||
| grep -E '\.pkg\.tar\.')
|
||
for f in "${pkgfiles[@]}"; do [ -e "$f" ] && existing+=("$f"); done
|
||
[ "${#existing[@]}" -gt 0 ] || error "Aucun paquet produit trouvé pour $name"
|
||
if is_noinstall "$name"; then
|
||
publish_to_repo "$name" "${existing[@]}"
|
||
success "$name build OK (non installé ici — embarqué dans l'ISO)"
|
||
return 0
|
||
fi
|
||
pacman_ur "${existing[@]}"
|
||
publish_to_repo "$name" "${existing[@]}"
|
||
success "$name build + install OK"
|
||
}
|
||
|
||
# ============================================================
|
||
step "3/4 — Build des paquets (saut si déjà à jour dans local-repo)"
|
||
# ============================================================
|
||
# --- Paquets AUR (ordre : deps avant dépendants ; clone shallow puis build/saut) ---
|
||
# AUR_UP : passe à 0 dès qu'un clonage épuise ses deux tentatives. Les paquets
|
||
# suivants sautent alors directement au repli, au lieu d'attendre deux délais
|
||
# d'expiration TCP chacun — sur huit paquets, plusieurs minutes pour rien.
|
||
AUR_UP=1
|
||
for pkg in "${AUR_PACKAGES[@]}"; do
|
||
if [ "$AUR_UP" = 1 ]; then
|
||
info "Clonage $pkg (AUR)…"
|
||
if clone_aur "$pkg"; then
|
||
build_or_skip "$pkg"
|
||
continue
|
||
fi
|
||
AUR_UP=0
|
||
warn "AUR injoignable — on se rabat sur local-repo pour la suite."
|
||
fi
|
||
|
||
# Hors ligne : on ne peut pas lire le PKGBUILD, donc pas savoir si une
|
||
# version plus récente existe. On prend celle qu'on a.
|
||
if repo_has_any "$pkg"; then
|
||
_f="$(repo_newest "$pkg")"
|
||
warn "$pkg : clonage impossible → paquet déjà construit réutilisé ($(basename "$_f"))"
|
||
is_noinstall "$pkg" || pacman_ur "$_f"
|
||
else
|
||
error "Clonage $pkg échoué et aucun paquet dans local-repo. Vérifie l'accès à aur.archlinux.org (voir ci-dessus), puis relance."
|
||
fi
|
||
done
|
||
|
||
# --- PKGBUILD locaux FWS (ordre explicite, feuilles d'abord, anaconda dernier) ---
|
||
LOCAL_PKGBUILDS_DIR="$SCRIPT_DIR/pkgbuilds"
|
||
LOCAL_BUILD_ORDER=(
|
||
fws-dnd fws-pacmanage
|
||
pykickstart python-productmd python-requests-file python-simpleline
|
||
python-crypt_r python-iso639 python-langtable python-meh python-blivet
|
||
anaconda-widgets anaconda
|
||
)
|
||
BUILT_LOCAL=()
|
||
|
||
prepare_and_build_local() {
|
||
local name="$1" dir="$LOCAL_PKGBUILDS_DIR/$1"
|
||
[ -f "$dir/PKGBUILD" ] || return 1
|
||
rm -rf "$BUILD_DIR/$name"
|
||
cp -a "$dir" "$BUILD_DIR/$name"
|
||
build_or_skip "$name"
|
||
}
|
||
|
||
if [ -d "$LOCAL_PKGBUILDS_DIR" ]; then
|
||
# 1) Ordre explicite (deps avant dépendants).
|
||
for name in "${LOCAL_BUILD_ORDER[@]}"; do
|
||
if prepare_and_build_local "$name"; then BUILT_LOCAL+=("$name"); fi
|
||
done
|
||
# 2) Repli : tout PKGBUILD présent mais non listé (futur ajout oublié).
|
||
for dir in "$LOCAL_PKGBUILDS_DIR"/*/; do
|
||
[ -f "$dir/PKGBUILD" ] || continue
|
||
name="$(basename "$dir")"
|
||
printf '%s\n' "${BUILT_LOCAL[@]}" | grep -qx "$name" && continue
|
||
prepare_and_build_local "$name" || true
|
||
done
|
||
fi
|
||
|
||
# ============================================================
|
||
step "4/4 — (Re)génération de la base du repo local fws-local"
|
||
# ============================================================
|
||
# local-repo contient déjà TOUS les paquets (construits ce run + sautés des
|
||
# runs précédents). On régénère juste la base de données pacman du dépôt.
|
||
rm -f "$LOCAL_REPO"/fws-local.db* "$LOCAL_REPO"/fws-local.files* 2>/dev/null || true
|
||
repo-add "$LOCAL_REPO/fws-local.db.tar.gz" "$LOCAL_REPO"/*.pkg.tar.* \
|
||
|| error "repo-add a échoué"
|
||
success "Repo local prêt : $LOCAL_REPO"
|
||
|
||
# ============================================================
|
||
# Nettoyage utilisateur de build
|
||
# ============================================================
|
||
userdel -r "$BUILD_USER" 2>/dev/null || true
|
||
rm -f /etc/sudoers.d/fwsbuild
|
||
|
||
echo ""
|
||
echo -e "${GREEN}╔══════════════════════════════════════════════════╗${NC}"
|
||
echo -e "${GREEN}║ Setup terminé. Lance maintenant : ./build.sh ║${NC}"
|
||
echo -e "${GREEN}╚══════════════════════════════════════════════════╝${NC}"
|