From 251488ab875e016b57d3e9ed9f8e51aa99cc97c9 Mon Sep 17 00:00:00 2001 From: Christophe JEANNEROT Date: Sat, 21 Feb 2026 18:40:27 +0100 Subject: [PATCH] Update unifi-os.sh --- unifi-os.sh | 183 +++++++++++++++++++++++----------------------------- 1 file changed, 82 insertions(+), 101 deletions(-) diff --git a/unifi-os.sh b/unifi-os.sh index daa5360..2fcc092 100644 --- a/unifi-os.sh +++ b/unifi-os.sh @@ -1,37 +1,40 @@ #!/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 -# - Cloud-init: activé par défaut -# - IPv4: DHCP (ipconfig0) -# - Locale/Clavier: FR robuste (kbd + console-setup + loadkeys) -# - Agent Proxmox: qemu-guest-agent -# - Resize disque: qm resize + growpart/resize_rootfs -# - Pas d'auto-start: onboot=0 + ne démarre pas la VM à la fin -# - Console noVNC plus confortable: VGA virtio + GRUB_GFXMODE 1920x1080 +# - Cloud-init: activé + DHCP IPv4 (ipconfig0) +# - root/root fonctionnel (unlock root sur Debian cloud) +# - QEMU guest agent +# - Resize disque (qm resize + growpart/resize_rootfs) +# - Console noVNC plus confortable: VGA virtio + GRUB 1920x1080 + police 8x16 +# - Notes Proxmox + logo AZYLIS +# - Installation UniFi OS Server (podman + slirp4netns + installer + service uosserver) set -euo pipefail # ----------------------------- -# Defaults (tu peux changer ici) +# Defaults (modifiable) # ----------------------------- -HN_DEFAULT="azylis-unifiOS" +HN_DEFAULT="debian13" BRG_DEFAULT="dhcp" CORE_DEFAULT="2" -RAM_DEFAULT="2048" # MiB -DISK_DEFAULT="10G" # ex: 8G, 20G, 50G +RAM_DEFAULT="4096" # MiB (reco 4G mini pour UOS) +DISK_DEFAULT="30G" # ex: 20G, 30G, 50G 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_PASS_DEFAULT="root" # ATTENTION: à adapter en prod +CI_PASS_DEFAULT="root" # ⚠️ à changer en prod # Debian 13 cloud image 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) 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 @@ -78,11 +81,7 @@ need_cmd qm need_cmd curl need_cmd awk need_cmd sed - -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 +need_cmd whiptail # ----------------------------- # UI @@ -95,27 +94,35 @@ RAM_SIZE="$RAM_DEFAULT" DISK_SIZE="$DISK_DEFAULT" START_VM="$START_VM_DEFAULT" -if ! whiptail --backtitle "AZYLIS - Proxmox" --title "Debian 13 VM" --yesno \ - "Ce script va créer une VM Debian 13 (cloud image) avec presets AZYLIS.\n\nContinuer ?" 12 70; then +UOS_URL="$UOS_URL_DEFAULT" + +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é." exit 0 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}" -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}" -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}" -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}" -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}" +# 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 \ "Démarrer la VM automatiquement à la fin ?" 10 70; then START_VM="yes" @@ -133,8 +140,7 @@ MSG_MAX_LEN=0 while read -r line; do TAG="$(awk '{print $1}' <<<"$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} Free: ${FREE:-?}" + ITEM="Type: ${TYPE}" (( ${#ITEM} > MSG_MAX_LEN )) && MSG_MAX_LEN=${#ITEM} STORAGE_MENU+=("$TAG" "$ITEM" "OFF") done < <(pvesm status -content images | awk 'NR>1') @@ -171,7 +177,7 @@ msg_ok "Image téléchargée" # ----------------------------- # Create VM # ----------------------------- -msg_info "Création VM (sans autostart)" +msg_info "Création VM (pas d'autostart)" qm create "$VMID" \ -name "$HN" \ -cores "$CORE_COUNT" \ @@ -184,11 +190,10 @@ qm create "$VMID" \ -tablet 0 \ -localtime 1 >/dev/null -# Better console for noVNC +# noVNC console comfort qm set "$VMID" --vga virtio >/dev/null - -# UEFI (optional, but common) qm set "$VMID" --bios ovmf >/dev/null +qm set "$VMID" --serial0 socket >/dev/null 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_DISK="$(awk -F"'" '/Successfully imported disk as/ {print $2}' <<<"$IMPORT_LOG" | tail -n1)" if [[ -z "${IMPORT_DISK:-}" ]]; then - # Fallback (souvent vrai sur ZFS/LVM) IMPORT_DISK="${STORAGE}:vm-${VMID}-disk-0" fi -# Attach + cloudinit drive qm set "$VMID" \ --scsi0 "${IMPORT_DISK},discard=on,ssd=1" \ --scsi1 "${STORAGE}:cloudinit" \ - --boot order=scsi0 \ - --serial0 socket >/dev/null + --boot order=scsi0 >/dev/null -# Resize disk side (Proxmox) +# Resize disk on Proxmox side msg_info "Resize disque virtuel à ${DISK_SIZE}" qm resize "$VMID" scsi0 "$DISK_SIZE" >/dev/null 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 -# 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 # ----------------------------- -# 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" 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}" -cat > "$USERDATA_FILE" <<'EOF' +cat > "$USERDATA_FILE" < on force un root/root utilisable (LAB) +disable_root: false +ssh_pwauth: true +chpasswd: + expire: false + list: | + root:${CI_PASS_DEFAULT} + packages: - qemu-guest-agent - cloud-guest-utils @@ -250,19 +260,11 @@ packages: - keyboard-configuration - curl - ca-certificates - - apt-transport-https - - gnupg + - podman + - slirp4netns locale: fr_FR.UTF-8 -disable_root: false -ssh_pwauth: true - -chpasswd: - expire: false - list: | - root:root - write_files: # Console keymap FR + police petite - path: /etc/default/console-setup @@ -287,69 +289,40 @@ write_files: GRUB_GFXMODE=1920x1080 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: + # 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 + # Locale FR - 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 - update-locale LANG=fr_FR.UTF-8 || true - # Console keymap immédiat + # Clavier console FR immédiat - loadkeys fr || true - setupcon -k || true - # GRUB update (pour prendre le 1080p) + # GRUB update (pour 1080p) - update-grub || true + # Root unlock (Debian cloud) + s'assurer que le mot de passe est bien actif + - passwd -u root || true + # Agent Proxmox - systemctl enable 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 # Attach snippet to VM (requires 'local' storage with Snippets enabled) qm set "$VMID" --cicustom "user=local:snippets/${VMID}-user-data.yaml" >/dev/null - msg_ok "Cloud-init user-data appliqué" # ----------------------------- @@ -376,7 +349,7 @@ DESCRIPTION=$(
  • IPv4 : DHCP (cloud-init ipconfig0)
  • -Accès +Accès (LAB) + +Accès UniFi OS +
    @@ -413,6 +392,8 @@ fi echo 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} network" \ No newline at end of file +echo " qm cloudinit dump ${VMID} network" +echo " Dans la VM: systemctl status uosserver" +echo " Dashboard: https://:11443" \ No newline at end of file