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

@@ -34,8 +34,8 @@ Deux scripts Bash permettent de créer un conteneur LXC Debian sur Proxmox puis
Prérequis sur la machine qui lance les scripts :
- `ssh`
- `sshpass`
- en mode distant : `ssh` et `sshpass`
- en mode local sur l'hôte Proxmox : aucun paquet supplémentaire n'est installé sur Proxmox
Le déploiement dans le LXC n'utilise pas Docker. Le script installe `nginx`, `git` et `rsync` dans le conteneur, clone le dépôt puis publie uniquement les fichiers web.
@@ -56,6 +56,12 @@ bash -c "$(curl -fsSL https://git.jeannerot.fr/christophe/chesscubing/raw/branch
Cette version pose les questions nécessaires si les variables d'environnement ne sont pas déjà définies.
Si elle est lancée directement sur l'hôte Proxmox, elle passe automatiquement en mode local :
- elle ne demande ni serveur, ni login, ni mot de passe SSH
- elle n'installe rien sur l'hôte Proxmox
- elle crée uniquement le LXC puis installe les dépendances dans ce LXC
Valeurs par défaut utiles :
- LXC nommé `chesscubing-web`
@@ -93,6 +99,8 @@ Version "curl | bash" :
bash -c "$(curl -fsSL https://git.jeannerot.fr/christophe/chesscubing/raw/branch/main/update-chesscubing-proxmox.sh)"
```
Sur l'hôte Proxmox, cette commande met à jour le LXC local sans passer par SSH.
On peut aussi cibler le conteneur par nom si on n'a pas le `CTID` :
```bash

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/install-chesscubing-proxmox.sh)"
Variables d'environnement reconnues :
CHESSCUBING_LOCAL
CHESSCUBING_PROXMOX_HOST
CHESSCUBING_PROXMOX_USER
CHESSCUBING_PROXMOX_PASSWORD
@@ -44,34 +45,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() {
@@ -113,8 +88,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:-}"
@@ -132,15 +108,23 @@ TEMPLATE_STORAGE="${CHESSCUBING_TEMPLATE_STORAGE:-}"
ROOTFS_STORAGE="${CHESSCUBING_ROOTFS_STORAGE:-}"
LXC_PASSWORD="${CHESSCUBING_LXC_PASSWORD:-}"
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 Proxmox (laisser vide pour auto)" ""
prompt_default LXC_HOSTNAME "Nom du LXC" "chesscubing-web"
prompt_default LXC_IP "IP du LXC ou dhcp" "dhcp"
@@ -149,9 +133,11 @@ if [[ "$LXC_IP" != "dhcp" ]]; then
fi
prompt_default LXC_BRIDGE "Bridge réseau Proxmox" "vmbr0"
[[ -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() {
@@ -159,15 +145,12 @@ 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 dinstallation ChessCubing...\n'
curl -fsSL "${RAW_BASE_URL}/scripts/install-proxmox-lxc.sh" -o "$TMP_DIR/install-proxmox-lxc.sh"
chmod +x "$TMP_DIR/install-proxmox-lxc.sh"
cmd=(
"$TMP_DIR/repo/scripts/install-proxmox-lxc.sh"
--proxmox-host "$PROXMOX_HOST"
--proxmox-user "$PROXMOX_USER"
--proxmox-password "$PROXMOX_PASSWORD"
--ssh-port "$SSH_PORT"
"$TMP_DIR/install-proxmox-lxc.sh"
--hostname "$LXC_HOSTNAME"
--lxc-ip "$LXC_IP"
--bridge "$LXC_BRIDGE"
@@ -178,6 +161,17 @@ cmd=(
--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")
fi

View File

@@ -9,11 +9,14 @@ Usage:
--proxmox-user root@pam \
--proxmox-password 'motdepasse'
./scripts/install-proxmox-lxc.sh --local
Options principales:
--proxmox-host IP ou nom DNS du serveur Proxmox
--proxmox-user Utilisateur SSH Proxmox (defaut: root@pam)
--proxmox-password Mot de passe SSH Proxmox
--ssh-port Port SSH Proxmox (defaut: 22)
--local Execute directement sur l'hote Proxmox local
--ctid CTID Proxmox. Si vide, le prochain ID libre est utilise
--hostname Nom du LXC (defaut: chesscubing-web)
--lxc-ip IP du LXC ou 'dhcp' (defaut: dhcp)
@@ -51,6 +54,7 @@ PROXMOX_HOST=""
PROXMOX_USER="root@pam"
PROXMOX_PASSWORD="${PROXMOX_PASSWORD:-}"
PROXMOX_PORT="22"
LOCAL_MODE="0"
CTID=""
LXC_HOSTNAME="chesscubing-web"
@@ -85,6 +89,10 @@ while [[ $# -gt 0 ]]; do
PROXMOX_PORT="${2:-}"
shift 2
;;
--local)
LOCAL_MODE="1"
shift
;;
--ctid)
CTID="${2:-}"
shift 2
@@ -151,41 +159,19 @@ while [[ $# -gt 0 ]]; do
esac
done
[[ -n "$PROXMOX_HOST" ]] || die "Merci de fournir --proxmox-host."
[[ -n "$PROXMOX_USER" ]] || die "Merci de fournir --proxmox-user."
if [[ -z "$PROXMOX_PASSWORD" ]]; then
read -rsp "Mot de passe SSH pour ${PROXMOX_USER}@${PROXMOX_HOST}: " PROXMOX_PASSWORD
echo
if [[ "$LOCAL_MODE" != "1" && -z "$PROXMOX_HOST" ]]; then
if command -v pct >/dev/null 2>&1 && command -v pveam >/dev/null 2>&1; then
LOCAL_MODE="1"
fi
fi
need_cmd ssh
need_cmd sshpass
payload_script="$(mktemp)"
cleanup() {
rm -f "$payload_script"
}
trap cleanup EXIT
printf 'Creation du LXC "%s" sur %s...\n' "$LXC_HOSTNAME" "$PROXMOX_HOST"
sshpass -p "$PROXMOX_PASSWORD" \
ssh \
-p "$PROXMOX_PORT" \
-o StrictHostKeyChecking=accept-new \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
"$PROXMOX_USER@$PROXMOX_HOST" \
bash -s -- \
"$CTID" \
"$LXC_HOSTNAME" \
"$LXC_IP" \
"$LXC_GATEWAY" \
"$LXC_BRIDGE" \
"$LXC_CORES" \
"$LXC_MEMORY" \
"$LXC_SWAP" \
"$LXC_DISK_GB" \
"$TEMPLATE_STORAGE" \
"$ROOTFS_STORAGE" \
"$REPO_URL" \
"$REPO_BRANCH" \
"$LXC_PASSWORD" <<'REMOTE'
cat >"$payload_script" <<'REMOTE'
set -euo pipefail
ctid="$1"
@@ -435,3 +421,59 @@ Pour mettre a jour l'application plus tard:
./scripts/update-proxmox-lxc.sh --proxmox-host <ip-proxmox> --proxmox-user <user> --proxmox-password '<motdepasse>' --ctid $ctid
EOF
REMOTE
if [[ "$LOCAL_MODE" == "1" ]]; then
printf 'Creation du LXC "%s" en local sur cet hote Proxmox...\n' "$LXC_HOSTNAME"
bash "$payload_script" \
"$CTID" \
"$LXC_HOSTNAME" \
"$LXC_IP" \
"$LXC_GATEWAY" \
"$LXC_BRIDGE" \
"$LXC_CORES" \
"$LXC_MEMORY" \
"$LXC_SWAP" \
"$LXC_DISK_GB" \
"$TEMPLATE_STORAGE" \
"$ROOTFS_STORAGE" \
"$REPO_URL" \
"$REPO_BRANCH" \
"$LXC_PASSWORD"
exit 0
fi
[[ -n "$PROXMOX_HOST" ]] || die "Merci de fournir --proxmox-host."
[[ -n "$PROXMOX_USER" ]] || die "Merci de fournir --proxmox-user."
if [[ -z "$PROXMOX_PASSWORD" ]]; then
read -rsp "Mot de passe SSH pour ${PROXMOX_USER}@${PROXMOX_HOST}: " PROXMOX_PASSWORD
echo
fi
need_cmd ssh
need_cmd sshpass
printf 'Creation du LXC "%s" sur %s...\n' "$LXC_HOSTNAME" "$PROXMOX_HOST"
sshpass -p "$PROXMOX_PASSWORD" \
ssh \
-p "$PROXMOX_PORT" \
-o StrictHostKeyChecking=accept-new \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
"$PROXMOX_USER@$PROXMOX_HOST" \
bash -s -- \
"$CTID" \
"$LXC_HOSTNAME" \
"$LXC_IP" \
"$LXC_GATEWAY" \
"$LXC_BRIDGE" \
"$LXC_CORES" \
"$LXC_MEMORY" \
"$LXC_SWAP" \
"$LXC_DISK_GB" \
"$TEMPLATE_STORAGE" \
"$ROOTFS_STORAGE" \
"$REPO_URL" \
"$REPO_BRANCH" \
"$LXC_PASSWORD" < "$payload_script"

View File

@@ -10,11 +10,14 @@ Usage:
--proxmox-password 'motdepasse' \
--ctid 120
./scripts/update-proxmox-lxc.sh --local --ctid 120
Options principales:
--proxmox-host IP ou nom DNS du serveur Proxmox
--proxmox-user Utilisateur SSH Proxmox (defaut: root@pam)
--proxmox-password Mot de passe SSH Proxmox
--ssh-port Port SSH Proxmox (defaut: 22)
--local Execute directement sur l'hote Proxmox local
--ctid CTID du LXC a mettre a jour
--hostname Nom du LXC si le CTID n'est pas fourni (defaut: chesscubing-web)
--branch Branche Git a deployer (defaut: main)
@@ -35,6 +38,7 @@ PROXMOX_HOST=""
PROXMOX_USER="root@pam"
PROXMOX_PASSWORD="${PROXMOX_PASSWORD:-}"
PROXMOX_PORT="22"
LOCAL_MODE="0"
CTID=""
LXC_HOSTNAME="chesscubing-web"
@@ -58,6 +62,10 @@ while [[ $# -gt 0 ]]; do
PROXMOX_PORT="${2:-}"
shift 2
;;
--local)
LOCAL_MODE="1"
shift
;;
--ctid)
CTID="${2:-}"
shift 2
@@ -80,30 +88,19 @@ while [[ $# -gt 0 ]]; do
esac
done
[[ -n "$PROXMOX_HOST" ]] || die "Merci de fournir --proxmox-host."
[[ -n "$PROXMOX_USER" ]] || die "Merci de fournir --proxmox-user."
if [[ -z "$PROXMOX_PASSWORD" ]]; then
read -rsp "Mot de passe SSH pour ${PROXMOX_USER}@${PROXMOX_HOST}: " PROXMOX_PASSWORD
echo
if [[ "$LOCAL_MODE" != "1" && -z "$PROXMOX_HOST" ]]; then
if command -v pct >/dev/null 2>&1 && command -v pveam >/dev/null 2>&1; then
LOCAL_MODE="1"
fi
fi
need_cmd ssh
need_cmd sshpass
payload_script="$(mktemp)"
cleanup() {
rm -f "$payload_script"
}
trap cleanup EXIT
printf 'Mise a jour du LXC ChessCubing sur %s...\n' "$PROXMOX_HOST"
sshpass -p "$PROXMOX_PASSWORD" \
ssh \
-p "$PROXMOX_PORT" \
-o StrictHostKeyChecking=accept-new \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
"$PROXMOX_USER@$PROXMOX_HOST" \
bash -s -- \
"$CTID" \
"$LXC_HOSTNAME" \
"$REPO_BRANCH" <<'REMOTE'
cat >"$payload_script" <<'REMOTE'
set -euo pipefail
ctid="$1"
@@ -168,3 +165,37 @@ Mise a jour terminee.
- URL probable: http://${container_ip:-<ip_du_lxc>}
EOF
REMOTE
if [[ "$LOCAL_MODE" == "1" ]]; then
printf 'Mise a jour du LXC ChessCubing en local sur cet hote Proxmox...\n'
bash "$payload_script" \
"$CTID" \
"$LXC_HOSTNAME" \
"$REPO_BRANCH"
exit 0
fi
[[ -n "$PROXMOX_HOST" ]] || die "Merci de fournir --proxmox-host."
[[ -n "$PROXMOX_USER" ]] || die "Merci de fournir --proxmox-user."
if [[ -z "$PROXMOX_PASSWORD" ]]; then
read -rsp "Mot de passe SSH pour ${PROXMOX_USER}@${PROXMOX_HOST}: " PROXMOX_PASSWORD
echo
fi
need_cmd ssh
need_cmd sshpass
printf 'Mise a jour du LXC ChessCubing sur %s...\n' "$PROXMOX_HOST"
sshpass -p "$PROXMOX_PASSWORD" \
ssh \
-p "$PROXMOX_PORT" \
-o StrictHostKeyChecking=accept-new \
-o PreferredAuthentications=password \
-o PubkeyAuthentication=no \
"$PROXMOX_USER@$PROXMOX_HOST" \
bash -s -- \
"$CTID" \
"$LXC_HOSTNAME" \
"$REPO_BRANCH" < "$payload_script"

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,17 +122,25 @@ 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"
"$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"
--branch "$REPO_BRANCH"
)
)
fi
if [[ -n "$CTID" ]]; then
cmd+=(--ctid "$CTID")