From c478f10d57391bbf16f95f200b501c3e42088ec4 Mon Sep 17 00:00:00 2001 From: lgromero Date: Tue, 30 Apr 2024 08:18:31 +0200 Subject: [PATCH] refs #273 adds clients array to ogboot installer and adds some parameters to mac script template --- installer/ogboot_installer.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/installer/ogboot_installer.sh b/installer/ogboot_installer.sh index 0df9f84..adfdd5c 100644 --- a/installer/ogboot_installer.sh +++ b/installer/ogboot_installer.sh @@ -1,7 +1,7 @@ #!/bin/bash BRANCH=$1 -MAC_ADDRESSES=("${@:2}") +CLIENTS=("${@:2}") if [[ -z $BRANCH ]]; then BRANCH="main" fi @@ -56,8 +56,6 @@ generate_ipxe_script() { echo "Generando script IPXE..." ip_address=$(ifconfig eth0 | awk '/inet / {print $2}') - ls -lha - pwd template="etc/dhcp_boot.ipxe.tmpl" ipxe_output="/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe" @@ -65,22 +63,24 @@ generate_ipxe_script() { # Reemplazar SERVERIP con la dirección IP en la plantilla y guardarla en el archivo de salida sed "s/SERVERIP/$ip_address/g" "$template" > "$ipxe_output" - echo "Archivo creado con éxito en $ipxe_output" - template_default="tftpboot/ipxe_scripts/default.ipxe" default_output="/opt/opengnsys/tftpboot/ipxe_scripts/default.ipxe" sed "s/SERVERIP/$ip_address/g" "$template_default" > "$default_output" echo "Creando ficheros MAC script" - ls -lh - echo ${MAC_ADDRESSES[@]} - for mac_address in "${MAC_ADDRESSES[@]}"; do - mac_address_lower=$(echo "$mac_address" | tr '[:upper:]' '[:lower:]') - filename="01-${mac_address_lower}" - echo "Creando archivo $filename..." - cp /opt/opengnsys/tftpboot/ipxe_scripts/default.ipxe /opt/opengnsys/tftpboot/ipxe_scripts/$filename + for client in "${CLIENTS[@]}"; do + IFS=':' read -r -a campos <<< "$client" + hostname="${campos[0]}" + mac_address="${campos[1]}" + ip_address="${campos[2]}" + filename="01-${mac_address//:/-}" + sed "s/IP_ADDRESS/$ip_address/g; s/HOSTNAME/$hostname/g; s/MAC_ADDRESS/$mac_address/g" /opt/opengnsys/tftpboot/ipxe_scripts/default.ipxe > /opt/opengnsys/tftpboot/ipxe_scripts/$filename + + echo "Archivo $filename creado con los parámetros modificados." done + + echo "Archivos creados correctamente."