Info::.pcmakeAllFromHalToOthers: comment mettre a jour srv18,rasp5B-01,win10-pro-paid à partir de hal
De wiki_pcwiki2
KEYWORDS: .PCMAKEALLFROMHALTOOTHERS, BUILD ALL
Le 26/10/2026:
.pcmakeAllFromHalToOthers
- Version : 1.01
- Date : 2026-10-26
- Emplacement :
/root/.pcmakeAllFromHalToOthers - Journal :
~/.pcmakeAllFromHalToOthers.log
Fonctionnement
- Phase hal : pour chaque projet
/Atelier/<prog>/Vx.yyet/pcroad/<prog>/Vx.yy(dernière version, hors.not,.old,.discontinued) disposant d'unCMakeLists.txt, d'unmakefile.unixou d'unmakefile:- le binaire (
build/<prog>ou<prog>) est recompilé s'il est absent ou plus ancien qu'une source ; - il est copié (identique au sens de
cmp) dans/PCStreet/binou/home/local/bin(emplacement existant, sinon/home/local/bin).
- le binaire (
- Phase cibles (
rasp5B-01,srv18puiswin10-pro) : le hash SHA-256 des sources est comparé à.pcsrc.sha256distant. S'il diffère, les sources sont envoyées (tar sur ssh, sansbuildni.git), compilées sur la cible puis le binaire est installé (/home/local/binsur Raspberry et srv18 ;/c/home/local/binsous MSYS2) et le hash mis à jour. - Un bilan final est affiché ; code retour 1 si au moins un échec.
Les sources sont déposées au même chemin sur la cible (préfixe /c sous Windows/MSYS2).
Les dossiers sans fichier de build (scripts, bibliothèques shell) sont ignorés.
Prérequis
- hal :
apt install cmake g++ make openssh-client coreutils findutils - rasp5B-01 :
apt install cmake g++ make, clé SSH root déployée (pcMakeAndSendSshKey) - srv18 (Debian) :
apt install cmake g++ make, clé SSH root déployée (pcMakeAndSendSshKey) - win10-pro : OpenSSH Server, MSYS2 (
pacman -S mingw-w64-x86_64-gcc cmake make tar), clé SSH déployée
Syntaxe
.pcmakeAllFromHalToOthers [-n|--dry-run] [--hal-only] [--targets LISTE] [--only PROG] [--language FR|UK] [-h|--help]
Options
| Option | Rôle | Exemple |
|---|---|---|
-n, --dry-run |
N'exécute rien, affiche ce qui serait fait | .pcmakeAllFromHalToOthers --dry-run
|
--hal-only |
Vérifie/compile sur hal uniquement | .pcmakeAllFromHalToOthers --hal-only
|
--targets LISTE |
Cibles rasp, srv, win (défaut rasp,srv,win) |
.pcmakeAllFromHalToOthers --targets srv
|
--only PROG |
Ne traite que le programme PROG | .pcmakeAllFromHalToOthers --only pcAt
|
| UK | Langue des messages (défaut FR) | .pcmakeAllFromHalToOthers --language UK
|
-h, --help |
Aide | .pcmakeAllFromHalToOthers -h
|
Variables d'environnement
| Variable | Défaut |
|---|---|
PCM_SRC_ROOTS |
/Atelier /pcroad
|
PCM_HAL_BINS |
/PCStreet/bin /home/local/bin
|
PCM_RASP_HOST / PCM_RASP_BIN |
rasp5B-01 / /home/local/bin
|
PCM_SRV_HOST / PCM_SRV_PREFIX / PCM_SRV_BIN |
srv18 / (vide) / /home/local/bin
|
PCM_WIN_HOST / PCM_WIN_PREFIX / PCM_WIN_BIN |
win10-pro / /c / /c/home/local/bin
|
PCM_WIN_SHELL |
C:/msys64/usr/bin/env.exe MSYSTEM=MINGW64 C:/msys64/usr/bin/bash.exe -lc
|
Pièges
win10-pron'est pas résolu actuellement (absent de/etc/hosts) : la cible est alors ignorée avec un avertissement.- Les makefiles historiques (
makefile.unix) peuvent ne pas aboutir sur ARM/MinGW : l'échec est consigné sans bloquer les autres projets. - Le shell distant reçoit la commande entre apostrophes : aucun chemin ne doit en contenir.
#!/bin/bash
# .pcmakeAllFromHalToOthers
# Version 1.01 du 2026-10-26
# Verifie que tout /Atelier et /pcroad est compile sur hal et installe
# dans /PCStreet/bin ou /home/local/bin, puis propage les sources non
# encore etablies sur win10-pro / srv18 / rasp5B-01, les y compile et les installe.
set -euo pipefail
kVersion="1.01"
kDate="2026-10-26"
kProg="$(basename "$0")"
kLog="${HOME}/${kProg}.log"
# --- Configuration (surchargeable par l'environnement) ---------------
SRC_ROOTS=(${PCM_SRC_ROOTS:-/Atelier /pcroad})
HAL_BINS=(${PCM_HAL_BINS:-/PCStreet/bin /home/local/bin})
HAL_DEFAULT_BIN="${PCM_HAL_DEFAULT_BIN:-/home/local/bin}"
RASP_HOST="${PCM_RASP_HOST:-rasp5B-01}"
RASP_PREFIX="${PCM_RASP_PREFIX:-}"
RASP_BIN="${PCM_RASP_BIN:-/home/local/bin}"
SRV_HOST="${PCM_SRV_HOST:-srv18}"
SRV_PREFIX="${PCM_SRV_PREFIX:-}"
SRV_BIN="${PCM_SRV_BIN:-/home/local/bin}"
WIN_HOST="${PCM_WIN_HOST:-win10-pro}"
WIN_PREFIX="${PCM_WIN_PREFIX:-/c}"
WIN_BIN="${PCM_WIN_BIN:-/c/home/local/bin}"
WIN_SHELL="${PCM_WIN_SHELL:-C:/msys64/usr/bin/env.exe MSYSTEM=MINGW64 C:/msys64/usr/bin/bash.exe -lc}"
SSH_OPTS=(-o BatchMode=yes -o ConnectTimeout=5)
optDry=0
optLang="FR"
optHalOnly=0
optTargets="rasp,srv,win"
optOnly=""
nbOk=0; nbBuilt=0; nbInstalled=0; nbSent=0; nbFail=0
declare -a failures=()
# --- Messages FR/UK ----------------------------------------------------
t() { if [[ "$optLang" == "UK" ]]; then printf '%s' "$2"; else printf '%s' "$1"; fi; }
usage() {
cat <<EOF
$kProg V$kVersion ($kDate)
$(t "Role" "Purpose")
$(t "Verifie la compilation/installation sur hal, puis propage les sources" "Checks build/install on hal, then pushes sources")
$(t "non etablies vers rasp5B-01, srv18 et win10-pro (envoi, compilation, install)." "not yet established to rasp5B-01, srv18 and win10-pro (send, build, install).")
$(t "Syntaxe" "Syntax")
$kProg [-n|--dry-run] [--hal-only] [--targets LISTE] [--only PROG]
[--language FR|UK] [-h|--help]
Options
-n, --dry-run $(t "n'execute rien, affiche ce qui serait fait" "runs nothing, shows what would be done")
ex: $kProg --dry-run
--hal-only $(t "verifie/compile sur hal uniquement" "check/build on hal only")
ex: $kProg --hal-only
--targets LISTE $(t "cibles separees par virgule : rasp, srv, win (defaut rasp,srv,win)" "comma separated targets: rasp, srv, win (default rasp,srv,win)")
ex: $kProg --targets rasp
--only PROG $(t "ne traite que le programme PROG" "process only program PROG")
ex: $kProg --only pcAt
--language FR|UK $(t "langue des messages (defaut FR)" "message language (default FR)")
ex: $kProg --language UK
-h, --help $(t "affiche cette aide" "shows this help")
ex: $kProg -h
$(t "Variables d'environnement" "Environment variables")
PCM_RASP_HOST PCM_SRV_HOST PCM_SRV_BIN PCM_SRV_PREFIX PCM_WIN_HOST PCM_WIN_PREFIX PCM_WIN_BIN PCM_WIN_SHELL
PCM_SRC_ROOTS PCM_HAL_BINS PCM_RASP_BIN PCM_RASP_PREFIX
$(t "Journal" "Log"): $kLog
EOF
}
log() { printf '%s %s\n' "$(date '+%F %T')" "$*" >> "$kLog"; }
say() { printf '%s\n' "$*"; log "$*"; }
warn() { printf '%s\n' "$*" >&2; log "WARN $*"; }
cleanup() { :; }
onSignal() { warn "$(t "Interrompu (signal)" "Interrupted (signal)")"; exit 130; }
trap cleanup EXIT
trap onSignal INT TERM HUP
# --- Arguments -----------------------------------------------------------
while (($#)); do
case "$1" in
-n|--dry-run) optDry=1 ;;
--hal-only) optHalOnly=1 ;;
--targets) shift; optTargets="${1:?--targets}" ;;
--only) shift; optOnly="${1:?--only}" ;;
--language) shift; optLang="${1:?--language}"; optLang="${optLang^^}"
[[ "$optLang" == "FR" || "$optLang" == "UK" ]] || { echo "--language FR|UK" >&2; exit 2; } ;;
-h|--help) usage; exit 0 ;;
*) echo "$(t "Option inconnue" "Unknown option"): $1" >&2; usage >&2; exit 2 ;;
esac
shift
done
# --- Outils locaux ---------------------------------------------------------
# Derniere version Vx.yy d'un projet (ignore .not, .discontinued, .old...)
latestVersion() {
local pdir="$1"
find "$pdir" -mindepth 1 -maxdepth 1 -type d -name 'V[0-9]*' -printf '%f\n' \
| grep -Ev '\.(not|old|discontinued|bak)' | sort -V | tail -n 1
}
# Genre de build : cmake | unix | make | (rien => non compilable)
buildKind() {
local s="$1"
if [[ -f "$s/CMakeLists.txt" ]]; then echo cmake
elif [[ -f "$s/makefile.unix" ]]; then echo unix
elif [[ -f "$s/makefile" || -f "$s/Makefile" ]]; then echo make
else return 1; fi
}
srcFiles() {
find "$1" \( -name build -o -name .git \) -prune -o -type f \
\( -name '*.cpp' -o -name '*.h' -o -name '*.hpp' -o -name '*.c' \
-o -name 'CMakeLists.txt' -o -name 'makefile*' -o -name 'Makefile' \
-o -name '*.po' -o -name '.pcmake' \) -print0
}
srcHash() {
( cd "$1" && srcFiles . | sort -z | xargs -0 -r sha256sum | sha256sum | cut -d' ' -f1 )
}
findBuilt() { # src prog
local c
for c in "$1/build/$2" "$1/$2"; do
if [[ -f "$c" && -x "$c" ]]; then echo "$c"; return 0; fi
done
return 1
}
findInstalled() { # prog
local d
for d in "${HAL_BINS[@]}"; do
if [[ -f "$d/$1" ]]; then echo "$d/$1"; return 0; fi
done
return 1
}
needRebuild() { # src prog
local bin
bin="$(findBuilt "$1" "$2")" || return 0
[[ -n "$(srcFiles "$1" | xargs -0 -r -I{} find {} -newer "$bin" -print -quit)" ]]
}
halBuild() { # src kind
local s="$1" k="$2" out="$1/.pcbuild.log"
(
cd "$s"
case "$k" in
cmake) cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
&& cmake --build build -j"$(nproc)" ;;
unix) make -f makefile.unix -j"$(nproc)" ;;
make) make -j"$(nproc)" ;;
esac
) >"$out" 2>&1 || { tail -n 3 "$out" >&2; return 1; }
}
fail() { nbFail=$((nbFail+1)); failures+=("$1"); warn "KO $1"; }
# --- Phase 1 : hal -----------------------------------------------------------
declare -a projects=() # "root|prog|ver|kind"
phaseHal() {
local root pdir prog ver kind src bin inst dest
for root in "${SRC_ROOTS[@]}"; do
[[ -d "$root" ]] || { warn "$root $(t "absent" "missing")"; continue; }
for pdir in "$root"/*/; do
pdir="${pdir%/}"; prog="$(basename "$pdir")"
[[ -z "$optOnly" || "$optOnly" == "$prog" ]] || continue
ver="$(latestVersion "$pdir")" || true
[[ -n "$ver" ]] || continue
src="$pdir/$ver"
kind="$(buildKind "$src")" || continue
projects+=("$root|$prog|$ver|$kind")
if needRebuild "$src" "$prog"; then
if ((optDry)); then say "DRY build $prog $ver"
else
if halBuild "$src" "$kind"; then nbBuilt=$((nbBuilt+1)); say "BUILD $prog $ver"
else fail "hal build $prog $ver"; continue; fi
fi
fi
bin="$(findBuilt "$src" "$prog")" || { ((optDry)) || fail "hal $prog $(t "binaire introuvable" "binary not found")"; continue; }
if inst="$(findInstalled "$prog")" && cmp -s "$bin" "$inst"; then
nbOk=$((nbOk+1)); continue
fi
dest="$(dirname "${inst:-$HAL_DEFAULT_BIN/$prog}")"
if ((optDry)); then say "DRY install $prog -> $dest"
elif install -m 0755 "$bin" "$dest/$prog"; then
nbInstalled=$((nbInstalled+1)); say "INST $prog -> $dest"
else fail "hal install $prog"; fi
done
done
}
# --- Phase 2 : cibles distantes -----------------------------------------------
REMOTE_BUILD='set -eu
d=$1; p=$2; dest=$3; h=$4
cd "$d"
if [ -f CMakeLists.txt ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build -j"$(nproc)"; b=build/$p
elif [ -f makefile.unix ]; then make -f makefile.unix -j"$(nproc)"; b=$p
else make -j"$(nproc)"; b=$p; fi >.pcbuild.log 2>&1 || { tail -n 3 .pcbuild.log >&2; exit 1; }
[ -f "$b.exe" ] && b=$b.exe
[ -f "$b" ] || { echo "binaire introuvable" >&2; exit 1; }
mkdir -p "$dest"; install -m 0755 "$b" "$dest/"
printf "%s\n" "$h" > .pcsrc.sha256'
# rrun <cible> <commande sans apostrophe> [args...] (stdin transmis)
rrun() {
local tgt="$1"; shift
local cmd="$*"
if [[ "$tgt" == "win" ]]; then
ssh "${SSH_OPTS[@]}" "$WIN_HOST" "$WIN_SHELL '$cmd'"
elif [[ "$tgt" == "srv" ]]; then
ssh "${SSH_OPTS[@]}" "$SRV_HOST" "$cmd"
else
ssh "${SSH_OPTS[@]}" "$RASP_HOST" "$cmd"
fi
}
pushTarget() { # tgt host prefix bin
local tgt="$1" host="$2" prefix="$3" rbin="$4"
local entry root prog ver kind src rdir hash rhash
if ((optDry)); then :; elif ! ssh "${SSH_OPTS[@]}" "$host" true 2>/dev/null; then
warn "$host $(t "injoignable, cible ignoree" "unreachable, target skipped")"; return 0
fi
for entry in "${projects[@]}"; do
IFS='|' read -r root prog ver kind <<<"$entry"
src="$root/$prog/$ver"; rdir="$prefix$root/$prog/$ver"
hash="$(srcHash "$src")"
rhash=""
if ! ((optDry)); then
rhash="$(rrun "$tgt" "cat $rdir/.pcsrc.sha256 2>/dev/null || true" </dev/null | tr -d '\r\n')" || true
fi
[[ "$hash" != "$rhash" ]] || { nbOk=$((nbOk+1)); continue; }
if ((optDry)); then say "DRY $host $prog $ver (send+build+install)"; continue; fi
if ! ( cd "$src" && tar --exclude=./build --exclude=./.git --exclude="./$prog" \
--exclude=./.pcbuild.log -cf - . ) \
| rrun "$tgt" "mkdir -p $rdir && tar -C $rdir -xf -"; then
fail "$host send $prog"; continue
fi
nbSent=$((nbSent+1))
if printf '%s\n' "$REMOTE_BUILD" | rrun "$tgt" "bash -s -- $rdir $prog $rbin $hash"; then
say "OK $host $prog $ver"
else
fail "$host build $prog $ver"
fi
done
}
# --- Principal -----------------------------------------------------------------
: >> "$kLog"
say "$kProg V$kVersion $(t "demarre" "started")$( ((optDry)) && echo ' (dry-run)')"
phaseHal
if ! ((optHalOnly)); then
[[ ",$optTargets," == *,rasp,* ]] && pushTarget rasp "$RASP_HOST" "$RASP_PREFIX" "$RASP_BIN"
[[ ",$optTargets," == *,srv,* ]] && pushTarget srv "$SRV_HOST" "$SRV_PREFIX" "$SRV_BIN"
[[ ",$optTargets," == *,win,* ]] && pushTarget win "$WIN_HOST" "$WIN_PREFIX" "$WIN_BIN"
fi
say "$(t "Bilan" "Summary"): ok=$nbOk build=$nbBuilt inst=$nbInstalled envoyes=$nbSent ko=$nbFail"
if ((nbFail)); then printf ' - %s\n' "${failures[@]}" >&2; exit 1; fi
exit 0