Compare commits

...

25 Commits

Author SHA1 Message Date
Luis Gerardo Romero Garcia b8449bf0a7 refs #347 adds dependencies to ogboot installer for ipxe-study branch 2024-05-13 11:03:46 +02:00
Luis Gerardo Romero Garcia 7fa8a60421 refs #273 adds a function to changes kea parameters to use ipxe scripts and delete some comments 2024-05-10 09:24:40 +02:00
Luis Gerardo Romero Garcia 17286940e4 refs #273 adds SERVER IP variable to the template 2024-04-30 13:34:08 +02:00
Luis Gerardo Romero Garcia 766c113fbb refs #273 adds mac_script template 2024-04-30 12:41:18 +02:00
Luis Gerardo Romero Garcia f1b1fd7713 refs #273 converts lowecase MAC filename 2024-04-30 12:20:01 +02:00
Luis Gerardo Romero Garcia a5ac3cb637 refs #273 changes CLIENTS to a array of commands 2024-04-30 10:37:44 +02:00
Luis Gerardo Romero Garcia 4043928bed refs #273 changes array clients declaration to associative array 2024-04-30 08:45:57 +02:00
Luis Gerardo Romero Garcia c478f10d57 refs #273 adds clients array to ogboot installer and adds some parameters to mac script template 2024-04-30 08:18:31 +02:00
Luis Gerardo Romero Garcia 64ff35368a refs #310 fix mac for array declaration 2024-04-25 11:44:57 +02:00
Luis Gerardo Romero Garcia 03a9c7564a refs #310 test another mac argument 2024-04-25 10:35:16 +02:00
Luis Gerardo Romero Garcia b219ed748b Changes to lower mac adresss to the name script 2024-04-25 09:44:33 +02:00
Luis Gerardo Romero Garcia 12a64d05b4 Removes old dhcp_boot file and add tftp to template 2024-04-25 08:38:06 +02:00
Luis Gerardo Romero Garcia cd281ef342 refs #310 changes http to tftp connection 2024-04-25 08:13:03 +02:00
Luis Gerardo Romero Garcia 6d3a187d78 refs #310 missing opt directory 2024-04-25 07:45:38 +02:00
Luis Gerardo Romero Garcia 923000c42e refs #310 changes directory destiny 2024-04-25 07:14:26 +02:00
Luis Gerardo Romero Garcia 336ce1cf54 refs #273 #329 #310 fix call directory when creates new script ipxe 2024-04-24 14:33:36 +02:00
Luis Gerardo Romero Garcia 358b5c8d35 refs #273 #329 #310 removes a missing function 2024-04-24 14:10:39 +02:00
Luis Gerardo Romero Garcia 76b435c6a3 refs #273 #329 #310 adds a pwd command to know where dir is executing 2024-04-24 12:42:00 +02:00
Luis Gerardo Romero Garcia 1d3267fbb9 refs #273 #329 #310 changes order execution of ipxe script generation and nfs mount 2024-04-24 12:40:49 +02:00
Luis Gerardo Romero Garcia bd16356183 refs #273 #329 #310 adds templates for ipxe scripts and mac script generation 2024-04-24 10:55:27 +02:00
Luis Gerardo Romero Garcia 1d4f293da4 refs #329 changes cp efi destination 2024-04-23 14:53:46 +02:00
Luis Gerardo Romero Garcia 9c5c07739e refs #329 changes efi build 2024-04-23 14:29:33 +02:00
Luis Gerardo Romero Garcia 3a63a96238 refs #329 adds function to mount NFS and compile ipxe 2024-04-23 13:19:15 +02:00
Luis Gerardo Romero Garcia a7604c00bd refs #199 adds download repo and copy paste to tftpboot opengsys functions 2024-04-11 12:56:26 +02:00
Luis Gerardo Romero Garcia 6c7b05fa38 refs #222 #243 #244 #245 adds ipxe configuration to the boot engine 2024-03-08 12:09:57 +01:00
7 changed files with 301 additions and 2 deletions

14
etc/dhcp_boot.ipxe.tmpl Normal file
View File

