#!/bin/bash # --- VARIABLES --- USB_PATH="/mnt/usb-pxe" # Modifiez ceci selon le point de montage de votre clé USB PXE_DIR="$USB_PATH/pxe-server" echo "🚀 Début de l'installation du serveur PXE sur $PXE_DIR..." # 1. Création de l'arborescence mkdir -p $PXE_DIR/{dnsmasq,tftpboot,www/ubuntu-admin,www/ubuntu-ro,www/rpi-ro,keycloak/data} # 2. Téléchargement des firmwares iPXE et UEFI echo "📥 Téléchargement des binaires iPXE..." wget -q https://boot.ipxe.org/undionly.kpxe -O $PXE_DIR/tftpboot/undionly.kpxe wget -q https://boot.ipxe.org/ipxe.efi -O $PXE_DIR/tftpboot/ipxe.efi wget -q https://boot.ipxe.org/arm64-efi/ipxe.efi -O $PXE_DIR/tftpboot/ipxe-arm64.efi echo "📥 Téléchargement du firmware UEFI pour RPi 4..." # Récupération de la dernière release (nécessite unzip) wget -qO rpi4-uefi.zip https://github.com/pftf/RPi4/releases/latest/download/RPi4_UEFI_Firmware.zip unzip -q -o rpi4-uefi.zip -d $PXE_DIR/tftpboot/ rm rpi4-uefi.zip # 3. Création du docker-compose.yml cat < $PXE_DIR/docker-compose.yml services: dnsmasq: image: strm/dnsmasq container_name: pxe-dnsmasq network_mode: "host" cap_add: - NET_ADMIN volumes: - ./dnsmasq/dnsmasq.conf:/etc/dnsmasq.conf:ro - ./tftpboot:/var/lib/tftpboot:ro restart: unless-stopped nginx: image: nginx:alpine container_name: pxe-http network_mode: "host" volumes: - ./www:/usr/share/nginx/html:ro restart: unless-stopped EOF # 4. Création de la configuration Dnsmasq cat < $PXE_DIR/dnsmasq/dnsmasq.conf port=0 log-dhcp dhcp-range=set:net_eth0,10.0.0.50,10.0.0.150,255.255.255.0,2h dhcp-range=set:net_eth1,10.0.1.50,10.0.1.150,255.255.255.0,2h enable-tftp tftp-root=/var/lib/tftpboot dhcp-match=set:ipxe,175 dhcp-match=set:efi-x86_64,option:client-arch,7 dhcp-match=set:efi-x86_64,option:client-arch,9 dhcp-match=set:efi-arm64,option:client-arch,11 dhcp-boot=tag:!ipxe,tag:efi-x86_64,ipxe.efi dhcp-boot=tag:!ipxe,tag:!efi-x86_64,tag:!efi-arm64,undionly.kpxe dhcp-boot=tag:!ipxe,tag:efi-arm64,ipxe-arm64.efi dhcp-boot=tag:ipxe,tag:net_eth0,http://10.0.0.1/boot-eth0.ipxe dhcp-boot=tag:ipxe,tag:net_eth1,http://10.0.1.1/boot-eth1.ipxe EOF # 5. Création des scripts iPXE cat < $PXE_DIR/www/boot-eth0.ipxe #!ipxe echo Boot Ubuntu x86_64 Admin... kernel http://10.0.0.1/ubuntu-admin/vmlinuz ip=dhcp url=http://10.0.0.1/ubuntu-admin/ubuntu.iso autologin initrd http://10.0.0.1/ubuntu-admin/initrd boot EOF cat < $PXE_DIR/www/boot-eth1.ipxe #!ipxe echo Boot Ubuntu Lecture Seule (Custom)... kernel http://10.0.1.1/ubuntu-ro/vmlinuz ip=dhcp url=http://10.0.1.1/ubuntu-ro/ubuntu.iso toram initrd http://10.0.1.1/ubuntu-ro/initrd boot EOF echo "✅ Arborescence et configurations terminées !" echo "👉 Placez vos ISO customisées et fichiers vmlinuz/initrd dans $PXE_DIR/www/" EOF