Ajoute un mode local Proxmox sans installation hôte

This commit is contained in:
2026-04-12 14:38:44 +02:00
parent a90b1b6d8a
commit 7330563ae6
5 changed files with 218 additions and 149 deletions

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git"
REPO_BRANCH="${CHESSCUBING_GIT_BRANCH:-main}"
RAW_BASE_URL="https://git.jeannerot.fr/christophe/chesscubing/raw/branch/${REPO_BRANCH}"
usage() {
cat <<'EOF'
@@ -15,6 +15,7 @@ Usage en une ligne :
bash -c "$(curl -fsSL https://git.jeannerot.fr/christophe/chesscubing/raw/branch/main/update-chesscubing-proxmox.sh)"
Variables d'environnement reconnues :
CHESSCUBING_LOCAL
CHESSCUBING_PROXMOX_HOST
CHESSCUBING_PROXMOX_USER
CHESSCUBING_PROXMOX_PASSWORD
@@ -34,34 +35,8 @@ have_cmd() {
command -v "$1" >/dev/null 2>&1
}
install_pkg_if_missing() {
local missing=()
local pkg=""
for pkg in "$@"; do
if ! have_cmd "$pkg"; then
missing+=("$pkg")
fi
done
if [[ ${#missing[@]} -eq 0 ]]; then
return 0
fi
if ! have_cmd apt-get; then
die "Commandes manquantes: ${missing[*]}. Installe-les manuellement."
fi
printf 'Installation des dépendances manquantes: %s\n' "${missing[*]}"
if have_cmd sudo && [[ "${EUID}" -ne 0 ]]; then
sudo apt-get update
sudo apt-get install -y git sshpass openssh-client ca-certificates
elif [[ "${EUID}" -eq 0 ]]; then
apt-get update
apt-get install -y git sshpass openssh-client ca-certificates
else
die "git/sshpass manquent et sudo n'est pas disponible."
fi
need_cmd() {
have_cmd "$1" || die "La commande '$1' est requise."
}
prompt_default() {
@@ -103,8 +78,9 @@ if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
exit 0
fi
install_pkg_if_missing git ssh sshpass
need_cmd curl
LOCAL_MODE="${CHESSCUBING_LOCAL:-}"
PROXMOX_HOST="${CHESSCUBING_PROXMOX_HOST:-}"
PROXMOX_USER="${CHESSCUBING_PROXMOX_USER:-}"
PROXMOX_PASSWORD="${CHESSCUBING_PROXMOX_PASSWORD:-}"
@@ -112,23 +88,33 @@ SSH_PORT="${CHESSCUBING_SSH_PORT:-22}"
CTID="${CHESSCUBING_CTID:-}"
LXC_HOSTNAME="${CHESSCUBING_LXC_HOSTNAME:-chesscubing-web}"
default_host=""
if have_cmd pct && have_cmd pveam; then
default_host="127.0.0.1"
if [[ -z "$LOCAL_MODE" && -z "$PROXMOX_HOST" ]]; then
if have_cmd pct && have_cmd pveam; then
LOCAL_MODE="1"
else
LOCAL_MODE="0"
fi
fi
if [[ "$LOCAL_MODE" != "1" ]]; then
need_cmd ssh
need_cmd sshpass
prompt_default PROXMOX_HOST "IP ou nom du serveur Proxmox" ""
prompt_default PROXMOX_USER "Utilisateur SSH Proxmox" "root@pam"
prompt_secret PROXMOX_PASSWORD "Mot de passe SSH Proxmox"
prompt_default SSH_PORT "Port SSH Proxmox" "22"
fi
prompt_default PROXMOX_HOST "IP ou nom du serveur Proxmox" "$default_host"
prompt_default PROXMOX_USER "Utilisateur SSH Proxmox" "root@pam"
prompt_secret PROXMOX_PASSWORD "Mot de passe SSH Proxmox"
prompt_default SSH_PORT "Port SSH Proxmox" "22"
prompt_default CTID "CTID du LXC (laisser vide pour rechercher par nom)" ""
if [[ -z "$CTID" ]]; then
prompt_default LXC_HOSTNAME "Nom du LXC" "chesscubing-web"
fi
[[ -n "$PROXMOX_HOST" ]] || die "Le serveur Proxmox est obligatoire."
[[ -n "$PROXMOX_USER" ]] || die "L'utilisateur Proxmox est obligatoire."
[[ -n "$PROXMOX_PASSWORD" ]] || die "Le mot de passe Proxmox est obligatoire."
if [[ "$LOCAL_MODE" != "1" ]]; then
[[ -n "$PROXMOX_HOST" ]] || die "Le serveur Proxmox est obligatoire."
[[ -n "$PROXMOX_USER" ]] || die "L'utilisateur Proxmox est obligatoire."
[[ -n "$PROXMOX_PASSWORD" ]] || die "Le mot de passe Proxmox est obligatoire."
fi
TMP_DIR="$(mktemp -d)"
cleanup() {
@@ -136,18 +122,26 @@ cleanup() {
}
trap cleanup EXIT
printf 'Clonage temporaire du dépôt ChessCubing...\n'
git clone --depth 1 --branch "$REPO_BRANCH" "$REPO_URL" "$TMP_DIR/repo" >/dev/null 2>&1
printf 'Téléchargement du script de mise à jour ChessCubing...\n'
curl -fsSL "${RAW_BASE_URL}/scripts/update-proxmox-lxc.sh" -o "$TMP_DIR/update-proxmox-lxc.sh"
chmod +x "$TMP_DIR/update-proxmox-lxc.sh"
cmd=(
"$TMP_DIR/repo/scripts/update-proxmox-lxc.sh"
--proxmox-host "$PROXMOX_HOST"
--proxmox-user "$PROXMOX_USER"
--proxmox-password "$PROXMOX_PASSWORD"
--ssh-port "$SSH_PORT"
"$TMP_DIR/update-proxmox-lxc.sh"
--branch "$REPO_BRANCH"
)
if [[ "$LOCAL_MODE" == "1" ]]; then
cmd+=(--local)
else
cmd+=(
--proxmox-host "$PROXMOX_HOST"
--proxmox-user "$PROXMOX_USER"
--proxmox-password "$PROXMOX_PASSWORD"
--ssh-port "$SSH_PORT"
)
fi
if [[ -n "$CTID" ]]; then
cmd+=(--ctid "$CTID")
else