Update unifi-os.sh

This commit is contained in:
2026-02-21 18:40:27 +01:00
parent 5e7a201486
commit 251488ab87

View File

@@ -1,37 +1,40 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Debian 13 (Trixie) VM - AZYLIS preset # Debian 13 (Trixie) VM - Preset AZYLIS + UniFi OS Server (uosserver)
# - Bridge par défaut: dhcp # - Bridge par défaut: dhcp
# - Cloud-init: activé par défaut # - Cloud-init: activé + DHCP IPv4 (ipconfig0)
# - IPv4: DHCP (ipconfig0) # - root/root fonctionnel (unlock root sur Debian cloud)
# - Locale/Clavier: FR robuste (kbd + console-setup + loadkeys) # - QEMU guest agent
# - Agent Proxmox: qemu-guest-agent # - Resize disque (qm resize + growpart/resize_rootfs)
# - Resize disque: qm resize + growpart/resize_rootfs # - Console noVNC plus confortable: VGA virtio + GRUB 1920x1080 + police 8x16
# - Pas d'auto-start: onboot=0 + ne démarre pas la VM à la fin # - Notes Proxmox + logo AZYLIS
# - Console noVNC plus confortable: VGA virtio + GRUB_GFXMODE 1920x1080 # - Installation UniFi OS Server (podman + slirp4netns + installer + service uosserver)
set -euo pipefail set -euo pipefail
# ----------------------------- # -----------------------------
# Defaults (tu peux changer ici) # Defaults (modifiable)
# ----------------------------- # -----------------------------
HN_DEFAULT="azylis-unifiOS" HN_DEFAULT="debian13"
BRG_DEFAULT="dhcp" BRG_DEFAULT="dhcp"
CORE_DEFAULT="2" CORE_DEFAULT="2"
RAM_DEFAULT="2048" # MiB RAM_DEFAULT="4096" # MiB (reco 4G mini pour UOS)
DISK_DEFAULT="10G" # ex: 8G, 20G, 50G DISK_DEFAULT="30G" # ex: 20G, 30G, 50G
START_VM_DEFAULT="no" # yes/no START_VM_DEFAULT="no" # yes/no
ONBOOT_DEFAULT="1" # 0/1 ONBOOT_DEFAULT="0" # 0/1
# Root access via Proxmox cloud-init fields # Root access (LAB / template)
CI_USER_DEFAULT="root" CI_USER_DEFAULT="root"
CI_PASS_DEFAULT="root" # ATTENTION: à adapter en prod CI_PASS_DEFAULT="root" # ⚠️ à changer en prod
# Debian 13 cloud image # Debian 13 cloud image
DEBIAN13_URL="https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2" DEBIAN13_URL="https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2"
# UniFi OS Server (linux x64) - DEFAULT demandé
UOS_URL_DEFAULT="https://fw-download.ubnt.com/data/unifi-os-server/1856-linux-x64-5.0.6-33f4990f-6c68-4e72-9d9c-477496c22450.6-x64"
# Notes/logo (Proxmox description) # Notes/logo (Proxmox description)
AZYLIS_SITE="https://www.azylis.net" AZYLIS_SITE="https://www.azylis.net"
AZYLIS_LOGO="https://www.azylis.net/favicon.ico" # si tu as une URL PNG/SVG directe du logo, remplace ici AZYLIS_LOGO="https://www.azylis.net/favicon.ico" # remplace par une URL directe PNG/SVG si tu as mieux
# ----------------------------- # -----------------------------
# Helpers # Helpers
@@ -78,11 +81,7 @@ need_cmd qm
need_cmd curl need_cmd curl
need_cmd awk need_cmd awk
need_cmd sed need_cmd sed
need_cmd whiptail
if ! command -v whiptail >/dev/null 2>&1; then
msg_err "whiptail n'est pas installé. Installe-le: apt update && apt install -y whiptail"
exit 1
fi
# ----------------------------- # -----------------------------
# UI # UI
@@ -95,27 +94,35 @@ RAM_SIZE="$RAM_DEFAULT"
DISK_SIZE="$DISK_DEFAULT" DISK_SIZE="$DISK_DEFAULT"
START_VM="$START_VM_DEFAULT" START_VM="$START_VM_DEFAULT"
if ! whiptail --backtitle "AZYLIS - Proxmox" --title "Debian 13 VM" --yesno \ UOS_URL="$UOS_URL_DEFAULT"
"Ce script va créer une VM Debian 13 (cloud image) avec presets AZYLIS.\n\nContinuer ?" 12 70; then
if ! whiptail --backtitle "AZYLIS - Proxmox" --title "Debian 13 VM + UniFi OS Server" --yesno \
"Ce script va créer une VM Debian 13 (cloud image) avec presets AZYLIS + UniFi OS Server (uosserver).\n\nContinuer ?" 12 78; then
msg_err "Annulé." msg_err "Annulé."
exit 0 exit 0
fi fi
HN="$(whiptail --backtitle "AZYLIS - Proxmox" --title "Hostname" --inputbox "Hostname VM:" 8 60 "$HN" 3>&1 1>&2 2>&3 || true)" HN="$(whiptail --backtitle "AZYLIS - Proxmox" --title "Hostname" --inputbox "Hostname VM:" 8 70 "$HN" 3>&1 1>&2 2>&3 || true)"
HN="${HN:-$HN_DEFAULT}" HN="${HN:-$HN_DEFAULT}"
BRG="$(whiptail --backtitle "AZYLIS - Proxmox" --title "Bridge" --inputbox "Bridge Proxmox (nom Linux):" 8 60 "$BRG" 3>&1 1>&2 2>&3 || true)" BRG="$(whiptail --backtitle "AZYLIS - Proxmox" --title "Bridge" --inputbox "Bridge Proxmox (nom Linux):" 8 70 "$BRG" 3>&1 1>&2 2>&3 || true)"
BRG="${BRG:-$BRG_DEFAULT}" BRG="${BRG:-$BRG_DEFAULT}"
CORE_COUNT="$(whiptail --backtitle "AZYLIS - Proxmox" --title "CPU" --inputbox "vCPU:" 8 60 "$CORE_COUNT" 3>&1 1>&2 2>&3 || true)" CORE_COUNT="$(whiptail --backtitle "AZYLIS - Proxmox" --title "CPU" --inputbox "vCPU:" 8 70 "$CORE_COUNT" 3>&1 1>&2 2>&3 || true)"
CORE_COUNT="${CORE_COUNT:-$CORE_DEFAULT}" CORE_COUNT="${CORE_COUNT:-$CORE_DEFAULT}"
RAM_SIZE="$(whiptail --backtitle "AZYLIS - Proxmox" --title "RAM" --inputbox "RAM (MiB):" 8 60 "$RAM_SIZE" 3>&1 1>&2 2>&3 || true)" RAM_SIZE="$(whiptail --backtitle "AZYLIS - Proxmox" --title "RAM" --inputbox "RAM (MiB) (reco 4096+ pour UOS):" 8 70 "$RAM_SIZE" 3>&1 1>&2 2>&3 || true)"
RAM_SIZE="${RAM_SIZE:-$RAM_DEFAULT}" RAM_SIZE="${RAM_SIZE:-$RAM_DEFAULT}"
DISK_SIZE="$(whiptail --backtitle "AZYLIS - Proxmox" --title "Disque" --inputbox "Taille disque (ex: 20G):" 8 60 "$DISK_SIZE" 3>&1 1>&2 2>&3 || true)" DISK_SIZE="$(whiptail --backtitle "AZYLIS - Proxmox" --title "Disque" --inputbox "Taille disque (ex: 30G):" 8 70 "$DISK_SIZE" 3>&1 1>&2 2>&3 || true)"
DISK_SIZE="${DISK_SIZE:-$DISK_DEFAULT}" DISK_SIZE="${DISK_SIZE:-$DISK_DEFAULT}"
# UOS URL - pré-remplie avec ta version 5.0.6
UOS_URL="$(whiptail --backtitle "AZYLIS - Proxmox" --title "UniFi OS Server (uosserver)" \
--inputbox "URL DIRECTE installeur Linux x64 (prérempli).\n\nTu peux la laisser telle quelle, ou coller une autre version depuis UI Releases/Download." 14 110 \
"$UOS_URL" 3>&1 1>&2 2>&3 || true)"
UOS_URL="${UOS_URL:-$UOS_URL_DEFAULT}"
if whiptail --backtitle "AZYLIS - Proxmox" --title "Démarrage" --defaultno --yesno \ if whiptail --backtitle "AZYLIS - Proxmox" --title "Démarrage" --defaultno --yesno \
"Démarrer la VM automatiquement à la fin ?" 10 70; then "Démarrer la VM automatiquement à la fin ?" 10 70; then
START_VM="yes" START_VM="yes"
@@ -133,8 +140,7 @@ MSG_MAX_LEN=0
while read -r line; do while read -r line; do
TAG="$(awk '{print $1}' <<<"$line")" TAG="$(awk '{print $1}' <<<"$line")"
TYPE="$(awk '{print $2}' <<<"$line")" TYPE="$(awk '{print $2}' <<<"$line")"
FREE="$(awk '{print $6}' <<<"$(pvesm status -storage "$TAG" | awk 'NR==2{print}')" 2>/dev/null || true)" ITEM="Type: ${TYPE}"
ITEM="Type: ${TYPE} Free: ${FREE:-?}"
(( ${#ITEM} > MSG_MAX_LEN )) && MSG_MAX_LEN=${#ITEM} (( ${#ITEM} > MSG_MAX_LEN )) && MSG_MAX_LEN=${#ITEM}
STORAGE_MENU+=("$TAG" "$ITEM" "OFF") STORAGE_MENU+=("$TAG" "$ITEM" "OFF")
done < <(pvesm status -content images | awk 'NR>1') done < <(pvesm status -content images | awk 'NR>1')
@@ -171,7 +177,7 @@ msg_ok "Image téléchargée"
# ----------------------------- # -----------------------------
# Create VM # Create VM
# ----------------------------- # -----------------------------
msg_info "Création VM (sans autostart)" msg_info "Création VM (pas d'autostart)"
qm create "$VMID" \ qm create "$VMID" \
-name "$HN" \ -name "$HN" \
-cores "$CORE_COUNT" \ -cores "$CORE_COUNT" \
@@ -184,11 +190,10 @@ qm create "$VMID" \
-tablet 0 \ -tablet 0 \
-localtime 1 >/dev/null -localtime 1 >/dev/null
# Better console for noVNC # noVNC console comfort
qm set "$VMID" --vga virtio >/dev/null qm set "$VMID" --vga virtio >/dev/null
# UEFI (optional, but common)
qm set "$VMID" --bios ovmf >/dev/null qm set "$VMID" --bios ovmf >/dev/null
qm set "$VMID" --serial0 socket >/dev/null
msg_ok "VM créée" msg_ok "VM créée"
@@ -199,30 +204,27 @@ msg_info "Import disque dans ${STORAGE}"
IMPORT_LOG="$(qm importdisk "$VMID" "$FILE" "$STORAGE" 2>&1 || true)" IMPORT_LOG="$(qm importdisk "$VMID" "$FILE" "$STORAGE" 2>&1 || true)"
IMPORT_DISK="$(awk -F"'" '/Successfully imported disk as/ {print $2}' <<<"$IMPORT_LOG" | tail -n1)" IMPORT_DISK="$(awk -F"'" '/Successfully imported disk as/ {print $2}' <<<"$IMPORT_LOG" | tail -n1)"
if [[ -z "${IMPORT_DISK:-}" ]]; then if [[ -z "${IMPORT_DISK:-}" ]]; then
# Fallback (souvent vrai sur ZFS/LVM)
IMPORT_DISK="${STORAGE}:vm-${VMID}-disk-0" IMPORT_DISK="${STORAGE}:vm-${VMID}-disk-0"
fi fi
# Attach + cloudinit drive
qm set "$VMID" \ qm set "$VMID" \
--scsi0 "${IMPORT_DISK},discard=on,ssd=1" \ --scsi0 "${IMPORT_DISK},discard=on,ssd=1" \
--scsi1 "${STORAGE}:cloudinit" \ --scsi1 "${STORAGE}:cloudinit" \
--boot order=scsi0 \ --boot order=scsi0 >/dev/null
--serial0 socket >/dev/null
# Resize disk side (Proxmox) # Resize disk on Proxmox side
msg_info "Resize disque virtuel à ${DISK_SIZE}" msg_info "Resize disque virtuel à ${DISK_SIZE}"
qm resize "$VMID" scsi0 "$DISK_SIZE" >/dev/null qm resize "$VMID" scsi0 "$DISK_SIZE" >/dev/null
msg_ok "Resize Proxmox OK" msg_ok "Resize Proxmox OK"
# Cloud-init network: DHCP IPv4 # Cloud-init network: DHCP IPv4 (affiché dans UI)
qm set "$VMID" --ipconfig0 ip=dhcp >/dev/null qm set "$VMID" --ipconfig0 ip=dhcp >/dev/null
# Cloud-init root user/password (via Proxmox fields) # Cloud-init user/password (Proxmox fields)
qm set "$VMID" --ciuser "$CI_USER_DEFAULT" --cipassword "$CI_PASS_DEFAULT" >/dev/null qm set "$VMID" --ciuser "$CI_USER_DEFAULT" --cipassword "$CI_PASS_DEFAULT" >/dev/null
# ----------------------------- # -----------------------------
# Cloud-init user-data (FR + guest agent + grow root + 1080p gfx) # Cloud-init user-data (FR + guest agent + grow root + 1080p + UOS Server)
# ----------------------------- # -----------------------------
SNIPPET_DIR="/var/lib/vz/snippets" SNIPPET_DIR="/var/lib/vz/snippets"
mkdir -p "$SNIPPET_DIR" mkdir -p "$SNIPPET_DIR"
@@ -230,7 +232,7 @@ USERDATA_FILE="${SNIPPET_DIR}/${VMID}-user-data.yaml"
msg_info "Génération cloud-init user-data: ${USERDATA_FILE}" msg_info "Génération cloud-init user-data: ${USERDATA_FILE}"
cat > "$USERDATA_FILE" <<'EOF' cat > "$USERDATA_FILE" <<EOF
#cloud-config #cloud-config
package_update: true package_update: true
@@ -241,6 +243,14 @@ growpart:
ignore_growroot_disabled: false ignore_growroot_disabled: false
resize_rootfs: true resize_rootfs: true
# Root: Debian cloud lock root par défaut -> on force un root/root utilisable (LAB)
disable_root: false
ssh_pwauth: true
chpasswd:
expire: false
list: |
root:${CI_PASS_DEFAULT}
packages: packages:
- qemu-guest-agent - qemu-guest-agent
- cloud-guest-utils - cloud-guest-utils
@@ -250,19 +260,11 @@ packages:
- keyboard-configuration - keyboard-configuration
- curl - curl
- ca-certificates - ca-certificates
- apt-transport-https - podman
- gnupg - slirp4netns
locale: fr_FR.UTF-8 locale: fr_FR.UTF-8
disable_root: false
ssh_pwauth: true
chpasswd:
expire: false
list: |
root:root
write_files: write_files:
# Console keymap FR + police petite # Console keymap FR + police petite
- path: /etc/default/console-setup - path: /etc/default/console-setup
@@ -287,69 +289,40 @@ write_files:
GRUB_GFXMODE=1920x1080 GRUB_GFXMODE=1920x1080
GRUB_GFXPAYLOAD_LINUX=keep GRUB_GFXPAYLOAD_LINUX=keep
- path: /etc/default/unifi
content: |
UNIFI_JVM_INIT_HEAP_SIZE=1024M
UNIFI_JVM_MAX_HEAP_SIZE=2048M
- path: /usr/local/sbin/install-unifi.sh
permissions: "0755"
content: |
#!/usr/bin/env bash
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y ca-certificates apt-transport-https wget gnupg
# Repo UniFi (source officielle)
echo 'deb [ arch=amd64,arm64 ] https://www.ui.com/downloads/unifi/debian stable ubiquiti' \
> /etc/apt/sources.list.d/100-ubnt-unifi.list
# GPG key (méthode recommandée officielle)
wget -qO /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ui.com/unifi/unifi-repo.gpg
# Certains cas nécessitent d'accepter un changement ReleaseInfo
apt-get update --allow-releaseinfo-change || apt-get update
# (Optionnel mais utile en VM headless) Entropie
apt-get install -y haveged || true
systemctl enable --now haveged || true
# Installation UniFi Network Application
apt-get install -y unifi
systemctl enable --now unifi
runcmd: runcmd:
# Réseau: petite attente (DHCP)
- bash -lc 'for i in {1..30}; do ping -c1 1.1.1.1 >/dev/null 2>&1 && break; sleep 2; done'
- passwd -u root || true # Locale FR
# Locale
- sed -i 's/^# *fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen || true - sed -i 's/^# *fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/' /etc/locale.gen || true
- locale-gen fr_FR.UTF-8 || true - locale-gen fr_FR.UTF-8 || true
- update-locale LANG=fr_FR.UTF-8 || true - update-locale LANG=fr_FR.UTF-8 || true
# Console keymap immédiat # Clavier console FR immédiat
- loadkeys fr || true - loadkeys fr || true
- setupcon -k || true - setupcon -k || true
# GRUB update (pour prendre le 1080p) # GRUB update (pour 1080p)
- update-grub || true - update-grub || true
# Root unlock (Debian cloud) + s'assurer que le mot de passe est bien actif
- passwd -u root || true
# Agent Proxmox # Agent Proxmox
- systemctl enable qemu-guest-agent || true - systemctl enable qemu-guest-agent || true
- systemctl start qemu-guest-agent || true - systemctl start qemu-guest-agent || true
# Install UNIFI
- /usr/local/sbin/install-unifi.sh
# --- UniFi OS Server (uosserver) ---
# Procédure officielle: installer podman+slirp4netns, télécharger l'installeur, chmod +x, exécuter, puis systemctl enable/start uosserver.
- bash -lc 'set -e; mkdir -p /root/uos && cd /root/uos && curl -fL -o uos-installer.bin "${UOS_URL}"'
- bash -lc 'set -e; cd /root/uos && chmod +x uos-installer.bin'
- bash -lc 'set -e; cd /root/uos && ./uos-installer.bin'
- systemctl enable uosserver
- systemctl start uosserver
EOF EOF
# Attach snippet to VM (requires 'local' storage with Snippets enabled) # Attach snippet to VM (requires 'local' storage with Snippets enabled)
qm set "$VMID" --cicustom "user=local:snippets/${VMID}-user-data.yaml" >/dev/null qm set "$VMID" --cicustom "user=local:snippets/${VMID}-user-data.yaml" >/dev/null
msg_ok "Cloud-init user-data appliqué" msg_ok "Cloud-init user-data appliqué"
# ----------------------------- # -----------------------------
@@ -376,7 +349,7 @@ DESCRIPTION=$(
<li><b>IPv4</b> : DHCP (cloud-init ipconfig0)</li> <li><b>IPv4</b> : DHCP (cloud-init ipconfig0)</li>
</ul> </ul>
<b>Accès</b> <b>Accès (LAB)</b>
<ul> <ul>
<li><b>Utilisateur</b> : ${CI_USER_DEFAULT}</li> <li><b>Utilisateur</b> : ${CI_USER_DEFAULT}</li>
<li><b>Mot de passe</b> : ${CI_PASS_DEFAULT}</li> <li><b>Mot de passe</b> : ${CI_PASS_DEFAULT}</li>
@@ -388,7 +361,13 @@ DESCRIPTION=$(
<li>Locale/Clavier: FR</li> <li>Locale/Clavier: FR</li>
<li>Console: GRUB 1920x1080 + police 8x16</li> <li>Console: GRUB 1920x1080 + police 8x16</li>
<li>Agent Proxmox: qemu-guest-agent</li> <li>Agent Proxmox: qemu-guest-agent</li>
<li>Auto-start Proxmox: onboot=${ONBOOT_DEFAULT}</li> <li>UniFi OS Server: install auto (uosserver) - 5.0.6</li>
</ul>
<b>Accès UniFi OS</b>
<ul>
<li>URL: <code>https://&lt;IP_VM&gt;:11443</code></li>
<li>Service: <code>systemctl status uosserver</code></li>
</ul> </ul>
<hr> <hr>
@@ -413,6 +392,8 @@ fi
echo echo
echo "Commandes utiles :" echo "Commandes utiles :"
echo " qm config ${VMID} | egrep 'name:|net0|ipconfig0|ciuser|cipassword|vga|scsi0|scsi1'" echo " qm config ${VMID} | egrep 'name:|net0|ipconfig0|ciuser|cipassword|vga|scsi0|scsi1|serial0'"
echo " qm cloudinit dump ${VMID} user" echo " qm cloudinit dump ${VMID} user"
echo " qm cloudinit dump ${VMID} network" echo " qm cloudinit dump ${VMID} network"
echo " Dans la VM: systemctl status uosserver"
echo " Dashboard: https://<IP_VM>:11443"