Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OUTPUT=PXE: Support for downloading kernel and initrd by http #3100

Merged
merged 14 commits into from Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 44 additions & 5 deletions usr/share/rear/conf/default.conf
Expand Up @@ -1329,22 +1329,61 @@ PXE_CONFIG_URL=
PXE_CONFIG_PREFIX=rear-
#
# TFPT IP server. needed to create grub menu when PXE_CONFIG_GRUB_STYLE=y
# If not set, we gonna try to get TFTP IP from PXE_TFTP_URL
# If not set, we gonna try to get TFTP IP from PXE_TFTP_UPLOAD_URL
PXE_TFTP_IP=
#
# where should we put the TFTP files ? (legacy way)
PXE_TFTP_PATH=/var/lib/rear/output
# where should we put the TFTP files ? (URL style)
PXE_TFTP_URL=
# PXE_TFTP_UPLOAD_URL must be set and point to your
# tftp server drectory using nfs or any other mountable scheme.
#PXE_TFTP_URL: deprecated as of 2.8. Use PXE_TFTP_UPLOAD_URL
PXE_TFTP_UPLOAD_URL=
#
# prefix for PXE files, e.g. the hostname
PXE_TFTP_PREFIX=$HOSTNAME.
#
# Optional support for downloading kernel and initrd by HTTP, thus making
# downloads considerably faster.
# First, you have to use lpxelinux.0 instead of pxelinux.0, the former supports
# HTTP downloads. It's compatible, just replace pxelinux.0 in your TFTP
# directory or set bootfile-name/filename to lpxelinux.0 in your DHCP server.
# PXE_CONFIG_GRUB_STYLE must NOT be set to yes.
#
# PXE_CONFIG_URL must be set and point to your pxelinux.cfg directory using nfs or any other mountable scheme.
#
# PXE_TFTP_UPLOAD_URL must still be set as it provides all files still being downloaded by TFTP.
#
# PXE_HTTP_UPLOAD_URL must be set and point to your
# web server "DocumentRoot" (httpd) or "root" (nginx) directory
# using nfs or any other mountable scheme.
#
# PXE_HTTP_DOWNLOAD_URL must be set and point to your web server root directory
# using http.
#
# PXE_HTTP_DOWNLOAD_URL must *logically* point to the same directory
# as PXE_HTTP_UPLOAD_URL!
#
# You may set OUTPUT_PREFIX_PXE, but keep in mind it will be added to
# PXE_TFTP_UPLOAD_URL, PXE_HTTP_UPLOAD_URL and PXE_HTTP_DOWNLOAD_URL.
#
# Example:
# OUTPUT=PXE
# PXE_CONFIG_GRUB_STYLE=
# OUTPUT_PREFIX_PXE=rear_kernels/$HOSTNAME
# PXE_CONFIG_URL=nfs://tftp-server/var/lib/tftpboot/pxelinux.cfg
# PXE_TFTP_UPLOAD_URL=nfs://tftp-server/var/lib/tftpboot
# PXE_HTTP_UPLOAD_URL=nfs://web-server/var/www/html
# PXE_HTTP_DOWNLOAD_URL=http://web-server
PXE_HTTP_UPLOAD_URL=
robertdahlem marked this conversation as resolved.
Show resolved Hide resolved
#
# Optional HTTP download source for PXE (URL style)
# for example PXE_HTTP_URL="http://pxe-over-http-srv:7777"
# for example PXE_HTTP_DOWNLOAD_URL="http://web-server".
# If set an additional PXE boot option 'rear-http' in the pxeconfig is provided
# which uses the specified URL as base path for kernel and initrd.
PXE_HTTP_URL=
# Optionally you can add a port: PXE_HTTP_DOWNLOAD_URL="http://web-server:8080".
#PXE_HTTP_URL: deprecated as of 2.8. Use PXE_HTTP_DOWNLOAD_URL
PXE_HTTP_DOWNLOAD_URL=
#
# Create pxelinux config symlinks for MAC addresses or for IP addresses ? [MAC|IP|'']
PXE_CREATE_LINKS=MAC
Expand Down Expand Up @@ -2311,7 +2350,7 @@ TSM_DSMC_RESTORE_OPTIONS=( )
#
# Tell if the result from mkbackup/mkrescue (Rescue image: ISO image, PXE, kernel and initrd)
# should be saved via TSM.
# You can disable these saving when the result is saved on an different way (ISO_URL, PXE_TFTP_URL....)
# You can disable these saving when the result is saved on an different way (ISO_URL, PXE_TFTP_UPLOAD_URL....)
# (y/n) default to y
TSM_RESULT_SAVE=y
#
Expand Down
Expand Up @@ -13,7 +13,7 @@ OUTPUT_PREFIX_PXE=$HOSTNAME
BACKUP=NETFS
BACKUP_URL=nfs://server/export/nfs/tftpboot

