diff --git a/pxe-boot/.gitignore b/pxe-boot/.gitignore new file mode 100644 index 0000000..6d19617 --- /dev/null +++ b/pxe-boot/.gitignore @@ -0,0 +1,2 @@ +config.yaml +auth.json diff --git a/pxe-boot/README.md b/pxe-boot/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pxe-boot/config/dnsmasq/dnsmasq.conf b/pxe-boot/config/dnsmasq/dnsmasq.conf new file mode 100644 index 0000000..2f6055f --- /dev/null +++ b/pxe-boot/config/dnsmasq/dnsmasq.conf @@ -0,0 +1,21 @@ +# Bind on enp1s0 +bind-dynamic +interface=enp1s0 + +# Disable DHCP +no-dhcpv4-interface=enp1s0 +no-dhcpv6-interface=enp1s0 +dhcp-alternate-port + +# Disable DNS +port=0 + +# Enable TFTP +enable-tftp=enp1s0 +tftp-root=/var/lib/tftpboot +tftp-secure +tftp-lowercase + +# Just to be safe... +log-dhcp +log-queries \ No newline at end of file diff --git a/pxe-boot/config/nginx/nginx.conf b/pxe-boot/config/nginx/nginx.conf new file mode 100644 index 0000000..0c8082f --- /dev/null +++ b/pxe-boot/config/nginx/nginx.conf @@ -0,0 +1,34 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log notice; +pid /run/nginx.pid; + +# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + keepalive_timeout 65; + types_hash_max_size 4096; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + server { + listen 127.0.0.1:8080; + server_name _; + root /var/www; + access_log /var/log/nginx/access.log; + } +} diff --git a/pxe-boot/install.sh b/pxe-boot/install.sh new file mode 100755 index 0000000..1bf26f1 --- /dev/null +++ b/pxe-boot/install.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +set -Eeuo pipefail + +if [[ "$UID" -ne 0 ]]; then + echo "This command must be run as root!" + exit 1 +fi + +# Get the directory of this script +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +# This function iterates over all files contained in the directory passed as the first argument +# and install them to the directory passed as the second argument, using the install command. +# It preserves the directory structure of the source directory. +# The remaining arguments are passed to the install command. +function install_files() { + local src_dir="$1" + local dest_dir="$2" + shift 2 + + find "$src_dir" -type f | while read -r file; do + local relative_path="${file#$src_dir/}" + local dest_path="$dest_dir/$relative_path" + + install "$@" "$file" "$dest_path" + done +} + +# Same but for directories +function install_directories() { + local src_dir="$1" + local dest_dir="$2" + shift 2 + + find "$src_dir" -type d | while read -r dir; do + local relative_path="${dir#$src_dir}" + relative_path="${relative_path#/}" # Remove leading slash if present + local dest_path="$dest_dir/$relative_path" + + install "$@" -d "$dest_path" + done +} + +# This function templates a kickstart file by replacing placeholders with actual values. +# The templates are located in the www/ks directory. +# The output files are written to /var/www/ks. +# The placeholders are in the format expected by envsubst. +# For each template file, seven versions are created: base + scenario{1,2,3,4,5,6}. +# The output files are named as /var/www/ks/