@ -0,0 +1,14 @@
#!ipxe
echo Booting by ipxe
echo MAC Address: ${net0/mac}
set macaddress ${net0/mac}
set prefix tftp://SERVERIP/ipxe_scripts
echo Prefix: ${prefix}
set configfile ${prefix}/01-${net0/mac}
echo Config File: ${configfile}
ifopen net0
route
# Intentar cargar la configuración personalizada por MAC
chain ${configfile} ||
# Si no se encuentra la configuración personalizada, cargar la configuración por defecto
chain $prefix/default.ipxe

14
etc/mac_script.ipxe.tmpl Normal file
View File

@ -0,0 +1,14 @@
#!ipxe
set timeout 0
set timeout-style hidden
set ISODIR ogLive
set default 0
set kernelargs ro boot=oginit quiet splash irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true ogdebug=true ogtmpfs=15 oglivedir=${ISODIR} LANG=es_ES.UTF-8 ip=IP_ADDRESS:192.168.2.1:192.168.2.1:255.255.255.0:HOSTNAME:eth0:none group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 oglog=192.168.2.1 ogshare=192.168.2.1 ogprof=false vga=788
echo "OgLive $ISODIR"
ifopen net0
route
kernel tftp://SERVERIP/ogLive/ogvmlinuz ${kernelargs}
initrd tftp://SERVERIP/ogLive/oginitrd.img
boot

View File

@ -1,4 +1,249 @@
#!/bin/bash
echo "Hello world"
touch "Hello world"
BRANCH=$1
CLIENTS=("${@:2}")
if [[ -z $BRANCH ]]; then
BRANCH="main"
fi
GIT_REPO="ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git"
# Obtiene el código fuente del proyecto desde el repositorio de GitHub.
function downloadCode()
{
if [ $# -ne 1 ]; then
echo "${FUNCNAME}(): invalid number of parameters"
exit 1
fi
local url="$1"
echo "${FUNCNAME}(): downloading code from '$url'..."
GIT_SSH_COMMAND="ssh -o StrictHostKeyChecking=accept-new" git archive --remote=$url --format zip --output ogboot.zip --prefix=ogboot/ $BRANCH && unzip ogboot.zip
if [ $? -ne 0 ]; then
echo "${FUNCNAME}(): error getting OpenGnsys code from $url"
return 1
fi
rm -f ogboot.zip
echo "${FUNCNAME}(): code was downloaded"
return 0
}
function checkDependencies() {
echoAndLog "Checking dependencies..."
# Lista de dependencias
local DEPENDENCIES=(
php
php-cli
php-fpm
php-json
php-pdo
php-mysql
php-zip
php-gd
php-mbstring
php-curl
php-xml
php-pear
php-bcmath
composer
unzip
apache2
libapache2-mod-php
subversion
php-ldap
isc-dhcp-server
bittorrent
tftp-hpa
tftpd-hpa
xinetd
build-essential
g++-multilib
wget
curl
graphviz
bittornado
ctorrent
samba
rsync
netpipes
debootstrap
schroot
squashfs-tools
btrfs-tools
procps
arp-scan
realpath
gettext
moreutils
jq
wakeonlan
udpcast
libev-dev
libjansson-dev
libssl-dev
shim-signed
grub-efi-amd64-signed
gawk
libdbi-dev
libdbi1
automake
liblz4-tool
)
# Comprobar cada dependencia
for dep in "${DEPENDENCIES[@]}"; do
if ! dpkg -s "$dep" >/dev/null 2>&1; then
echoAndLog "$dep is not installed. Installing..."
sudo apt-get install -y "$dep"
else
echoAndLog "$dep is already installed."
fi
done
echoAndLog "Dependencies checked."
}
function add_tftpboot_files() {
# Navegar al directorio ogboot
cd ogboot
src_dir="tftpboot"
dest_dir="/opt/opengnsys/tftpboot"
mkdir -p "$dest_dir"
cp -rn "$src_dir/." "$dest_dir/"
if [ $? -eq 0 ]; then
echo "Los archivos se añadieron con éxito."
else
echo "Hubo un error al añadir los archivos."
fi
}
replace_in_config_kea() {
local config_file="/etc/kea/kea-dhcp4.conf"
sed -i 's/"boot-file-name": "shimx64.efi.signed"/"boot-file-name": "ipxe.efi"/g' "$config_file"
sed -i 's/"boot-file-name": "grldr"/"boot-file-name": "undionly.kpxe"/g' "$config_file"
}
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"
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
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."
}
mount_NFS() {
if sudo mount -t nfs ognartefactos.evlt.uma.es:/ /mnt; then
echo "Sistema NFS montado correctamente."
else
echo "Error: No se pudo montar el sistema NFS."
exit 1
fi
ls /mnt/
sudo cp -r /mnt/srv/artefactos/ipxe/ /tmp
cd /tmp/ipxe/src
if sudo make -j 4; then
echo "Directorio /tmp/ipxe/src montado correctamente."
else
echo "Error: No se pudo montar el directorio /tmp/ipxe/src."
exit 1
fi
if sudo make bin/undionly.kpxe EMBED=/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe; then
echo "Fichero de arranque montado correctamente."
else
echo "Error: No se pudo montar el fichero de arranque."
exit 1
fi
sudo cp bin/undionly.kpxe /opt/opengnsys/tftpboot
if sudo make bin-x86_64-efi/ipxe.efi EMBED=/opt/opengnsys/tftpboot/ipxe_scripts/dhcp_boot.ipxe; then
echo "Fichero EFI construido correctamente."
else
echo "Error: No se pudo construir el fichero EFI."
exit 1
fi
sudo cp bin-x86_64-efi/ipxe.efi /opt/opengnsys/tftpboot
}
checkDependencies
downloadCode $GIT_REPO
if [ $? -ne 0 ]; then
echo "Error while getting code from the repository"
exit 1
fi
add_tftpboot_files
if [ $? -ne 0 ]; then
echo "Error añadiendo ficheros"
exit 1
fi
replace_in_config_kea
if [ $? -ne 0 ]; then
echo "Error en la sustitución de valores en el archivo de configuración de KEA DHCP"
exit 1
fi
generate_ipxe_script
if [ $? -ne 0 ]; then
echo "Error en la generación de scripts IPXE"
exit 1
fi
mount_NFS
if [ $? -ne 0 ]; then
echo "Error en el montaje NFS"
exit 1
fi

