refs #273 adds clients array to ogboot installer and adds some parameters to mac script template

pull/1/head
Luis Gerardo Romero Garcia 2024-04-30 08:18:31 +02:00
parent 64ff35368a
commit c478f10d57
1 changed files with 12 additions and 12 deletions

View File

@ -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."