92 lines
3.6 KiB
Bash
92 lines
3.6 KiB
Bash
#!/bin/bash
|
|
#===============================================================================
|
|
# Installe pve-netconfig sur un hôte Proxmox VE 9 fraîchement installé.
|
|
# À exécuter en root immédiatement après l'installation du serveur.
|
|
#===============================================================================
|
|
set -euo pipefail
|
|
|
|
[[ $EUID -eq 0 ]] || { echo "Exécuter en root." >&2; exit 1; }
|
|
|
|
SRC_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo "==> Vérification de l'environnement"
|
|
if ! command -v pveversion >/dev/null 2>&1; then
|
|
echo "AVERTISSEMENT : pveversion introuvable, est-ce bien un hôte Proxmox VE ?" >&2
|
|
fi
|
|
echo " Debian : $(cat /etc/debian_version)"
|
|
|
|
echo "==> Installation des dépendances"
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
apt-get update -qq
|
|
apt-get install -y --no-install-recommends jq iproute2
|
|
|
|
# Client DHCP : vérifier qu'au moins un est présent
|
|
if ! command -v dhclient >/dev/null 2>&1 && ! command -v dhcpcd >/dev/null 2>&1; then
|
|
echo "==> Aucun client DHCP détecté, installation d'isc-dhcp-client"
|
|
apt-get install -y --no-install-recommends isc-dhcp-client
|
|
fi
|
|
|
|
echo "==> Sauvegarde de la configuration réseau initiale"
|
|
mkdir -p /var/backups/pve-netconfig
|
|
cp -a /etc/network/interfaces "/var/backups/pve-netconfig/interfaces.pre-install.$(date +%Y%m%d-%H%M%S)"
|
|
cp -a /etc/hosts "/var/backups/pve-netconfig/hosts.pre-install.$(date +%Y%m%d-%H%M%S)"
|
|
|
|
echo "==> Copie des scripts"
|
|
install -m 0750 -o root -g root "${SRC_DIR}/pve-netconfig.sh" /usr/local/sbin/pve-netconfig.sh
|
|
install -m 0750 -o root -g root "${SRC_DIR}/pve-netconfig-watch.sh" /usr/local/sbin/pve-netconfig-watch.sh
|
|
|
|
echo "==> Installation des unités systemd"
|
|
install -m 0644 "${SRC_DIR}/pve-netconfig.service" /etc/systemd/system/
|
|
install -m 0644 "${SRC_DIR}/pve-netconfig.timer" /etc/systemd/system/
|
|
install -m 0644 "${SRC_DIR}/pve-netconfig-watch.service" /etc/systemd/system/
|
|
|
|
echo "==> Installation du hook DHCP"
|
|
if command -v dhclient >/dev/null 2>&1; then
|
|
mkdir -p /etc/dhcp/dhclient-exit-hooks.d
|
|
install -m 0755 "${SRC_DIR}/dhclient-hook" /etc/dhcp/dhclient-exit-hooks.d/pve-netconfig
|
|
echo " Hook dhclient installé."
|
|
fi
|
|
if command -v dhcpcd >/dev/null 2>&1; then
|
|
mkdir -p /usr/lib/dhcpcd/dhcpcd-hooks
|
|
install -m 0755 "${SRC_DIR}/dhcpcd-hook" /usr/lib/dhcpcd/dhcpcd-hooks/90-pve-netconfig
|
|
echo " Hook dhcpcd installé."
|
|
fi
|
|
|
|
echo "==> Activation des services"
|
|
systemctl daemon-reload
|
|
systemctl enable pve-netconfig.service
|
|
systemctl enable pve-netconfig.timer
|
|
systemctl enable pve-netconfig-watch.service
|
|
|
|
cat <<'EOF'
|
|
|
|
===============================================================================
|
|
Installation terminée.
|
|
|
|
ÉTAPES SUIVANTES (à faire manuellement) :
|
|
|
|
1. Éditer la section CONFIGURATION du script :
|
|
nano /usr/local/sbin/pve-netconfig.sh
|
|
-> FALLBACK_IP, FALLBACK_CIDR, FALLBACK_GATEWAY, FALLBACK_DNS
|
|
-> PORT_MAIN / PORT_SECONDARY si la détection automatique échoue
|
|
|
|
2. Vérifier la détection des ports :
|
|
pve-netconfig.sh status
|
|
ip -br link
|
|
|
|
3. Générer /etc/network/interfaces :
|
|
pve-netconfig.sh apply-interfaces
|
|
ATTENTION : rupture réseau possible. Prévoir un accès console (iDRAC/IPMI/KVM).
|
|
|
|
4. Lancer un premier contrôle complet :
|
|
pve-netconfig.sh check
|
|
pve-netconfig.sh status
|
|
|
|
5. Démarrer les services :
|
|
systemctl start pve-netconfig.timer
|
|
systemctl start pve-netconfig-watch.service
|
|
|
|
6. Redémarrer pour valider le comportement au boot :
|
|
reboot
|
|
===============================================================================
|
|
EOF |