feat(build): add a script that prepares the remote fws repository

The [fws] repository is shared with other FWS projects (fws-deskmanager,
fws-kitty…): a database rebuilt from local-repo alone would drop their
packages once uploaded. The script starts from the online database, adds
our packages without downgrading a newer published version, and stops
when that database cannot be read. Uploading stays manual.
This commit is contained in:
nocode committed 2026-11-26 11:52:04 +01:00
1 parent 0cdde23a8f
commit e38dc51da0
1 file changed
+105
+105
View File
@@ -0,0 +1,105 @@
#!/bin/bash
# ============================================================
# FWS — Prépare le contenu du dépôt distant [fws] à partir de local-repo/
# (généré par setup-aur.sh).
#
# Résultat : remote-repo/, à téléverser tel quel dans x86_64/ sur le
# serveur (les paquets d'abord, les fichiers fws.* ensuite).
# Rien n'est envoyé : le téléversement reste manuel.
#
# Autre serveur : FWS_REMOTE_REPO_URL=<url> ./prepare-remote-repo.sh
# ============================================================
set -e
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'
BLUE='\033[0;34m'; 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" >&2; exit 1; }
REPO_NAME="fws"
REMOTE_URL="${FWS_REMOTE_REPO_URL:-https://repo.laxacube.ch/x86_64}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOCAL_REPO="$SCRIPT_DIR/local-repo"
OUT="$SCRIPT_DIR/remote-repo"
DB="$REPO_NAME.db"
FILES="$REPO_NAME.files"
for cmd in repo-add curl tar; do
command -v "$cmd" >/dev/null 2>&1 \
|| error "$cmd introuvable — lance ce script depuis Arch Linux (ou la WSL Arch)."
done
# Ghost entries (names a FS such as NTFS rejected, left half-created by a
# failed cp) show up in the glob but fail at stat: keep readable files only.
# Signatures are uploaded alongside, but repo-add only takes the packages.
to_copy=()
for f in "$LOCAL_REPO"/*.pkg.tar.*; do
[ -e "$f" ] && to_copy+=("$f")
done
[ "${#to_copy[@]}" -gt 0 ] || error "local-repo/ ne contient aucun paquet — lance d'abord ./setup-aur.sh"
rm -rf "$OUT"
mkdir -p "$OUT"
# The remote repo is shared: other FWS projects (fws-deskmanager, fws-kitty…)
# already publish into it. A database rebuilt from local-repo alone would drop
# their entries once uploaded, so we start from the ONLINE database and add our
# packages to it — and refuse to go on when it cannot be read.
info "Récupération de la base [$REPO_NAME] en ligne ($REMOTE_URL)…"
state=""
for f in "$DB.tar.gz" "$FILES.tar.gz"; do
code="$(curl -sSL --retry 2 --connect-timeout 15 -o "$OUT/$f" \
-w '%{http_code}' "$REMOTE_URL/$f" 2>/dev/null)" || code="000"
# A 200 can still be an HTML error page from a proxy: only a real archive
# counts as the online database.
if [ "$code" = 200 ] && ! tar -tzf "$OUT/$f" >/dev/null 2>&1; then
code="200-invalide"
fi
state+="$code "
done
case "$state" in
"200 200 ")
success "Base en ligne récupérée — nos paquets y sont ajoutés." ;;
"404 404 ")
rm -f "$OUT/$DB.tar.gz" "$OUT/$FILES.tar.gz"
warn "Aucune base [$REPO_NAME] sur $REMOTE_URL — création d'une base neuve." ;;
*)
rm -rf "$OUT"
error "Base en ligne illisible (HTTP ${state% }). Une base faite sans elle effacerait les paquets des autres projets : rien n'est généré. Vérifie l'accès à $REMOTE_URL et relance." ;;
esac
info "Copie des paquets de local-repo/…"
pkgs=()
for f in "${to_copy[@]}"; do
# Hard link when possible: no second copy of anaconda & co on disk.
ln -f "$f" "$OUT/" 2>/dev/null || cp -f "$f" "$OUT/" \
|| error "Copie de $(basename "$f") échouée"
case "$f" in *.sig) ;; *) pkgs+=("$OUT/$(basename "$f")") ;; esac
done
# --prevent-downgrade: a newer version already published online (from
# another machine) must not be replaced by an older local build.
info "Mise à jour de la base [$REPO_NAME]…"
repo-add -q --prevent-downgrade "$OUT/$DB.tar.gz" "${pkgs[@]}" \
|| error "repo-add a échoué"
rm -f "$OUT"/*.old
# pacman downloads exactly fws.db / fws.files, which repo-add creates as
# symlinks; SFTP clients and web upload panels silently skip symlinks.
for f in "$DB" "$FILES"; do
rm -f "$OUT/$f"
cp -f "$OUT/$f.tar.gz" "$OUT/$f"
done
echo ""
success "Prêt : $OUT"
info "Contenu de la base [$REPO_NAME] :"
tar -tzf "$OUT/$DB.tar.gz" | sed -n 's|^\([^/]*\)/$| \1|p' | sort
echo ""
echo " À téléverser dans $REMOTE_URL/ (sans rien supprimer sur le serveur) :"
echo " 1. les paquets : remote-repo/*.pkg.tar.*"
echo " 2. puis la base : remote-repo/$DB $DB.tar.gz $FILES $FILES.tar.gz"
echo " Relance ce script juste avant d'envoyer : un autre projet a pu publier entre-temps."