2026-02-12 15:46:57 -08:00
|
|
|
#!/usr/bin/env bash
|
2026-04-12 18:20:41 -07:00
|
|
|
# Fix Besu installation on selected nodes.
|
2026-02-12 15:46:57 -08:00
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
2026-04-12 18:20:41 -07:00
|
|
|
source "$PROJECT_ROOT/scripts/lib/load-project-env.sh"
|
2026-02-12 15:46:57 -08:00
|
|
|
|
2026-04-12 18:20:41 -07:00
|
|
|
APPLY=false
|
|
|
|
|
TARGET_VMIDS=()
|
|
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
|
cat <<'EOF'
|
|
|
|
|
Usage: ./scripts/fix-besu-installation.sh --vmid <N> [--vmid <N> ...] [--apply]
|
|
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
--vmid <N> Required. Limit fix to one or more VMIDs.
|
|
|
|
|
--apply Perform the install fix. Without this flag, the script prints the target VMIDs and exits.
|
|
|
|
|
EOF
|
2026-02-12 15:46:57 -08:00
|
|
|
}
|
|
|
|
|
|
2026-04-12 18:20:41 -07:00
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
--vmid)
|
|
|
|
|
[[ $# -ge 2 ]] || { usage >&2; exit 2; }
|
|
|
|
|
TARGET_VMIDS+=("$2")
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
--apply)
|
|
|
|
|
APPLY=true
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-h|--help)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
echo "Unknown argument: $1" >&2
|
|
|
|
|
usage >&2
|
|
|
|
|
exit 2
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
[[ ${#TARGET_VMIDS[@]} -gt 0 ]] || { usage >&2; exit 2; }
|
|
|
|
|
|
|
|
|
|
if ! $APPLY; then
|
|
|
|
|
echo "Dry-run only. Target VMIDs:"
|
|
|
|
|
for vmid in "${TARGET_VMIDS[@]}"; do
|
|
|
|
|
echo " VMID $vmid on $(get_host_for_vmid "$vmid")"
|
|
|
|
|
done
|
|
|
|
|
echo "Re-run with --apply to perform the Besu installation fix."
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-12 15:46:57 -08:00
|
|
|
fix_besu() {
|
|
|
|
|
local vmid=$1
|
2026-04-12 18:20:41 -07:00
|
|
|
local host
|
|
|
|
|
host="$(get_host_for_vmid "$vmid")"
|
2026-02-12 15:46:57 -08:00
|
|
|
|
|
|
|
|
ssh -o StrictHostKeyChecking=no root@${host} "pct exec $vmid -- bash -c '
|
|
|
|
|
cd /opt
|
|
|
|
|
if [ -f besu-23.10.3.tar.gz ] && [ ! -d besu-23.10.3 ]; then
|
|
|
|
|
echo \"Extracting Besu for $vmid...\"
|
|
|
|
|
tar -xzf besu-23.10.3.tar.gz
|
|
|
|
|
fi
|
|
|
|
|
if [ -d besu-23.10.3 ] && [ ! -L besu ]; then
|
|
|
|
|
ln -sf besu-23.10.3 besu
|
|
|
|
|
fi
|
|
|
|
|
if [ -d besu-23.10.3 ]; then
|
|
|
|
|
chown -R besu:besu besu-23.10.3 besu 2>/dev/null || true
|
|
|
|
|
echo \"Besu fixed for $vmid\"
|
|
|
|
|
fi
|
|
|
|
|
'" 2>&1 | grep -E "(Extracting|fixed)" || true
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-12 18:20:41 -07:00
|
|
|
for vmid in "${TARGET_VMIDS[@]}"; do
|
|
|
|
|
fix_besu "$vmid" &
|
2026-02-12 15:46:57 -08:00
|
|
|
done
|
|
|
|
|
wait
|
2026-04-12 18:20:41 -07:00
|
|
|
echo "Besu installation fix attempted on selected nodes"
|