Install 3CX V20 sur Debian 12

Installation complète de 3CX Phone System V20 sur un Debian 12 Bookworm vierge (VPS OVH ou bare-metal). Gère les dépendances, le repo officiel, le swap et affiche l'URL du wizard en fin d'install.

3cxvoipdebianpbxvdcom
$ curl scripts.ysavary.fr/3cx-v20 | bash

Install 3CX V20 sur Debian 12 Bookworm

Installation automatisée de 3CX Phone System V20 sur Debian 12 Bookworm (amd64).
Compatible VPS OVH, KVM, VMware, Hyper-V. Nécessite un serveur dédié à 3CX — ne pas co-installer d'autres services web.

Prérequis :

Ce que fait le script :

Option : passer --testing pour utiliser le repo bookworm-testing (RC/updates preview).

Après l'install : récupérer le SetupConfig.xml sur www.3cx.com/install et le charger sur http://IP:5015/.

bash
#!/bin/bash
# =============================================================================
#  install-3cx-debian12.sh — Installation 3CX V20 sur Debian 12 Bookworm
#  Usage : bash install-3cx-debian12.sh [--testing]
#          --testing  → utilise le repo bookworm-testing (updates RC)
# =============================================================================
set -euo pipefail

# ---------- couleurs ----------------------------------------------------------
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
info()  { echo -e "${GREEN}[INFO]${NC}  $*"; }
warn()  { echo -e "${YELLOW}[WARN]${NC}  $*"; }
error() { echo -e "${RED}[ERR]${NC}   $*"; exit 1; }

# ---------- vérifications préliminaires --------------------------------------
[[ $EUID -ne 0 ]] && error "Ce script doit être exécuté en root (ou via sudo)."

OS=$(grep -oP '(?<=^VERSION_CODENAME=).+' /etc/os-release 2>/dev/null || true)
[[ "$OS" != "bookworm" ]] && error "Debian 12 Bookworm requis (détecté : ${OS:-inconnu})."

ARCH=$(dpkg --print-architecture)
[[ "$ARCH" != "amd64" ]] && error "Architecture amd64 requise (détecté : $ARCH)."

# ---------- repo stable ou testing -------------------------------------------
REPO_SUFFIX="bookworm"
[[ "${1:-}" == "--testing" ]] && REPO_SUFFIX="bookworm-testing" && warn "Utilisation du repo TESTING"

# =============================================================================
info "=== Étape 1/6 — Mise à jour du système ==="
# =============================================================================
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
apt-get upgrade -y --with-new-pkgs
apt-get dist-upgrade -y
apt-get autoremove -y

# =============================================================================
info "=== Étape 2/6 — Dépendances ==="
# =============================================================================
apt-get install -y \
    wget \
    curl \
    gnupg2 \
    dphys-swapfile \
    net-tools \
    ca-certificates \
    apt-transport-https \
    lsb-release

# ---------- swap (recommandé par 3CX si RAM < 4 Go) --------------------------
TOTAL_RAM_MB=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo)
if [[ $TOTAL_RAM_MB -lt 4096 ]]; then
    warn "RAM détectée : ${TOTAL_RAM_MB} Mo — activation d'un swap 2 Go"
    sed -i 's/^CONF_SWAPSIZE=.*/CONF_SWAPSIZE=2048/' /etc/dphys-swapfile
    systemctl restart dphys-swapfile
    info "Swap activé : $(swapon --show)"
else
    info "RAM suffisante (${TOTAL_RAM_MB} Mo) — swap laissé tel quel"
fi

# =============================================================================
info "=== Étape 3/6 — Ajout du dépôt 3CX ==="
# =============================================================================
wget -qO- https://repo.3cx.com/key.pub | gpg --dearmor \
    | tee /usr/share/keyrings/3cx-archive-keyring.gpg > /dev/null

echo "deb [arch=amd64 by-hash=yes signed-by=/usr/share/keyrings/3cx-archive-keyring.gpg] \
http://repo.3cx.com/3cx ${REPO_SUFFIX} main" \
    | tee /etc/apt/sources.list.d/3cxpbx.list

apt-get update -y

# =============================================================================
info "=== Étape 4/6 — Installation du paquet 3cxpbx ==="
# =============================================================================
apt-get install -y 3cxpbx

# =============================================================================
info "=== Étape 5/6 — Vérification des services ==="
# =============================================================================
sleep 5

for svc in 3CXCallFlow 3CXMediaServer 3CXPhoneSystem; do
    if systemctl is-active --quiet "$svc" 2>/dev/null; then
        info "  ✓ $svc actif"
    else
        warn "  ✗ $svc non actif (normal avant config initiale)"
    fi
done

# =============================================================================
info "=== Étape 6/6 — Résumé & accès wizard ==="
# =============================================================================
LOCAL_IP=$(hostname -I | awk '{print $1}')

echo ""
echo -e "${GREEN}╔══════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║         Installation 3CX V20 terminée               ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════╝${NC}"
echo ""
echo "  Version installée :"
dpkg -l 3cxpbx 2>/dev/null | awk 'NR==4{print "  → 3cxpbx " $3}' || true
echo ""
echo "  ┌─ Wizard de configuration ──────────────────────────┐"
echo "  │  URL (web)  : http://${LOCAL_IP}:5015/             │"
echo "  │  CLI        : /usr/sbin/3CXWizard                  │"
echo "  └─────────────────────────────────────────────────────┘"
echo ""
echo "  → Récupérez votre fichier SetupConfig.xml sur :"
echo "    https://www.3cx.com/install/"
echo ""
echo "  → Si le wizard ne répond pas :"
echo "    /usr/sbin/3CXWizard --cleanup && /usr/sbin/3CXWizard"
echo ""
echo "  Ports à ouvrir sur le firewall/sg OVH :"
echo "    443/tcp  5001/tcp  5015/tcp   (web admin & wizard)"
echo "    5060/udp 5060/tcp  5061/tcp   (SIP)"
echo "    9000-9499/udp                 (RTP media)"
echo ""
warn "Ne pas installer d'autres services web sur ce serveur."
warn "Les mises à jour système passent uniquement par la console 3CX."
echo ""