refs #273 Adds CLIENTS parameters if is declared and ipxe script generation
parent
0e22aa0d04
commit
54e13e45d9
|
|
@ -23,6 +23,10 @@ function globalSetup() {
|
||||||
|
|
||||||
BRANCH=${1:-"main"}
|
BRANCH=${1:-"main"}
|
||||||
|
|
||||||
|
if (( $# > 1 )); then
|
||||||
|
CLIENTS=("${@:2}")
|
||||||
|
fi
|
||||||
|
|
||||||
GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
|
||||||
|
|
||||||
# Directorios de instalación y destino de OpenGnsys.
|
# Directorios de instalación y destino de OpenGnsys.
|
||||||
|
|
@ -94,7 +98,44 @@ local DEPENDENCIES=(
|
||||||
tftpd-hpa
|
tftpd-hpa
|
||||||
xinetd
|
xinetd
|
||||||
build-essential
|
build-essential
|
||||||
g++-multilib
|
g++-multilibgenerate_ipxe_script() {
|
||||||
|
|
||||||
|
echo "Generando script IPXE..."
|
||||||
|
ip_address_server=$(ifconfig eth0 | awk '/inet / {print $2}')
|
||||||
|
template="etc/dhcp_boot.ipxe.tmpl"
|
||||||
|
|
||||||
|
ipxe_output="/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
||||||
|
|
||||||
|
# Reemplazar SERVERIP con la dirección IP en la plantilla y guardarla en el archivo de salida
|
||||||
|
sed "s/SERVERIP/$ip_address_server/g" "$template" > "$ipxe_output"
|
||||||
|
|
||||||
|
template_default="tftpboot/ipxe_scripts/default.ipxe"
|
||||||
|
|
||||||
|
default_output="/opt/opengnsys/tftpboot/ipxe_scripts/default.ipxe"
|
||||||
|
|
||||||
|
mac_script_template="etc/mac_script.ipxe.tmpl"
|
||||||
|
|
||||||
|
sed "s/SERVERIP/$ip_address_server/g" "$template_default" > "$default_output"
|
||||||
|
echo "Creando ficheros MAC script"
|
||||||
|
for client_declaration in "${CLIENTS[@]}"; do
|
||||||
|
# Evaluar la cadena para reconstruir el array asociativo del cliente
|
||||||
|
eval "$client_declaration"
|
||||||
|
|
||||||
|
hostname="${CLIENT[hostname]}"
|
||||||
|
mac_address="${CLIENT[mac_address]}"
|
||||||
|
ip_address="${CLIENT[ip_address]}"
|
||||||
|
mac_address_lower=$(echo "$mac_address" | tr '[:upper:]' '[:lower:]')
|
||||||
|
filename="01-${mac_address_lower}"
|
||||||
|
sed "s/SERVERIP/$ip_address_server/g; s/IP_ADDRESS/$ip_address/g; s/HOSTNAME/$hostname/g; s/MAC_ADDRESS/$mac_address/g" $mac_script_template > "/opt/opengnsys/tftpboot/ipxe_scripts/$filename"
|
||||||
|
echo "Archivo $filename creado con los parámetros modificados."
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
echo "Archivos creados correctamente."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
wget
|
wget
|
||||||
curl
|
curl
|
||||||
graphviz
|
graphviz
|
||||||
|
|
@ -397,6 +438,45 @@ function copyServerFiles() {
|
||||||
popd || return
|
popd || return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generate_ipxe_script() {
|
||||||
|
|
||||||
|
echo "Generando script IPXE..."
|
||||||
|
ip_address_server=$(ifconfig eth0 | awk '/inet / {print $2}')
|
||||||
|
template="etc/dhcp_boot.ipxe.tmpl"
|
||||||
|
|
||||||
|
ipxe_output="/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe"
|
||||||
|
|
||||||
|
# Reemplazar SERVERIP con la dirección IP en la plantilla y guardarla en el archivo de salida
|
||||||
|
sed "s/SERVERIP/$ip_address_server/g" "$template" > "$ipxe_output"
|
||||||
|
|
||||||
|
template_default="tftpboot/ipxe_scripts/default.ipxe"
|
||||||
|
|
||||||
|
default_output="/opt/opengnsys/tftpboot/ipxe_scripts/default.ipxe"
|
||||||
|
|
||||||
|
mac_script_template="etc/mac_script.ipxe.tmpl"
|
||||||
|
|
||||||
|
sed "s/SERVERIP/$ip_address_server/g" "$template_default" > "$default_output"
|
||||||
|
echo "Creando ficheros MAC script"
|
||||||
|
for client_declaration in "${CLIENTS[@]}"; do
|
||||||
|
# Evaluar la cadena para reconstruir el array asociativo del cliente
|
||||||
|
eval "$client_declaration"
|
||||||
|
|
||||||
|
hostname="${CLIENT[hostname]}"
|
||||||
|
mac_address="${CLIENT[mac_address]}"
|
||||||
|
ip_address="${CLIENT[ip_address]}"
|
||||||
|
mac_address_lower=$(echo "$mac_address" | tr '[:upper:]' '[:lower:]')
|
||||||
|
filename="01-${mac_address_lower}"
|
||||||
|
sed "s/SERVERIP/$ip_address_server/g; s/IP_ADDRESS/$ip_address/g; s/HOSTNAME/$hostname/g; s/MAC_ADDRESS/$mac_address/g" $mac_script_template > "/opt/opengnsys/tftpboot/ipxe_scripts/$filename"
|
||||||
|
echo "Archivo $filename creado con los parámetros modificados."
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
echo "Archivos creados correctamente."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function tftpConfigure()
|
function tftpConfigure()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue