Ajoute des scripts bootstrap pour Proxmox
This commit is contained in:
158
update-chesscubing-proxmox.sh
Executable file
158
update-chesscubing-proxmox.sh
Executable file
@@ -0,0 +1,158 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
REPO_URL="https://git.jeannerot.fr/christophe/chesscubing.git"
|
||||
REPO_BRANCH="${CHESSCUBING_GIT_BRANCH:-main}"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Bootstrap de mise à jour ChessCubing pour Proxmox.
|
||||
|
||||
Usage local :
|
||||
./update-chesscubing-proxmox.sh
|
||||
|
||||
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_PROXMOX_HOST
|
||||
CHESSCUBING_PROXMOX_USER
|
||||
CHESSCUBING_PROXMOX_PASSWORD
|
||||
CHESSCUBING_SSH_PORT
|
||||
CHESSCUBING_CTID
|
||||
CHESSCUBING_LXC_HOSTNAME
|
||||
CHESSCUBING_GIT_BRANCH
|
||||
EOF
|
||||
}
|
||||
|
||||
die() {
|
||||
printf 'Erreur: %s\n' "$*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
prompt_default() {
|
||||
local var_name="$1"
|
||||
local prompt_label="$2"
|
||||
local default_value="${3:-}"
|
||||
local current_value="${!var_name:-}"
|
||||
local input=""
|
||||
|
||||
if [[ -n "$current_value" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ -n "$default_value" ]]; then
|
||||
read -r -p "$prompt_label [$default_value]: " input
|
||||
printf -v "$var_name" '%s' "${input:-$default_value}"
|
||||
else
|
||||
read -r -p "$prompt_label: " input
|
||||
printf -v "$var_name" '%s' "$input"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_secret() {
|
||||
local var_name="$1"
|
||||
local prompt_label="$2"
|
||||
local current_value="${!var_name:-}"
|
||||
|
||||
if [[ -n "$current_value" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
read -rsp "$prompt_label: " current_value
|
||||
echo
|
||||
printf -v "$var_name" '%s' "$current_value"
|
||||
}
|
||||
|
||||
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
install_pkg_if_missing git ssh sshpass
|
||||
|
||||
PROXMOX_HOST="${CHESSCUBING_PROXMOX_HOST:-}"
|
||||
PROXMOX_USER="${CHESSCUBING_PROXMOX_USER:-}"
|
||||
PROXMOX_PASSWORD="${CHESSCUBING_PROXMOX_PASSWORD:-}"
|
||||
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"
|
||||
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."
|
||||
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
cleanup() {
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
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
|
||||
|
||||
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"
|
||||
--branch "$REPO_BRANCH"
|
||||
)
|
||||
|
||||
if [[ -n "$CTID" ]]; then
|
||||
cmd+=(--ctid "$CTID")
|
||||
else
|
||||
cmd+=(--hostname "$LXC_HOSTNAME")
|
||||
fi
|
||||
|
||||
printf 'Lancement de la mise à jour ChessCubing...\n'
|
||||
"${cmd[@]}"
|
||||
Reference in New Issue
Block a user