BIN
tftpboot/ipxe.efi Normal file

Binary file not shown.

View File

@ -0,0 +1,12 @@
#!ipxe
set timeout 0
set timeout-style hidden
set ISODIR ogLive
set default 0
set kernelargs ro boot=oginit quiet splash irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true ogdebug=true ogtmpfs=15 oglivedir=${ISODIR} LANG=es_ES.UTF-8 ip=192.168.2.11:192.168.2.1:192.168.2.1:255.255.255.0:pc11:eth0:none group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 oglog=192.168.2.1 ogshare=192.168.2.1 ogprof=false vga=788
kernel tftp://172.17.8.71/ogLive/ogvmlinuz ${kernelargs}
initrd tftp://172.17.8.71/ogLive/oginitrd.img
boot

View File

@ -0,0 +1,14 @@
#!ipxe
set timeout 0
set timeout-style hidden
set ISODIR ogLive
set default 0
set kernelargs ro boot=oginit quiet splash irqpoll acpi=on og2nd=sqfs ogprotocol=smb ogactiveadmin=true ogdebug=true ogtmpfs=15 oglivedir=${ISODIR} LANG=es_ES.UTF-8 ip=192.168.2.11:192.168.2.1:192.168.2.1:255.255.255.0:pc11:eth0:none group=Aula_virtual ogrepo=192.168.2.1 oglive=192.168.2.1 oglog=192.168.2.1 ogshare=192.168.2.1 ogprof=false vga=788
echo "OgLive $ISODIR"
ifopen net0
route
kernel tftp://SERVERIP/ogLive/ogvmlinuz ${kernelargs}
initrd tftp://SERVERIP/ogLive/oginitrd.img
boot

BIN
tftpboot/undionly.kpxe Normal file

Binary file not shown.