PXE_TFTP_URL=nfs://server/export/nfs/tftpboot
PXE_TFTP_UPLOAD_URL=nfs://server/export/nfs/tftpboot
PXE_CONFIG_URL=nfs://server/export/nfs/tftpboot/pxelinux.cfg
# unattended means auto_recover with no questions asked (expert mode)
# We tend to use this for our automated test environment and we
Expand Down
Expand Up @@ -31,7 +31,7 @@ PXE_TFTP_IP=XX.YY.ZZ.AA
PXE_CONFIG_URL="nfs://$PXE_TFTP_IP/var/lib/tftpboot/boot/grub2/powerpc-ieee1275"
PXE_CREATE_LINKS=IP
PXE_REMOVE_OLD_LINKS=y
PXE_TFTP_URL="nfs://$PXE_TFTP_IP/var/lib/tftpboot"
PXE_TFTP_UPLOAD_URL="nfs://$PXE_TFTP_IP/var/lib/tftpboot"

# Other generic settings:
USE_STATIC_NETWORKING=y
Expand Down
18 changes: 9 additions & 9 deletions usr/share/rear/lib/bootloader-functions.sh
Expand Up @@ -796,7 +796,7 @@ function make_pxelinux_config {
echo "say ----------------------------------------------------------"

# start with optional rear http entry if specified
if [[ ! -z $PXE_HTTP_URL ]] ; then
if [[ "$PXE_HTTP_DOWNLOAD_URL" ]] ; then
case "$PXE_RECOVER_MODE" in
"automatic")
echo "say rear-automatic-http - Recover $HOSTNAME (HTTP) with auto-recover kernel option"
Expand All @@ -818,8 +818,8 @@ function make_pxelinux_config {
echo "Rescue image kernel $KERNEL_VERSION ${IPADDR:+on $IPADDR} $(date -R)"
echo "${BACKUP:+BACKUP=$BACKUP} ${OUTPUT:+OUTPUT=$OUTPUT} ${BACKUP_URL:+BACKUP_URL=$BACKUP_URL}"
echo "ENDTEXT"
echo " kernel $PXE_HTTP_URL/$PXE_KERNEL"
echo " append initrd=$PXE_HTTP_URL/$PXE_INITRD root=/dev/ram0 vga=normal rw $KERNEL_CMDLINE $PXE_RECOVER_MODE"
echo " kernel $PXE_HTTP_DOWNLOAD_URL/$PXE_KERNEL"
echo " append initrd=$PXE_HTTP_DOWNLOAD_URL/$PXE_INITRD root=/dev/ram0 vga=normal rw $KERNEL_CMDLINE $PXE_RECOVER_MODE"
echo "say ----------------------------------------------------------"
fi

Expand Down Expand Up @@ -895,15 +895,15 @@ function make_pxelinux_config {
function make_pxelinux_config_grub {
net_default_server_opt=""

# Be sure that TFTP Server IP is set with TFTP_SERVER_IP Variable.
# else set it based on PXE_TFTP_UR variable.
# Be sure that TFTP Server IP is set with PXE_TFTP_IP Variable.
# else set it based on PXE_TFTP_UPLOAD_URL variable.
if [[ -z $PXE_TFTP_IP ]] ; then
if [[ -z $PXE_TFTP_URL ]] ; then
LogPrintError "Can't find TFTP IP information. Variable TFTP_SERVER_IP or PXE_TFTP_URL with clear IP address must be set."
if [[ -z "$PXE_TFTP_UPLOAD_URL" ]] ; then
LogPrintError "Can't find TFTP IP information. Variable PXE_TFTP_IP or PXE_TFTP_UPLOAD_URL with clear IP address must be set."
return
else
# Get IP address from PXE_TFTP_URL (ex:http://xx.yy.zz.aa:port/foo/bar)
PXE_TFTP_IP=$(echo "$PXE_TFTP_URL" | awk -F'[/:]' '{ print $4 }')
# Get IP address from PXE_TFTP_UPLOAD_URL (ex:http://xx.yy.zz.aa:port/foo/bar)
PXE_TFTP_IP=$(echo "$PXE_TFTP_UPLOAD_URL" | awk -F'[/:]' '{ print $4 }')

# If PXE_TFTP_IP is not an IP, it could be a FQDM that must be resolved to IP.
# is_ip() function is defined in network-function.sh
Expand Down
44 changes: 20 additions & 24 deletions usr/share/rear/output/PXE/default/800_copy_to_tftp.sh
Expand Up @@ -5,46 +5,42 @@
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.

if [[ ! -z "$PXE_TFTP_URL" ]] ; then
# E.g. PXE_TFTP_URL=nfs://server/export/nfs/tftpboot
local scheme=$( url_scheme $PXE_TFTP_URL )
local pxe_tftp_local_path
if [[ "$PXE_TFTP_UPLOAD_URL" ]] ; then
# E.g. PXE_TFTP_UPLOAD_URL=nfs://server/export/nfs/tftpboot
local scheme=$( url_scheme "$PXE_TFTP_UPLOAD_URL" )

# We need filesystem access to the destination (schemes like ftp:// are not supported)
if ! scheme_supports_filesystem $scheme ; then
Error "Scheme $scheme for PXE output not supported, use a scheme that supports mounting (like nfs: )"
fi
scheme_supports_filesystem $scheme || Error "Scheme $scheme for PXE output not supported, use a scheme that supports mounting (like nfs: )"

mount_url $PXE_TFTP_URL $BUILD_DIR/tftpbootfs $BACKUP_OPTIONS
mount_url "$PXE_TFTP_UPLOAD_URL" $BUILD_DIR/tftpbootfs $BACKUP_OPTIONS
# However, we copy under $OUTPUT_PREFIX_PXE directory (usually HOSTNAME) to have different clients on one pxe server
PXE_TFTP_LOCAL_PATH=$BUILD_DIR/tftpbootfs
pxe_tftp_local_path=$BUILD_DIR/tftpbootfs
# mode must readable for others for pxe and we copy under the client HOSTNAME (=OUTPUT_PREFIX_PXE)
mkdir -m 755 -p $v "$BUILD_DIR/tftpbootfs/$OUTPUT_PREFIX_PXE" >&2
StopIfError "Could not mkdir '$BUILD_DIR/tftpbootfs/$OUTPUT_PREFIX_PXE'"
mkdir $v -m 755 -p "$BUILD_DIR/tftpbootfs/$OUTPUT_PREFIX_PXE" || Error "Could not mkdir '$BUILD_DIR/tftpbootfs/$OUTPUT_PREFIX_PXE'"
PXE_KERNEL="$OUTPUT_PREFIX_PXE/${PXE_TFTP_PREFIX}kernel"
PXE_INITRD="$OUTPUT_PREFIX_PXE/$PXE_TFTP_PREFIX$REAR_INITRD_FILENAME"
PXE_MESSAGE="$OUTPUT_PREFIX_PXE/${PXE_TFTP_PREFIX}message"
else
PXE_TFTP_LOCAL_PATH="$PXE_TFTP_PATH"
pxe_tftp_local_path="$PXE_TFTP_PATH"
# By default PXE_TFTP_PREFIX=$HOSTNAME. (see conf/default.conf)
PXE_KERNEL="${PXE_TFTP_PREFIX}kernel"
PXE_INITRD="$PXE_TFTP_PREFIX$REAR_INITRD_FILENAME"
PXE_MESSAGE="${PXE_TFTP_PREFIX}message"
[[ ! -d "$PXE_TFTP_LOCAL_PATH" ]] && mkdir $v -m 750 "$PXE_TFTP_LOCAL_PATH" >&2
[[ -d "$pxe_tftp_local_path" ]] || mkdir $v -m 750 "$pxe_tftp_local_path" >&2
fi

# Follow symbolic links to ensure the real content gets copied
# but do not preserve mode,ownership,timestamps (i.e. no -p option) because that may fail (on sshfs) like
# "cp: failed to preserve ownership for '/tmp/rear-efi.XXXXXXXXXX/EFI/BOOT/kernel': Operation not permitted"
cp -L $v "$KERNEL_FILE" "$PXE_TFTP_LOCAL_PATH/$PXE_KERNEL" || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"
cp -L $v "$TMP_DIR/$REAR_INITRD_FILENAME" "$PXE_TFTP_LOCAL_PATH/$PXE_INITRD" || Error "Failed to copy initrd '$REAR_INITRD_FILENAME'"
echo "$VERSION_INFO" >"$PXE_TFTP_LOCAL_PATH/$PXE_MESSAGE"
cp -L $v "$KERNEL_FILE" "$pxe_tftp_local_path/$PXE_KERNEL" || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"
cp -L $v "$TMP_DIR/$REAR_INITRD_FILENAME" "$pxe_tftp_local_path/$PXE_INITRD" || Error "Failed to copy initrd '$REAR_INITRD_FILENAME'"
echo "$VERSION_INFO" >"$pxe_tftp_local_path/$PXE_MESSAGE"
# files must be readable for others for PXE
# files should be writebale by owner or overwriting it on later runs will fail
chmod 644 "$PXE_TFTP_LOCAL_PATH/$PXE_KERNEL"
chmod 644 "$PXE_TFTP_LOCAL_PATH/$PXE_INITRD"
chmod 644 "$PXE_TFTP_LOCAL_PATH/$PXE_MESSAGE"
chmod 644 "$pxe_tftp_local_path/$PXE_KERNEL" "$pxe_tftp_local_path/$PXE_INITRD" "$pxe_tftp_local_path/$PXE_MESSAGE"

if [[ ! -z "$PXE_TFTP_URL" ]] && [[ "$PXE_RECOVER_MODE" = "unattended" ]] ; then
if [[ "$PXE_TFTP_UPLOAD_URL" ]] && [[ "$PXE_RECOVER_MODE" = "unattended" ]] ; then
# If we have chosen for "unattended" recover mode then we also copy the
# required pxe modules (and we assume that the PXE server run the same OS)
# copy pxelinux.0 and friends
Expand All @@ -54,7 +50,7 @@ if [[ ! -z "$PXE_TFTP_URL" ]] && [[ "$PXE_RECOVER_MODE" = "unattended" ]] ; then
# perhaps Debian/Ubuntu and friends
[[ -f /usr/lib/PXELINUX/pxelinux.0 ]] && PXELINUX_BIN=/usr/lib/PXELINUX/pxelinux.0
fi
if [[ ! -z "$PXELINUX_BIN" ]] ; then
if [[ "$PXELINUX_BIN" ]] ; then
cp $v "$PXELINUX_BIN" $BUILD_DIR/tftpbootfs >&2
fi
syslinux_modules_dir=$( find_syslinux_modules_dir menu.c32 )
Expand All @@ -76,14 +72,14 @@ if [[ ! -z "$PXE_TFTP_URL" ]] && [[ "$PXE_RECOVER_MODE" = "unattended" ]] ; then
fi


if [[ ! -z "$PXE_TFTP_URL" ]] ; then
LogPrint "Copied kernel+initrd $( du -shc $KERNEL_FILE "$TMP_DIR/$REAR_INITRD_FILENAME" | tail -n 1 | tr -s "\t " " " | cut -d " " -f 1 ) to $PXE_TFTP_URL/$OUTPUT_PREFIX_PXE"
umount_url $PXE_TFTP_URL $BUILD_DIR/tftpbootfs
if [[ "$PXE_TFTP_UPLOAD_URL" ]] ; then
LogPrint "Copied kernel+initrd $( du -shc $KERNEL_FILE "$TMP_DIR/$REAR_INITRD_FILENAME" | tail -n 1 | tr -s "\t " " " | cut -d " " -f 1 ) to $PXE_TFTP_UPLOAD_URL/$OUTPUT_PREFIX_PXE"
umount_url "$PXE_TFTP_UPLOAD_URL" $BUILD_DIR/tftpbootfs
else
# legacy way PXE_TFTP_PATH
LogPrint "Copied kernel+initrd $( du -shc $KERNEL_FILE "$TMP_DIR/$REAR_INITRD_FILENAME" | tail -n 1 | tr -s "\t " " " | cut -d " " -f 1 ) to $PXE_TFTP_PATH"
# Add to result files
RESULT_FILES+=( "$PXE_TFTP_LOCAL_PATH/$PXE_KERNEL" "$PXE_TFTP_LOCAL_PATH/$PXE_INITRD" "$PXE_TFTP_LOCAL_PATH/$PXE_MESSAGE" )
RESULT_FILES+=( "$pxe_tftp_local_path/$PXE_KERNEL" "$pxe_tftp_local_path/$PXE_INITRD" "$pxe_tftp_local_path/$PXE_MESSAGE" )
robertdahlem marked this conversation as resolved.
Show resolved Hide resolved
fi

# vim: set et ts=4 sw=4
46 changes: 46 additions & 0 deletions usr/share/rear/output/PXE/default/801_copy_to_http.sh
@@ -0,0 +1,46 @@
# 801_copy_to_http.sh
#
# copy kernel and initrd to HTTP server for Relax-and-Recover
#
# This file is part of Relax-and-Recover, licensed under the GNU General
# Public License. Refer to the included COPYING for full text of license.

[[ "$PXE_HTTP_UPLOAD_URL" ]] || return

# When PXE_HTTP_UPLOAD_URL equals PXE_TFTP_UPLOAD_URL then the files have
# already been uploaded by 800_copy_to_tftp.sh and we don't need to do
# anything here.
if [[ "$PXE_HTTP_UPLOAD_URL" = "$PXE_TFTP_UPLOAD_URL" ]] ; then
Debug "PXE_HTTP_UPLOAD_URL = PXE_TFTP_UPLOAD_URL, upload already done by TFTP code in 800_copy_to_tftp.sh"
return
fi

# E.g. PXE_HTTP_UPLOAD_URL=nfs://server/export/nfs/www
local scheme=$( url_scheme "$PXE_HTTP_UPLOAD_URL" )

# We need filesystem access to the destination (schemes like ftp:// are not supported)
scheme_supports_filesystem $scheme || Error "Scheme $scheme from PXE_HTTP_UPLOAD_URL not supported, use a scheme that supports mounting (like nfs: )"

mount_url "$PXE_HTTP_UPLOAD_URL" $BUILD_DIR/httpbootfs $BACKUP_OPTIONS
# However, we copy under $OUTPUT_PREFIX_PXE directory (usually HOSTNAME) to have different clients on one pxe server
pxe_http_local_path=$BUILD_DIR/httpbootfs
# mode must readable for others for pxe and we copy under the client HOSTNAME (=OUTPUT_PREFIX_PXE)
mkdir $v -m 755 -p "$BUILD_DIR/httpbootfs/$OUTPUT_PREFIX_PXE" || Error "Could not mkdir '$BUILD_DIR/httpbootfs/$OUTPUT_PREFIX_PXE'"
PXE_KERNEL="$OUTPUT_PREFIX_PXE/${PXE_TFTP_PREFIX}kernel"
PXE_INITRD="$OUTPUT_PREFIX_PXE/$PXE_TFTP_PREFIX$REAR_INITRD_FILENAME"
PXE_MESSAGE="$OUTPUT_PREFIX_PXE/${PXE_TFTP_PREFIX}message"

# Follow symbolic links to ensure the real content gets copied
# but do not preserve mode,ownership,timestamps (i.e. no -p option) because that may fail (on sshfs) like
# "cp: failed to preserve ownership for '/tmp/rear-efi.XXXXXXXXXX/EFI/BOOT/kernel': Operation not permitted"
cp -L $v "$KERNEL_FILE" "$pxe_http_local_path/$PXE_KERNEL" || Error "Failed to copy KERNEL_FILE '$KERNEL_FILE'"
cp -L $v "$TMP_DIR/$REAR_INITRD_FILENAME" "$pxe_http_local_path/$PXE_INITRD" || Error "Failed to copy initrd '$REAR_INITRD_FILENAME'"
echo "$VERSION_INFO" >"$pxe_http_local_path/$PXE_MESSAGE"
# files must be readable for others for PXE
# files should be writebale by owner or overwriting it on later runs will fail
chmod 644 "$pxe_http_local_path/$PXE_KERNEL" "$pxe_http_local_path/$PXE_INITRD" "$pxe_http_local_path/$PXE_MESSAGE"

LogPrint "Copied kernel+initrd $( du -shc $KERNEL_FILE "$TMP_DIR/$REAR_INITRD_FILENAME" | tail -n 1 | tr -s "\t " " " | cut -d " " -f 1 ) to $PXE_HTTP_UPLOAD_URL/$OUTPUT_PREFIX_PXE"
umount_url "$PXE_HTTP_UPLOAD_URL" $BUILD_DIR/httpbootfs

# vim: set et ts=4 sw=4
45 changes: 23 additions & 22 deletions usr/share/rear/output/PXE/default/810_create_pxelinux_cfg.sh
Expand Up @@ -7,6 +7,7 @@

# We got PXE_KERNEL and PXE_INITRD set in the previous script.

local pxe_local_path
if test "$PXE_CONFIG_URL" ; then
# E.g. PXE_CONFIG_URL=nfs://server/export/nfs/tftpboot/pxelinux.cfg
# On 'server' the directory /export/nfs/tftpboot/pxelinux.cfg must exist.
Expand All @@ -16,26 +17,26 @@ if test "$PXE_CONFIG_URL" ; then
Error "Scheme $scheme for PXE output not supported, use a scheme that supports mounting (like nfs: )"
fi
mount_url $PXE_CONFIG_URL $BUILD_DIR/tftpbootfs $BACKUP_OPTIONS
PXE_LOCAL_PATH=$BUILD_DIR/tftpbootfs
pxe_local_path=$BUILD_DIR/tftpbootfs
else
# legacy way using PXE_LOCAL_PATH default
PXE_LOCAL_PATH=$PXE_CONFIG_PATH
# legacy way using pxe_local_path default
pxe_local_path=$PXE_CONFIG_PATH
fi

# PXE_CONFIG_PREFIX is by default 'rear-' (see default.conf).
# PXE_CONFIG_FILE contains the PXELINUX boot configuration of $HOSTNAME
PXE_CONFIG_FILE="${PXE_CONFIG_PREFIX}$HOSTNAME"
# pxe_config_file contains the PXELINUX boot configuration of $HOSTNAME
local pxe_config_file="${PXE_CONFIG_PREFIX}$HOSTNAME"
if test "$PXE_CONFIG_URL" ; then
if is_true "$PXE_CONFIG_GRUB_STYLE" ; then
make_pxelinux_config_grub >"$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
make_pxelinux_config_grub >"$pxe_local_path/$pxe_config_file"
else
make_pxelinux_config >"$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
make_pxelinux_config >"$pxe_local_path/$pxe_config_file"
fi
chmod 444 "$PXE_LOCAL_PATH/$PXE_CONFIG_FILE"
chmod 444 "$pxe_local_path/$pxe_config_file"
else
# legacy way using PXE_LOCAL_PATH default
# legacy way using pxe_local_path default
local pxe_template_file=$( get_template "PXE_pxelinux.cfg" )
cat >"$PXE_LOCAL_PATH/$PXE_CONFIG_FILE" <<EOF
cat >"$pxe_local_path/$pxe_config_file" <<EOF
$( test -s "$pxe_template_file" && cat "$pxe_template_file" )
display $OUTPUT_PREFIX_PXE/$PXE_MESSAGE
say ----------------------------------------------------------
Expand All @@ -46,13 +47,13 @@ else
EOF
fi

pushd "$PXE_LOCAL_PATH" >/dev/null || Error "PXE_LOCAL_PATH '$PXE_LOCAL_PATH' does not exist"
pushd "$pxe_local_path" >/dev/null || Error "pxe_local_path '$pxe_local_path' does not exist"

if test "$PXE_CREATE_LINKS" -a "$PXE_REMOVE_OLD_LINKS" ; then
# remove old symlinks
local symlink
find . -maxdepth 1 -type l | while read symlink ; do
test "$( readlink -s $symlink )" = "$PXE_CONFIG_FILE" && rm -f $symlink
test "$( readlink -s $symlink )" = "$pxe_config_file" && rm -f $symlink
done
fi

Expand All @@ -70,27 +71,27 @@ case "$PXE_CREATE_LINKS" in
# cut trailing CIDR or netmask e.g. '192.168.100.101/24' -> '192.168.100.101'
IP=${IP%/*}
if has_binary gethostip &>/dev/null ; then
ln -sf $v "$PXE_CONFIG_FILE" $pxe_link_prefix$( gethostip -x $IP )
ln -sf $v "$pxe_config_file" $pxe_link_prefix$( gethostip -x $IP )
# to capture the whole subnet as well
ln -sf $v "$PXE_CONFIG_FILE" $pxe_link_prefix$( gethostip -x $IP | cut -c 1-6 )
ln -sf $v "$pxe_config_file" $pxe_link_prefix$( gethostip -x $IP | cut -c 1-6 )
else
# if gethostip is not available on your platform like ppc64,
# use printf to output IP in hex mode
ln -sf $v "$PXE_CONFIG_FILE" $pxe_link_prefix$( printf '%02X' ${IP//./ } )
ln -sf $v "$pxe_config_file" $pxe_link_prefix$( printf '%02X' ${IP//./ } )
# to capture the whole subnet as well
ln -sf $v "$PXE_CONFIG_FILE" $pxe_link_prefix$( printf '%02X' ${IP//./ } | cut -c 1-6 )
ln -sf $v "$pxe_config_file" $pxe_link_prefix$( printf '%02X' ${IP//./ } | cut -c 1-6 )
fi
done
;;
(MAC)
# look at all devices that have link/ether
ip link | grep 'link/ether' | while read headword MAC junk ; do
# in MAC replace ':' with '-' e.g. 'a1:b2:c3:d4:e5:f6' -> 'a1-b2-c3-d4-e5-f6'
ln -sf $v "$PXE_CONFIG_FILE" ${pxe_link_prefix}01-${MAC//:/-}
ln -sf $v "$pxe_config_file" ${pxe_link_prefix}01-${MAC//:/-}
done
;;
("")
Log "Not creating symlinks to PXELINUX config file '$PXE_CONFIG_FILE' (empty PXE_CREATE_LINKS)"
Log "Not creating symlinks to PXELINUX config file '$pxe_config_file' (empty PXE_CREATE_LINKS)"
;;
(*)
Error "Invalid PXE_CREATE_LINKS '$PXE_CREATE_LINKS' (must be MAC or IP or '')"
Expand All @@ -100,9 +101,9 @@ esac
popd >/dev/null

if test "$PXE_CONFIG_URL" ; then
LogPrint "Created PXELINUX config '$PXE_CONFIG_FILE' and symlinks for $PXE_CREATE_LINKS adresses in $PXE_CONFIG_URL"
umount_url $PXE_TFTP_URL $BUILD_DIR/tftpbootfs
LogPrint "Created PXELINUX config '$pxe_config_file' and symlinks for $PXE_CREATE_LINKS adresses in $PXE_CONFIG_URL"
umount_url $PXE_TFTP_UPLOAD_URL $BUILD_DIR/tftpbootfs
else
LogPrint "Created PXELINUX config '$PXE_CONFIG_FILE' and symlinks for $PXE_CREATE_LINKS adresses in $PXE_CONFIG_PATH"
RESULT_FILES+=( "$PXE_LOCAL_PATH/$PXE_CONFIG_FILE" )
LogPrint "Created PXELINUX config '$pxe_config_file' and symlinks for $PXE_CREATE_LINKS adresses in $PXE_CONFIG_PATH"
RESULT_FILES+=( "$pxe_local_path/$pxe_config_file" )
fi